diff --git a/libsearch/index/construct-document.cpp b/libsearch/index/construct-document.cpp index f0cc876..5c66a8a 100644 --- a/libsearch/index/construct-document.cpp +++ b/libsearch/index/construct-document.cpp @@ -65,7 +65,7 @@ void ConstructDocumentForPath::run() { doc.setData(sourcePath); doc.setUniqueTerm(uniqueterm); doc.addTerm(upTerm); - doc.addValue(m_list.at(2)); + doc.addValue(1, m_list.at(2)); /* QStringList temp; // temp.append(index_text); temp.append(pinyin_text_list)*/; @@ -107,7 +107,7 @@ void ConstructDocumentForContent::run() { Document doc; doc.setUniqueTerm(FileUtils::makeDocUterm(m_path)); doc.addTerm("ZEEKERUPTERM" + FileUtils::makeDocUterm(m_path.section("/", 0, -2, QString::SectionIncludeLeadingSep))); - doc.addValue(m_path); + doc.addValue(1, m_path); if(content.isEmpty()) { doc.reuireDeleted(); diff --git a/libsearch/index/document.cpp b/libsearch/index/document.cpp index f6a58f6..ae3abcf 100644 --- a/libsearch/index/document.cpp +++ b/libsearch/index/document.cpp @@ -69,8 +69,9 @@ void Document::addTerm(std::string term) { m_document.add_term(term); } -void Document::addValue(QString value) { - m_document.add_value(1, value.toStdString()); +void Document::addValue(unsigned slot, QString value) +{ + m_document.add_value(slot, value.toStdString()); } void Document::setUniqueTerm(QString term) { diff --git a/libsearch/index/document.h b/libsearch/index/document.h index 9fbb6f5..c72c73e 100644 --- a/libsearch/index/document.h +++ b/libsearch/index/document.h @@ -47,7 +47,7 @@ public: void addPosting(std::string term, unsigned int offset, int weight = 1); void addTerm(QString term); void addTerm(std::string term); - void addValue(QString value); + void addValue(unsigned slot, QString value); void setUniqueTerm(QString term); void setUniqueTerm(std::string term); std::string getUniqueTerm(); diff --git a/libsearch/index/index-generator.cpp b/libsearch/index/index-generator.cpp index dc07b87..0e601ed 100644 --- a/libsearch/index/index-generator.cpp +++ b/libsearch/index/index-generator.cpp @@ -326,7 +326,7 @@ Document IndexGenerator::GenerateDocument(const QVector &list) { doc.setData(sourcePath); doc.setUniqueTerm(uniqueterm); doc.addTerm(upTerm); - doc.addValue(list.at(2)); + doc.addValue(1, list.at(2)); QStringList temp; temp.append(index_text); temp.append(pinyin_text_list); @@ -352,7 +352,7 @@ Document IndexGenerator::GenerateContentDocument(const QString &path) { doc.setData(content); doc.setUniqueTerm(uniqueterm); doc.addTerm(upTerm); - doc.addValue(path); + doc.addValue(1, path); for(int i = 0; i < term.size(); ++i) { doc.addPosting(term.at(i).word, term.at(i).offsets, static_cast(term.at(i).weight)); diff --git a/libsearch/index/search-manager.cpp b/libsearch/index/search-manager.cpp index 1852ca7..1078e2a 100644 --- a/libsearch/index/search-manager.cpp +++ b/libsearch/index/search-manager.cpp @@ -110,10 +110,13 @@ FileSearch::FileSearch(DataQueue *searchResult, s m_slot = slot; m_begin = begin; m_num = num; + m_matchDecider = new FileMatchDecider(); } FileSearch::~FileSearch() { m_search_result = nullptr; + if(m_matchDecider) + delete m_matchDecider; } void FileSearch::run() { @@ -130,16 +133,9 @@ void FileSearch::run() { } SearchManager::m_mutexDir.unlock(); } - - int resultCount = 0; - int total = 0; - while(total < 100) { - resultCount = keywordSearchfile(); - if(resultCount == 0 || resultCount == -1) - break; - total += resultCount; - m_begin += m_num; - } + m_begin = 0; + m_num = -1; + keywordSearchfile(); return; } @@ -162,7 +158,7 @@ int FileSearch::keywordSearchfile() { qDebug() << "keywordSearchfile:" << QString::fromStdString(queryFile.get_description()); enquire.set_query(queryFile); - Xapian::MSet result = enquire.get_mset(m_begin, m_num); + Xapian::MSet result = enquire.get_mset(m_begin, m_num, 0, m_matchDecider); int resultCount = result.size(); qDebug() << "keywordSearchfile results count=" << resultCount; if(resultCount == 0) @@ -199,9 +195,6 @@ int FileSearch::getResult(Xapian::MSet &result) { QString path = QString::fromStdString(data); std::string().swap(data); - if(SearchManager::isBlocked(path)) { - continue; - } SearchPluginIface::ResultInfo ri; if(SearchManager::creatResultInfo(ri, path)) { switch(m_value.toInt()) { @@ -245,10 +238,13 @@ FileContentSearch::FileContentSearch(DataQueue *s m_keyword = keyword; m_begin = begin; m_num = num; + m_matchDecider = new FileContentMatchDecider(); } FileContentSearch::~FileContentSearch() { m_search_result = nullptr; + if(m_matchDecider) + delete m_matchDecider; } void FileContentSearch::run() { @@ -257,17 +253,10 @@ void FileContentSearch::run() { m_search_result->clear(); } SearchManager::m_mutexContent.unlock(); - int resultCount = 0; - int total = 0; - while(total < 50) { - resultCount = keywordSearchContent(); - if(resultCount == 0 || resultCount == -1) { - break; - } - total += resultCount; - m_begin += m_num; - } + m_begin = 0; + m_num = -1; + keywordSearchContent(); return; } @@ -314,7 +303,7 @@ int FileContentSearch::keywordSearchContent() { enquire.set_query(query); - Xapian::MSet result = enquire.get_mset(m_begin, m_num); + Xapian::MSet result = enquire.get_mset(m_begin, m_num, 0, m_matchDecider); int resultCount = result.size(); if(result.size() == 0) { return 0; @@ -342,10 +331,6 @@ int FileContentSearch::getResult(Xapian::MSet &result, std::string &keyWord) { Xapian::percent docScorePercent = it.get_percent(); QString path = QString::fromStdString(doc.get_value(1)); - if(SearchManager::isBlocked(path)) { - continue; - } - SearchPluginIface::ResultInfo ri; if(!SearchManager::creatResultInfo(ri, path)) { continue; @@ -501,3 +486,21 @@ void DirectSearch::run() { } } } + +bool FileMatchDecider::operator ()(const Xapian::Document &doc) const +{ + QString path = QString::fromStdString(doc.get_data()); + if(SearchManager::isBlocked(path)) { + return false; + } + return true; +} + +bool FileContentMatchDecider::operator ()(const Xapian::Document &doc) const +{ + QString path = QString::fromStdString(doc.get_value(1)); + if(SearchManager::isBlocked(path)) { + return false; + } + return true; +} diff --git a/libsearch/index/search-manager.h b/libsearch/index/search-manager.h index 773f1d7..94d8d15 100644 --- a/libsearch/index/search-manager.h +++ b/libsearch/index/search-manager.h @@ -46,10 +46,14 @@ #define INDEX_PATH (QStandardPaths::writableLocation(QStandardPaths::HomeLocation)+"/.config/org.ukui/ukui-search/index_data").toStdString() #define CONTENT_INDEX_PATH (QStandardPaths::writableLocation(QStandardPaths::HomeLocation)+"/.config/org.ukui/ukui-search/content_index_data").toStdString() namespace Zeeker { +class FileMatchDecider; +class FileContentMatchDecider; class LIBSEARCH_EXPORT SearchManager : public QObject { friend class FileSearch; friend class FileContentSearch; friend class DirectSearch; + friend class FileMatchDecider; + friend class FileContentMatchDecider; Q_OBJECT public: explicit SearchManager(QObject *parent = nullptr); @@ -90,6 +94,7 @@ private: int getResult(Xapian::MSet &result); DataQueue *m_search_result = nullptr; + FileMatchDecider *m_matchDecider; QString m_value; unsigned m_slot = 1; size_t m_uniqueSymbol; @@ -109,6 +114,7 @@ private: int getResult(Xapian::MSet &result, std::string &keyWord); DataQueue *m_search_result = nullptr; + FileContentMatchDecider *m_matchDecider; size_t m_uniqueSymbol; QString m_keyword; int m_begin = 0; @@ -127,5 +133,14 @@ private: QString m_value; }; +class FileMatchDecider :public Xapian::MatchDecider { +public: + bool operator ()(const Xapian::Document &doc) const; +}; +class FileContentMatchDecider :public Xapian::MatchDecider { +public: + bool operator ()(const Xapian::Document &doc) const; +}; + } #endif // SEARCHMANAGER_H