1.每个task只发送一次finish信号。2.设置直接搜索时的最大返回结果数量
This commit is contained in:
parent
c4fb3123b2
commit
8e68962393
|
@ -73,17 +73,18 @@ void FileSearchWorker::run()
|
|||
}
|
||||
}
|
||||
|
||||
bool finished = true;
|
||||
//TODO 还需要判断是否为不能建立索引的目录
|
||||
if (IndexStatusRecorder::getInstance()->indexDatabaseEnable()) {
|
||||
qDebug() << "index ready";
|
||||
searchWithIndex();
|
||||
finished = searchWithIndex();
|
||||
|
||||
} else {
|
||||
qDebug() << "direct search";
|
||||
directSearch();
|
||||
finished = directSearch();
|
||||
}
|
||||
|
||||
QMetaObject::invokeMethod(m_FileSearchTask, "searchFinished", Q_ARG(size_t, m_currentSearchId));
|
||||
if (finished) QMetaObject::invokeMethod(m_FileSearchTask, "searchFinished", Q_ARG(size_t, m_currentSearchId));
|
||||
}
|
||||
|
||||
Xapian::Query FileSearchWorker::creatQueryForFileSearch() {
|
||||
|
@ -115,7 +116,7 @@ Xapian::Query FileSearchWorker::creatQueryForFileSearch() {
|
|||
return {Xapian::Query::OP_AND, {Xapian::Query::OP_AND, queries.begin(), queries.end()}, fileOrDir};
|
||||
}
|
||||
|
||||
void FileSearchWorker::searchWithIndex()
|
||||
bool FileSearchWorker::searchWithIndex()
|
||||
{
|
||||
try {
|
||||
Xapian::Database db(INDEX_PATH.toStdString());
|
||||
|
@ -137,17 +138,20 @@ void FileSearchWorker::searchWithIndex()
|
|||
} else {
|
||||
qDebug() << "Search id changed!";
|
||||
m_searchController->finishSearchIdCheck();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
} catch(const Xapian::Error &e) {
|
||||
qWarning() << QString::fromStdString(e.get_description());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void FileSearchWorker::directSearch()
|
||||
bool FileSearchWorker::directSearch()
|
||||
{
|
||||
unsigned int maxResults = m_searchController->maxResults();
|
||||
QQueue<QString> searchPathQueue;
|
||||
for (QString &dir : m_validDirectories) {
|
||||
searchPathQueue.enqueue(dir);
|
||||
|
@ -194,15 +198,21 @@ void FileSearchWorker::directSearch()
|
|||
if (matched) {
|
||||
ResultItem ri(m_currentSearchId, fileInfo.absoluteFilePath());
|
||||
m_searchController->getDataQueue()->enqueue(ri);
|
||||
--maxResults;
|
||||
}
|
||||
m_searchController->finishSearchIdCheck();
|
||||
if (maxResults == 0) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
qDebug() << "Search id changed!";
|
||||
m_searchController->finishSearchIdCheck();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
FileSearchFilter::FileSearchFilter(FileSearchWorker *parent) : parent(parent) {}
|
||||
|
|
|
@ -47,8 +47,15 @@ protected:
|
|||
void run();
|
||||
|
||||
private:
|
||||
void searchWithIndex();
|
||||
void directSearch();
|
||||
/**
|
||||
* @brief 通过索引进行搜索,如果搜索过程正常,返回true
|
||||
* 如果搜索被打断,返回false.
|
||||
* 搜索被打断是指用户使用同一个task发起多次搜索,导致searchId发生变化,那么上一次搜索即被打断。
|
||||
* @return
|
||||
*/
|
||||
bool searchWithIndex();
|
||||
//同上
|
||||
bool directSearch();
|
||||
Xapian::Query creatQueryForFileSearch();
|
||||
|
||||
private:
|
||||
|
|
Loading…
Reference in New Issue