From 6893409b5ef6c6fcc6efaec6d735e9d162c79fe5 Mon Sep 17 00:00:00 2001 From: iaom <18504285112@163.com> Date: Mon, 1 Mar 2021 09:07:33 +0800 Subject: [PATCH] Make file search case insensitive. --- libsearch/index/construct-document.cpp | 2 +- libsearch/index/file-searcher.cpp | 13 +++--- libsearch/index/first-index.cpp | 1 + libsearch/index/index-generator.cpp | 65 ++++++++++++++++++++++++++ libsearch/index/index-generator.h | 1 + src/mainwindow.cpp | 6 +-- 6 files changed, 78 insertions(+), 10 deletions(-) diff --git a/libsearch/index/construct-document.cpp b/libsearch/index/construct-document.cpp index 6249fe3..28273fb 100644 --- a/libsearch/index/construct-document.cpp +++ b/libsearch/index/construct-document.cpp @@ -43,7 +43,7 @@ void ConstructDocumentForPath::run() if (!_doc_list_path) _doc_list_path = new QList; // qDebug()<<_doc_list_path->size(); - QString index_text = m_list.at(0); + QString index_text = m_list.at(0).toLower(); QString sourcePath = m_list.at(1); Document doc; diff --git a/libsearch/index/file-searcher.cpp b/libsearch/index/file-searcher.cpp index d2d80d6..6da3d6b 100644 --- a/libsearch/index/file-searcher.cpp +++ b/libsearch/index/file-searcher.cpp @@ -226,11 +226,12 @@ int FileSearcher::keywordSearchContent(size_t uniqueSymbol, QString keyword, int } Xapian::Query FileSearcher::creatQueryForFileSearch(QString keyword, Xapian::Database &db) { - // Xapian::QueryParser qp; - // qp.set_default_op(Xapian::Query::OP_PHRASE); - // qp.set_database(db); - auto userInput = keyword; - // userInput = userInput.replace(".","").simplified(); +// Xapian::QueryParser qp; +// qp.set_default_op(Xapian::Query::OP_PHRASE); +// qp.set_database(db); + auto userInput = keyword.toLower(); +// userInput = userInput.replace(".","").simplified(); +// userInput = QString(QUrl::toPercentEncoding(userInput)).replace(""," ").simplified(); // std::string queryStr = keyword.replace(".","").replace(" ","").replace(""," ").simplified().toStdString(); // std::string s =db.get_spelling_suggestion(queryStr,10); @@ -238,7 +239,7 @@ Xapian::Query FileSearcher::creatQueryForFileSearch(QString keyword, Xapian::Dat // qDebug()<<"queryStr!"< v; for(int i=0;ip_indexGenerator->creatAllIndex(tmp); tmp->clear(); } +// this->p_indexGenerator->setSynonym(); delete tmp; qDebug() << "index end;"; sem.release(2); diff --git a/libsearch/index/index-generator.cpp b/libsearch/index/index-generator.cpp index 333cd62..5105058 100644 --- a/libsearch/index/index-generator.cpp +++ b/libsearch/index/index-generator.cpp @@ -466,6 +466,71 @@ QStringList IndexGenerator::IndexSearch(QString indexText) return searchResult; } +//void IndexGenerator::setSynonym() +//{ +// try +// { +// m_database_path->add_synonym("a","A"); +// m_database_path->add_synonym("b","B"); +// m_database_path->add_synonym("c","C"); +// m_database_path->add_synonym("d","D"); +// m_database_path->add_synonym("e","A"); +// m_database_path->add_synonym("f","F"); +// m_database_path->add_synonym("g","G"); +// m_database_path->add_synonym("h","H"); +// m_database_path->add_synonym("i","I"); +// m_database_path->add_synonym("j","J"); +// m_database_path->add_synonym("k","K"); +// m_database_path->add_synonym("l","L"); +// m_database_path->add_synonym("m","M"); +// m_database_path->add_synonym("n","N"); +// m_database_path->add_synonym("o","O"); +// m_database_path->add_synonym("p","P"); +// m_database_path->add_synonym("q","Q"); +// m_database_path->add_synonym("r","R"); +// m_database_path->add_synonym("s","S"); +// m_database_path->add_synonym("t","T"); +// m_database_path->add_synonym("u","U"); +// m_database_path->add_synonym("v","V"); +// m_database_path->add_synonym("w","W"); +// m_database_path->add_synonym("x","X"); +// m_database_path->add_synonym("y","Y"); +// m_database_path->add_synonym("z","Z"); + +// m_database_path->add_synonym("A","a"); +// m_database_path->add_synonym("B","b"); +// m_database_path->add_synonym("C","c"); +// m_database_path->add_synonym("D","d"); +// m_database_path->add_synonym("E","e"); +// m_database_path->add_synonym("F","f"); +// m_database_path->add_synonym("G","g"); +// m_database_path->add_synonym("H","h"); +// m_database_path->add_synonym("I","i"); +// m_database_path->add_synonym("J","j"); +// m_database_path->add_synonym("K","k"); +// m_database_path->add_synonym("L","a"); +// m_database_path->add_synonym("M","m"); +// m_database_path->add_synonym("N","n"); +// m_database_path->add_synonym("O","o"); +// m_database_path->add_synonym("P","p"); +// m_database_path->add_synonym("Q","q"); +// m_database_path->add_synonym("R","r"); +// m_database_path->add_synonym("S","s"); +// m_database_path->add_synonym("T","t"); +// m_database_path->add_synonym("U","u"); +// m_database_path->add_synonym("V","v"); +// m_database_path->add_synonym("W","w"); +// m_database_path->add_synonym("X","x"); +// m_database_path->add_synonym("Y","y"); +// m_database_path->add_synonym("Z","z"); +// m_database_path->commit(); +// } +// catch(const Xapian::Error &e) +// { +// qWarning() <start(); connect(m_search_result_thread, &SearchResult::searchResultFile, this, [ = ](QString path) { - qDebug()<<"Append a file into list: "<appendSearchItem(SearchItem::SearchType::Files, path); }); connect(m_search_result_thread, &SearchResult::searchResultDir, this, [ = ](QString path) { - qDebug()<<"Append a dir into list: "<appendSearchItem(SearchItem::SearchType::Dirs, path); }); connect(m_search_result_thread, &SearchResult::searchResultContent, this, [ = ](QPair pair) { - qDebug()<<"Append a file content into list: "<appendSearchItem(SearchItem::SearchType::Contents, pair.first, pair.second); });