Make file search case insensitive.

This commit is contained in:
iaom 2021-03-01 09:07:33 +08:00
parent 4f12c9dc31
commit 6893409b5e
6 changed files with 78 additions and 10 deletions

View File

@ -43,7 +43,7 @@ void ConstructDocumentForPath::run()
if (!_doc_list_path)
_doc_list_path = new QList<Document>;
// 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;

View File

@ -229,8 +229,9 @@ Xapian::Query FileSearcher::creatQueryForFileSearch(QString keyword, Xapian::Dat
// Xapian::QueryParser qp;
// qp.set_default_op(Xapian::Query::OP_PHRASE);
// qp.set_database(db);
auto userInput = keyword;
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!"<<QString::fromStdString(queryStr);
//Creat a query
// Xapian::Query queryPhrase = qp.parse_query(queryStr,Xapian::QueryParser::FLAG_PHRASE);
// Xapian::Query queryPhrase = qp.parse_query(userInput.toStdString(),Xapian::QueryParser::FLAG_PHRASE|Xapian::QueryParser::FLAG_SYNONYM);
std::vector<Xapian::Query> v;
for(int i=0;i<userInput.size();i++)
{

View File

@ -152,6 +152,7 @@ void FirstIndex::run(){
this->p_indexGenerator->creatAllIndex(tmp);
tmp->clear();
}
// this->p_indexGenerator->setSynonym();
delete tmp;
qDebug() << "index end;";
sem.release(2);

View File

@ -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() <<QString::fromStdString(e.get_description());
// }
//}
bool IndexGenerator::deleteAllIndex(QStringList *pathlist)
{
QStringList *list = pathlist;

View File

@ -48,6 +48,7 @@ public:
// Q_INVOKABLE void appendDocListPath(Document doc);
//for search test
static QStringList IndexSearch(QString indexText);
void setSynonym();
Q_SIGNALS:
void transactionFinished();
void searchFinish();

View File

@ -98,15 +98,15 @@ MainWindow::MainWindow(QWidget *parent) :
m_search_result_thread = new SearchResult(this);
// m_search_result_thread->start();
connect(m_search_result_thread, &SearchResult::searchResultFile, this, [ = ](QString path) {
qDebug()<<"Append a file into list: "<<path;
// qDebug()<<"Append a file into list: "<<path;
m_contentFrame->appendSearchItem(SearchItem::SearchType::Files, path);
});
connect(m_search_result_thread, &SearchResult::searchResultDir, this, [ = ](QString path) {
qDebug()<<"Append a dir into list: "<<path;
// qDebug()<<"Append a dir into list: "<<path;
m_contentFrame->appendSearchItem(SearchItem::SearchType::Dirs, path);
});
connect(m_search_result_thread, &SearchResult::searchResultContent, this, [ = ](QPair<QString, QStringList> pair) {
qDebug()<<"Append a file content into list: "<<pair.first;
// qDebug()<<"Append a file content into list: "<<pair.first;
m_contentFrame->appendSearchItem(SearchItem::SearchType::Contents, pair.first, pair.second);
});