Merge pull request #152 from iaom/0219-dev
Make file search case insensitive.
This commit is contained in:
commit
a3f7241539
|
@ -43,7 +43,7 @@ void ConstructDocumentForPath::run()
|
||||||
if (!_doc_list_path)
|
if (!_doc_list_path)
|
||||||
_doc_list_path = new QList<Document>;
|
_doc_list_path = new QList<Document>;
|
||||||
// qDebug()<<_doc_list_path->size();
|
// 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);
|
QString sourcePath = m_list.at(1);
|
||||||
Document doc;
|
Document doc;
|
||||||
|
|
||||||
|
|
|
@ -226,11 +226,12 @@ int FileSearcher::keywordSearchContent(size_t uniqueSymbol, QString keyword, int
|
||||||
}
|
}
|
||||||
Xapian::Query FileSearcher::creatQueryForFileSearch(QString keyword, Xapian::Database &db)
|
Xapian::Query FileSearcher::creatQueryForFileSearch(QString keyword, Xapian::Database &db)
|
||||||
{
|
{
|
||||||
// Xapian::QueryParser qp;
|
// Xapian::QueryParser qp;
|
||||||
// qp.set_default_op(Xapian::Query::OP_PHRASE);
|
// qp.set_default_op(Xapian::Query::OP_PHRASE);
|
||||||
// qp.set_database(db);
|
// qp.set_database(db);
|
||||||
auto userInput = keyword;
|
auto userInput = keyword.toLower();
|
||||||
// userInput = userInput.replace(".","").simplified();
|
// userInput = userInput.replace(".","").simplified();
|
||||||
|
// userInput = QString(QUrl::toPercentEncoding(userInput)).replace(""," ").simplified();
|
||||||
|
|
||||||
// std::string queryStr = keyword.replace(".","").replace(" ","").replace(""," ").simplified().toStdString();
|
// std::string queryStr = keyword.replace(".","").replace(" ","").replace(""," ").simplified().toStdString();
|
||||||
// std::string s =db.get_spelling_suggestion(queryStr,10);
|
// 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);
|
// qDebug()<<"queryStr!"<<QString::fromStdString(queryStr);
|
||||||
//Creat a query
|
//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;
|
std::vector<Xapian::Query> v;
|
||||||
for(int i=0;i<userInput.size();i++)
|
for(int i=0;i<userInput.size();i++)
|
||||||
{
|
{
|
||||||
|
|
|
@ -152,6 +152,7 @@ void FirstIndex::run(){
|
||||||
this->p_indexGenerator->creatAllIndex(tmp);
|
this->p_indexGenerator->creatAllIndex(tmp);
|
||||||
tmp->clear();
|
tmp->clear();
|
||||||
}
|
}
|
||||||
|
// this->p_indexGenerator->setSynonym();
|
||||||
delete tmp;
|
delete tmp;
|
||||||
qDebug() << "index end;";
|
qDebug() << "index end;";
|
||||||
sem.release(2);
|
sem.release(2);
|
||||||
|
|
|
@ -466,6 +466,71 @@ QStringList IndexGenerator::IndexSearch(QString indexText)
|
||||||
return searchResult;
|
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)
|
bool IndexGenerator::deleteAllIndex(QStringList *pathlist)
|
||||||
{
|
{
|
||||||
QStringList *list = pathlist;
|
QStringList *list = pathlist;
|
||||||
|
|
|
@ -48,6 +48,7 @@ public:
|
||||||
// Q_INVOKABLE void appendDocListPath(Document doc);
|
// Q_INVOKABLE void appendDocListPath(Document doc);
|
||||||
//for search test
|
//for search test
|
||||||
static QStringList IndexSearch(QString indexText);
|
static QStringList IndexSearch(QString indexText);
|
||||||
|
void setSynonym();
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void transactionFinished();
|
void transactionFinished();
|
||||||
void searchFinish();
|
void searchFinish();
|
||||||
|
|
|
@ -98,15 +98,15 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||||
m_search_result_thread = new SearchResult(this);
|
m_search_result_thread = new SearchResult(this);
|
||||||
// m_search_result_thread->start();
|
// m_search_result_thread->start();
|
||||||
connect(m_search_result_thread, &SearchResult::searchResultFile, this, [ = ](QString path) {
|
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);
|
m_contentFrame->appendSearchItem(SearchItem::SearchType::Files, path);
|
||||||
});
|
});
|
||||||
connect(m_search_result_thread, &SearchResult::searchResultDir, this, [ = ](QString 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);
|
m_contentFrame->appendSearchItem(SearchItem::SearchType::Dirs, path);
|
||||||
});
|
});
|
||||||
connect(m_search_result_thread, &SearchResult::searchResultContent, this, [ = ](QPair<QString, QStringList> pair) {
|
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);
|
m_contentFrame->appendSearchItem(SearchItem::SearchType::Contents, pair.first, pair.second);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue