diff --git a/libsearch/index/batch-indexer.cpp b/libsearch/index/batch-indexer.cpp index ea3e6e2..5828722 100644 --- a/libsearch/index/batch-indexer.cpp +++ b/libsearch/index/batch-indexer.cpp @@ -119,6 +119,11 @@ void BatchIndexer::fetch() dir.setPath(bfs.dequeue()); list = dir.entryInfoList(); for(const auto& i : list) { + if(m_indexStop->LOAD && m_contentIndexStop->LOAD && m_contentIndexOcrStop->LOAD && m_aiIndexStop->LOAD) { + qDebug() << "Index stopped, abort index from traversal."; + m_cache.clear(); + return; + } bool isBlocked = false; for(const QString &path : tmpList) { if(i.absoluteFilePath() == path) { @@ -142,6 +147,11 @@ void BatchIndexer::fetch() void BatchIndexer::basicIndex() { qDebug() << "Begin basic index"; + if(m_indexStop->LOAD) { + qDebug() << "Index stopped, abort basic index."; + return; + } + WritableDatabase basicDb(DataBaseType::Basic); if(!basicDb.open()) { qWarning() << "Basic db open failed, fail to run basic index!"; @@ -183,6 +193,12 @@ void BatchIndexer::basicIndex() uint batchSize = 0; uint finishNum = 0; for (const QString& path: filesNeedIndex) { + if(m_indexStop->LOAD) { + basicDb.commit(); + qDebug() << "Index stopped, interrupt basic index."; + filesNeedIndex.clear(); + return; + } BasicIndexer indexer(path); if(indexer.index()) { basicDb.addDocument(indexer.document()); @@ -193,12 +209,6 @@ void BatchIndexer::basicIndex() qDebug() << finishNum << "of" << allSize <<"finished."; basicDb.commit(); Q_EMIT progress(IndexType::Basic, allSize, finishNum); - //文件名索引很快 - if(m_indexStop->LOAD) { - qDebug() << "Index stopped, abort basic index."; - filesNeedIndex.clear(); - return; - } batchSize = 0; } } diff --git a/libsearch/index/index-scheduler.cpp b/libsearch/index/index-scheduler.cpp index 5837e66..c9c06e9 100644 --- a/libsearch/index/index-scheduler.cpp +++ b/libsearch/index/index-scheduler.cpp @@ -360,7 +360,7 @@ void IndexScheduler::batchIndexerFinished(BatchIndexer::WorkMode mode, BatchInde if(mode == BatchIndexer::WorkMode::Add) { m_addNewPathPendingWorkCount--; } - if(isIdle()) { + if (isIdle() && m_state != Stop) { m_state = Idle; Q_EMIT stateChange(m_state); } @@ -369,7 +369,7 @@ void IndexScheduler::batchIndexerFinished(BatchIndexer::WorkMode mode, BatchInde void IndexScheduler::updateFinished() { m_updatePendingWorkCount--; - if(isIdle()) { + if (isIdle() && m_state != Stop) { m_state = Idle; Q_EMIT stateChange(m_state); } diff --git a/ukui-search-service/monitor.cpp b/ukui-search-service/monitor.cpp index e2a9e55..9627679 100644 --- a/ukui-search-service/monitor.cpp +++ b/ukui-search-service/monitor.cpp @@ -19,6 +19,7 @@ */ #include "monitor.h" #include +#include #include "file-indexer-config.h" using namespace UkuiSearch; Monitor::Monitor(IndexScheduler *scheduler, QObject *parent) : MonitorSource(parent), @@ -163,6 +164,7 @@ void Monitor::onIndexStateChanged(IndexScheduler::IndexerState state) } QMetaEnum metaEnum = QMetaEnum::fromType(); Q_EMIT indexStateChanged(QString::fromLocal8Bit(metaEnum.valueToKey(state))); + QGuiApplication::processEvents(QEventLoop::ExcludeUserInputEvents); } void Monitor::processUpdate(IndexType type, uint all, uint finished)