From ba8837427361368687eaa8132837a53a8e1e71d7 Mon Sep 17 00:00:00 2001 From: iaom Date: Thu, 11 Nov 2021 11:44:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E5=8D=95=E6=AC=A1=E6=95=B0=E9=87=8F=E9=99=90?= =?UTF-8?q?=E5=88=B6=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libsearch/index/search-manager.cpp | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/libsearch/index/search-manager.cpp b/libsearch/index/search-manager.cpp index 1078e2a..18af3c4 100644 --- a/libsearch/index/search-manager.cpp +++ b/libsearch/index/search-manager.cpp @@ -133,9 +133,19 @@ void FileSearch::run() { } SearchManager::m_mutexDir.unlock(); } + //目前的需求是文件搜索数量无上限。 + //但如果不设置单次搜索数量限制,在一些性能非常弱的机器上(如兆芯某些机器),就算我们这里不阻塞UI,也会因为搜索本身占用cpu过多(可能)导致UI卡顿。 + //可能会有更好的方法,待优化。 m_begin = 0; - m_num = -1; - keywordSearchfile(); + m_num = 100; + int resultCount = 1; + int totalCount = 0; + while(resultCount > 0) { + resultCount = keywordSearchfile(); + m_begin += m_num; + totalCount += resultCount; + } + qDebug() << "Total count:" << m_value << totalCount; return; } @@ -223,7 +233,6 @@ int FileSearch::getResult(Xapian::MSet &result) { break; } } - // searchResult.append(path); //qDebug() << "doc=" << path << ",weight=" << docScoreWeight << ",percent=" << docScorePercent; } // if(!pathTobeDelete->isEmpty()) @@ -254,9 +263,17 @@ void FileContentSearch::run() { } SearchManager::m_mutexContent.unlock(); + //这里同文件搜索,待优化。 m_begin = 0; - m_num = -1; - keywordSearchContent(); + m_num = 100; + int resultCount = 1; + int totalCount = 0; + while(resultCount > 0) { + resultCount = keywordSearchContent(); + m_begin += m_num; + totalCount += resultCount; + } + qDebug() << "Total count:" << totalCount; return; }