增加查看当前索引状态的命令行

This commit is contained in:
iaom 2023-10-07 15:44:59 +08:00
parent d6e3cd46e9
commit 69eb8632fa
11 changed files with 251 additions and 224 deletions

View File

@ -65,7 +65,6 @@ set(LIBUKUI_SEARCH_SRC
index/index-scheduler.cpp index/index-scheduler.h
index/index-status-recorder.cpp index/index-status-recorder.h
index/index-updater.cpp index/index-updater.h
index/monitor.cpp index/monitor.h
index/ocrobject.cpp index/ocrobject.h
index/pending-file.cpp index/pending-file.h
index/pending-file-queue.cpp index/pending-file-queue.h

View File

@ -29,6 +29,9 @@ Database::Database(const DataBaseType &type)
case DataBaseType::Content:
m_database = new Xapian::Database(CONTENT_INDEX_PATH.toStdString());
break;
case DataBaseType::OcrContent:
m_database = new Xapian::Database(OCR_CONTENT_INDEX_PATH.toStdString());
break;
default:
break;
}
@ -42,7 +45,7 @@ Database::~Database()
}
}
uint Database::getIndexDocCount()
uint Database::getIndexDocCount() const
{
return m_database->get_doccount();
}

View File

@ -26,10 +26,10 @@ namespace UkuiSearch {
class Database
{
public:
Database(const DataBaseType &type);
explicit Database(const DataBaseType &type);
~Database();
uint getIndexDocCount();
uint getIndexDocCount() const;
private:
Xapian::Database *m_database;
};

View File

@ -1,173 +0,0 @@
/*
* Copyright (C) 2022, KylinSoft Co., Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* Authors: iaom <zhangpengfei@kylinos.cn>
*
*/
#ifndef MONITOR_H
#define MONITOR_H
#include <QObject>
#include "index-scheduler.h"
#include "database.h"
namespace UkuiSearch {
/**
* @brief The Monitor class
*
* qml
*/
class Monitor : public QObject
{
Q_OBJECT
Q_PROPERTY(QStringList currentIndexPaths READ getCurrentIndexPaths)
Q_PROPERTY(QString indexState READ getIndexState NOTIFY indexStateChanged)
Q_PROPERTY(uint basicIndexSize READ getBasicIndexSize NOTIFY basicIndexSizeChange)
Q_PROPERTY(uint contentIndexSize READ getContentIndexSize NOTIFY contentIndexSizeChange)
Q_PROPERTY(uint ocrIndexSize READ getOCRIndexSize NOTIFY ocrIndexSizeChange)
Q_PROPERTY(uint basicIndexProgress READ getBasicIndexProgress NOTIFY basicIndexProgressUpdate)
Q_PROPERTY(uint contentIndexProgress READ getContentIndexProgress NOTIFY contentIndexProgressUpdate)
Q_PROPERTY(uint ocrIndexProgress READ getOCRIndexProgress NOTIFY ocrIndexProgressUpdate)
Q_PROPERTY(uint basicIndexDocNum READ getBasicIndexDocNum NOTIFY basicIndexDocNumUpdate)
Q_PROPERTY(uint contentIndexDocNum READ getContentIndexDocNum NOTIFY contentIndexDocNumUpdate)
public:
explicit Monitor(IndexScheduler* scheduler, QObject *parent = nullptr);
/**
* @brief getCurrentIndexPaths
* @return
*/
QStringList getCurrentIndexPaths();
/**
* @brief getIndexState
* @return
*/
QString getIndexState();
/**
* @brief getBasicIndexSize
* @return
*/
uint getBasicIndexSize();
/**
* @brief getContentIndexSize
* @return
*/
uint getContentIndexSize();
/**
* @brief getOCRIndexSize
* @return OCR索引数量
*/
uint getOCRIndexSize();
/**
* @brief getBasicIndexProgress
* @return
*/
uint getBasicIndexProgress();
/**
* @brief getContentIndexProgress
* @return
*/
uint getContentIndexProgress();
/**
* @brief getOCRIndexProgress
* @return ocr索引进度
*/
uint getOCRIndexProgress();
/**
* @brief getBasicIndexDocNum
* @return
*/
uint getBasicIndexDocNum();
/**
* @brief getContentIndexDocNum
* @return
*/
uint getContentIndexDocNum();
Q_SIGNALS:
/**
* @brief indexStateChanged
*
*/
void indexStateChanged(QString);
/**
* @brief basicIndexSizeChange
*
*/
void basicIndexSizeChange(uint);
/**
* @brief contentIndexSizeChange
* OCR索引
*/
void contentIndexSizeChange(uint);
/**
* @brief ocrIndexSizeChange
* OCR索引总量
*/
void ocrIndexSizeChange(uint);
/**
* @brief basicIndexProgressUpdate
*
*/
void basicIndexProgressUpdate(uint);
/**
* @brief contentIndexProgressUpdate
* OCR索引
*/
void contentIndexProgressUpdate(uint);
/**
* @brief ocrIndexProgressUpdate
* OCR索引进度
*/
void ocrIndexProgressUpdate(uint);
/**
* @brief basicIndexDocNumUpdate
*
*/
void basicIndexDocNumUpdate(uint);
/**
* @brief contentIndexDocNumUpdate
*
*/
void contentIndexDocNumUpdate(uint);
/**
* @brief basicIndexDone
*
*/
void basicIndexDone();
/**
* @brief contentIndexDone
*
*/
void contentIndexDone();
private Q_SLOTS:
void onIndexStateChanged(IndexScheduler::IndexerState);
void processUpdate(IndexType type, uint all, uint finished);
private:
IndexScheduler *m_scheduler = nullptr;
Database m_basicDatabase;
Database m_contentDatabase;
uint m_basicIndexSize = 0;
uint m_contentIndexSize = 0;
uint m_ocrIndexSize = 0;
uint m_basicIndexProgress = 0;
uint m_contentIndexProgress = 0;
uint m_ocrIndexProgress = 0;
};
}
#endif // MONITOR_H

View File

@ -11,8 +11,8 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core DBus Gui Quick Widgets REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core DBus Gui Quick Widgets REQUIRED)
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core DBus Gui Quick Widgets RemoteObjects REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core DBus Gui Quick Widgets RemoteObjects REQUIRED)
find_package(PkgConfig REQUIRED)
set(UKUI_SEARCH_SERVICE_EXTERNAL_LIBS "")
set(UKUI_SEARCH_SERVICE_PC_PKGS gsettings-qt)
@ -27,9 +27,17 @@ foreach(PC_LIB IN ITEMS ${UKUI_SEARCH_SERVICE_PC_PKGS})
endforeach()
set(QRC_FILES qml/qml.qrc)
add_executable(ukui-search-service
set(UKUI_SEARCH_SERVICE_SRC
main.cpp
ukui-search-service.cpp ukui-search-service.h
ukui-search-service.cpp
ukui-search-service.h
monitor.cpp
monitor.h
)
qt5_generate_repc(UKUI_SEARCH_SERVICE_SRC monitor.rep SOURCE)
qt5_generate_repc(UKUI_SEARCH_SERVICE_SRC monitor.rep REPLICA)
add_executable(ukui-search-service
${UKUI_SEARCH_SERVICE_SRC}
${QRC_FILES}
)
target_include_directories(ukui-search-service PRIVATE
@ -53,6 +61,7 @@ target_link_libraries(ukui-search-service PRIVATE
Qt${QT_VERSION_MAJOR}::Gui
Qt${QT_VERSION_MAJOR}::Quick
Qt${QT_VERSION_MAJOR}::Widgets
Qt${QT_VERSION_MAJOR}::RemoteObjects
libukui-search
qtsingleapplication
${UKUI_SEARCH_SERVICE_EXTERNAL_LIBS}

View File

@ -56,8 +56,6 @@ int main(int argc, char *argv[])
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
#endif
UkuiSearchService ukss(argc, argv, "ukui-search-service");
if (ukss.isRunning())
return 0;
return ukss.exec();
return UkuiSearch::UkuiSearchService::exec();
}

View File

@ -21,74 +21,85 @@
#include <QMetaEnum>
#include "file-indexer-config.h"
using namespace UkuiSearch;
Monitor::Monitor(IndexScheduler *scheduler, QObject *parent)
: QObject(parent),
Monitor::Monitor(IndexScheduler *scheduler, QObject *parent) : MonitorSource(parent),
m_scheduler(scheduler),
m_basicDatabase(DataBaseType::Basic),
m_contentDatabase(DataBaseType::Content)
m_contentDatabase(DataBaseType::Content),
m_ocrContentDatabase(DataBaseType::OcrContent)
{
connect(scheduler, &IndexScheduler::stateChange, this, &Monitor::onIndexStateChanged);
connect(scheduler, &IndexScheduler::process, this, &Monitor::processUpdate);
connect(scheduler, &IndexScheduler::basicIndexDone, this, &Monitor::basicIndexDone);
connect(scheduler, &IndexScheduler::contentIndexDone, this, &Monitor::contentIndexDone);
connect(FileIndexerConfig::getInstance(), &FileIndexerConfig::appendIndexDir, this, [&](){
Q_EMIT currentIndexPathsChanged(FileIndexerConfig::getInstance()->currentIndexableDir());
});
connect(FileIndexerConfig::getInstance(), &FileIndexerConfig::removeIndexDir, this, [&](){
Q_EMIT currentIndexPathsChanged(FileIndexerConfig::getInstance()->currentIndexableDir());
});
}
QStringList Monitor::getCurrentIndexPaths()
QStringList Monitor::currentIndexPaths() const
{
return FileIndexerConfig::getInstance()->currentIndexableDir();
}
QString Monitor::getIndexState()
QString Monitor::indexState() const
{
QMetaEnum metaEnum = QMetaEnum::fromType<IndexScheduler::IndexerState>();
return QString::fromLocal8Bit(metaEnum.valueToKey(m_scheduler->getIndexState()));
}
uint Monitor::getBasicIndexSize()
uint Monitor::basicIndexSize() const
{
return m_basicIndexSize;
}
uint Monitor::getContentIndexSize()
uint Monitor::contentIndexSize() const
{
return m_contentIndexSize;
}
uint Monitor::getOCRIndexSize()
uint Monitor::ocrIndexSize() const
{
return m_ocrIndexSize;
}
uint Monitor::getBasicIndexProgress()
uint Monitor::basicIndexProgress() const
{
return m_basicIndexProgress;
}
uint Monitor::getContentIndexProgress()
uint Monitor::contentIndexProgress() const
{
return m_contentIndexProgress;
}
uint Monitor::getOCRIndexProgress()
uint Monitor::ocrIndexProgress() const
{
return m_ocrIndexProgress;
}
uint Monitor::getBasicIndexDocNum()
uint Monitor::basicIndexDocNum() const
{
return m_basicDatabase.getIndexDocCount();
}
uint Monitor::getContentIndexDocNum()
uint Monitor::contentIndexDocNum() const
{
return m_contentDatabase.getIndexDocCount();
}
uint Monitor::ocrContentIndexDocNum() const
{
return m_ocrContentDatabase.getIndexDocCount();
}
void Monitor::onIndexStateChanged(IndexScheduler::IndexerState state)
{
if(state == IndexScheduler::IndexerState::Idle) {
Q_EMIT basicIndexDocNumUpdate(m_basicDatabase.getIndexDocCount());
Q_EMIT contentIndexDocNumUpdate(m_contentDatabase.getIndexDocCount());
Q_EMIT basicIndexDocNumChanged(m_basicDatabase.getIndexDocCount());
Q_EMIT contentIndexDocNumChanged(m_contentDatabase.getIndexDocCount());
}
QMetaEnum metaEnum = QMetaEnum::fromType<IndexScheduler::IndexerState>();
Q_EMIT indexStateChanged(QString::fromLocal8Bit(metaEnum.valueToKey(state)));
@ -99,21 +110,21 @@ void Monitor::processUpdate(IndexType type, uint all, uint finished)
switch (type) {
case IndexType::Basic:
m_basicIndexSize = all;
Q_EMIT basicIndexSizeChange(m_basicIndexSize);
Q_EMIT basicIndexSizeChanged(m_basicIndexSize);
m_basicIndexProgress = finished;
Q_EMIT basicIndexProgressUpdate(m_basicIndexProgress);
Q_EMIT basicIndexProgressChanged(m_basicIndexProgress);
break;
case IndexType::Contents:
m_contentIndexSize = all;
Q_EMIT contentIndexSizeChange(m_contentIndexSize);
Q_EMIT contentIndexSizeChanged(m_contentIndexSize);
m_contentIndexProgress = finished;
Q_EMIT contentIndexProgressUpdate(m_contentIndexProgress);
Q_EMIT contentIndexProgressChanged(m_contentIndexProgress);
break;
case IndexType::OCR:
m_ocrIndexSize = all;
Q_EMIT ocrIndexSizeChange(m_ocrIndexSize);
Q_EMIT ocrIndexSizeChanged(m_ocrIndexSize);
m_contentIndexProgress = finished;
Q_EMIT ocrIndexProgressUpdate(m_contentIndexProgress);
Q_EMIT ocrIndexProgressChanged(m_contentIndexProgress);
break;
default:
break;

View File

@ -0,0 +1,123 @@
/*
* Copyright (C) 2022, KylinSoft Co., Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* Authors: iaom <zhangpengfei@kylinos.cn>
*
*/
#ifndef MONITOR_H
#define MONITOR_H
#include <QObject>
#include "index-scheduler.h"
#include "database.h"
#include "rep_monitor_source.h"
namespace UkuiSearch {
/**
* @brief The Monitor class
*
*/
class Monitor : public MonitorSource
{
Q_OBJECT
public:
explicit Monitor(IndexScheduler* scheduler, QObject *parent = nullptr);
/**
* @brief currentIndexPaths
* @return
*/
QStringList currentIndexPaths() const override;
/**
* @brief indexState
* @return
*/
QString indexState() const override;
/**
* @brief basicIndexSize
* @return
*/
uint basicIndexSize() const override;
/**
* @brief contentIndexSize
* @return
*/
uint contentIndexSize() const override;
/**
* @brief ocrIndexSize
* @return OCR索引数量
*/
uint ocrIndexSize() const override;
/**
* @brief basicIndexProgress
* @return
*/
uint basicIndexProgress() const override;
/**
* @brief contentIndexProgress
* @return
*/
uint contentIndexProgress() const override;
/**
* @brief ocrIndexProgress
* @return ocr索引进度
*/
uint ocrIndexProgress() const override;
/**
* @brief basicIndexDocNum
* @return
*/
uint basicIndexDocNum() const override;
/**
* @brief contentIndexDocNum
* @return
*/
uint contentIndexDocNum() const override;
/**
* @brief contentIndexDocNum
* @return ocr容索引完成的总文档数
*/
uint ocrContentIndexDocNum() const override;
Q_SIGNALS:
/**
* @brief basicIndexDone
*
*/
void basicIndexDone();
/**
* @brief contentIndexDone
*
*/
void contentIndexDone();
private Q_SLOTS:
void onIndexStateChanged(IndexScheduler::IndexerState);
void processUpdate(UkuiSearch::IndexType type, uint all, uint finished);
private:
IndexScheduler *m_scheduler = nullptr;
Database m_basicDatabase;
Database m_contentDatabase;
Database m_ocrContentDatabase;
uint m_basicIndexSize = 0;
uint m_contentIndexSize = 0;
uint m_ocrIndexSize = 0;
uint m_basicIndexProgress = 0;
uint m_contentIndexProgress = 0;
uint m_ocrIndexProgress = 0;
};
}
#endif // MONITOR_H

View File

@ -0,0 +1,15 @@
#include <QStringList>
class Monitor
{
PROP(QStringList currentIndexPaths READONLY);
PROP(QString indexState READONLY);
PROP(uint basicIndexSize READONLY);
PROP(uint contentIndexSize READONLY);
PROP(uint ocrIndexSize READONLY);
PROP(uint basicIndexProgress READONLY);
PROP(uint contentIndexProgress READONLY);
PROP(uint ocrIndexProgress READONLY);
PROP(uint basicIndexDocNum READONLY);
PROP(uint contentIndexDocNum READONLY);
PROP(uint ocrContentIndexDocNum READONLY);
};

View File

@ -20,10 +20,14 @@
#include <QDebug>
#include <QDBusConnection>
#include <QQmlContext>
#include <utility>
#include <stdio.h>
#include "ukui-search-service.h"
#include "dir-watcher.h"
#include "file-utils.h"
#include "file-indexer-config.h"
#include "rep_monitor_replica.h"
using namespace UkuiSearch;
UkuiSearchService::UkuiSearchService(int &argc, char *argv[], const QString &applicationName)
@ -34,17 +38,20 @@ UkuiSearchService::UkuiSearchService(int &argc, char *argv[], const QString &app
setQuitOnLastWindowClosed(false);
if (!this->isRunning()) {
connect(this, &QtSingleApplication::messageReceived, [=](QString msg) {
connect(this, &QtSingleApplication::messageReceived, [=](const QString& msg) {
this->parseCmd(msg, true);
});
qRegisterMetaType<IndexType>("IndexType");
m_indexScheduler = new IndexScheduler(this);
DirWatcher::getDirWatcher()->initDbusService();
m_monitor = new Monitor(m_indexScheduler, this);
m_qroHost.setHostUrl(QUrl(QStringLiteral("local:ukui-search-service-monitor")));
qDebug() << "Init remote status object:" << m_qroHost.enableRemoting<MonitorSourceAPI>(m_monitor);
}
//parse cmd
qDebug()<<"parse cmd";
auto message = this->arguments().join(' ').toUtf8();
auto message = arguments().join(' ').toUtf8();
parseCmd(message, !isRunning());
qDebug()<<"ukui search service constructor end";
@ -58,7 +65,7 @@ UkuiSearchService::~UkuiSearchService()
}
}
void UkuiSearchService::parseCmd(QString msg, bool isPrimary)
void UkuiSearchService::parseCmd(const QString& msg, bool isPrimary)
{
QCommandLineParser parser;
@ -71,8 +78,8 @@ void UkuiSearchService::parseCmd(QString msg, bool isPrimary)
QCommandLineOption monitorWindow(QStringList()<<"m"<<"monitor", tr("Show index monitor window"));
parser.addOption(monitorWindow);
// QCommandLineOption statusOption(QStringList()<<"s"<<"status", tr("show status of file index service"));
// parser.addOption(statusOption);
QCommandLineOption statusOption(QStringList()<<"s"<<"status", tr("show status of file index service"));
parser.addOption(statusOption);
if (isPrimary) {
const QStringList args = QString(msg).split(' ');
@ -86,13 +93,18 @@ void UkuiSearchService::parseCmd(QString msg, bool isPrimary)
qApp->quit();
return;
}
}
else {
} else {
if (arguments().count() < 2) {
parser.showHelp();
}
parser.process(arguments());
if(parser.isSet(statusOption)) {
showMonitorState();
return;
} else {
sendMessage(msg);
::exit(0);
}
}
}
@ -108,3 +120,29 @@ void UkuiSearchService::loadMonitorWindow()
m_quickView->setSource(m_qmlPath);
}
}
void UkuiSearchService::showMonitorState()
{
m_qroNode.connectToNode(QUrl(QStringLiteral("local:ukui-search-service-monitor")));
auto *m = m_qroNode.acquire<MonitorReplica>();
connect(m, &QRemoteObjectReplica::initialized, [&, m](){
qDebug() << "QRemoteObjectReplica initialized";
QString state = m->indexState();
QString message = "Current index path: " + m->currentIndexPaths().join(",") + "\n"
+ "Current index scheduler state: " + m->indexState() + "\n";
if(state == "Idle" || state == "Stop") {
message += "Basic index size: " + QString::number(m->basicIndexDocNum()) + " \n"
+ "Content index size: " + QString::number(m->contentIndexDocNum()) + " \n"
+ "Ocr index size: " + QString::number(m->ocrContentIndexDocNum()) + " \n";
} else {
message += "Basic index progress: " + QString::number(m->basicIndexProgress()) + " of " + QString::number(m->basicIndexSize())+ " finished\n"
+ "Content index size: " + QString::number(m->contentIndexProgress()) + " of " + QString::number(m->contentIndexSize())+ " finished\n"
+ "Ocr content index size: " + QString::number(m->ocrIndexProgress()) + " of " + QString::number(m->ocrIndexSize())+ " finished\n";
}
delete m;
fputs(qPrintable(message), stdout);
qApp->quit();
});
}

View File

@ -24,6 +24,7 @@
#include <QCommandLineParser>
#include <QGSettings>
#include <QQuickView>
#include <QtRemoteObjects/qremoteobjectnode.h>
#include "qtsingleapplication.h"
#include "common.h"
#include "index-scheduler.h"
@ -39,12 +40,15 @@ public:
~UkuiSearchService();
protected Q_SLOTS:
void parseCmd(QString msg, bool isPrimary);
void parseCmd(const QString& msg, bool isPrimary);
private:
void loadMonitorWindow();
void showMonitorState();
IndexScheduler *m_indexScheduler = nullptr;
Monitor *m_monitor = nullptr;
QRemoteObjectHost m_qroHost;
QRemoteObjectNode m_qroNode;
QQuickView *m_quickView = nullptr;
QUrl m_qmlPath = QString("qrc:/qml/IndexMonitor.qml");