Merge pull request #106 from iaom/0122-dev
Optimized file search method;Update debian files about translations.
This commit is contained in:
commit
b1696716bf
|
@ -1,3 +1,9 @@
|
|||
ukui-search (0.0.1+0123) v101; urgency=medium
|
||||
|
||||
* Bugs Fixed.
|
||||
|
||||
-- zhangpengfei <zhangpengfei@kylinos.cn> Sat, 23 Jan 2021 13:53:53 +0800
|
||||
|
||||
ukui-search (0.0.1+0120) v101; urgency=medium
|
||||
|
||||
* Bugs Fixed.
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
usr/lib/*/*.so.*
|
||||
usr/share/ukui-search/translations/libsearch/*.qm
|
||||
|
|
|
@ -114,7 +114,7 @@ int FileSearcher::keywordSearchfile(size_t uniqueSymbol, QString keyword, QStrin
|
|||
{
|
||||
try
|
||||
{
|
||||
qDebug()<<"--search start--";
|
||||
qDebug()<<"--keywordSearchfile start--";
|
||||
Xapian::Database db(INDEX_PATH);
|
||||
Xapian::Query query = creatQueryForFileSearch(keyword,db);
|
||||
Xapian::Enquire enquire(db);
|
||||
|
@ -131,24 +131,24 @@ int FileSearcher::keywordSearchfile(size_t uniqueSymbol, QString keyword, QStrin
|
|||
queryFile = query;
|
||||
}
|
||||
|
||||
qDebug()<<QString::fromStdString(queryFile.get_description());
|
||||
qDebug()<<"keywordSearchfile:"<<QString::fromStdString(queryFile.get_description());
|
||||
|
||||
enquire.set_query(queryFile);
|
||||
Xapian::MSet result = enquire.get_mset(begin, begin+num);
|
||||
int resultCount = static_cast<int>(result.get_matches_estimated());
|
||||
qDebug()<< "find results count=" <<resultCount;
|
||||
qDebug()<< "keywordSearchfile results count=" <<resultCount;
|
||||
if(result.size() == 0)
|
||||
return 0;
|
||||
if(getResult(uniqueSymbol, result, value) == -1)
|
||||
return -1;
|
||||
|
||||
qDebug()<< "--search finish--";
|
||||
qDebug()<< "--keywordSearchfile finish--";
|
||||
return resultCount;
|
||||
}
|
||||
catch(const Xapian::Error &e)
|
||||
{
|
||||
qWarning() <<QString::fromStdString(e.get_description());
|
||||
qDebug()<< "--search finish--";
|
||||
qDebug()<< "--keywordSearchfile finish--";
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ int FileSearcher::keywordSearchContent(size_t uniqueSymbol, QString keyword, int
|
|||
{
|
||||
try
|
||||
{
|
||||
qDebug()<<"--content search start--";
|
||||
qDebug()<<"--keywordSearchContent search start--";
|
||||
|
||||
Xapian::Database db(CONTENT_INDEX_PATH);
|
||||
Xapian::Enquire enquire(db);
|
||||
|
@ -181,53 +181,56 @@ int FileSearcher::keywordSearchContent(size_t uniqueSymbol, QString keyword, int
|
|||
// qDebug()<<QString::fromStdString(sKeyWord.at(i).word);
|
||||
// }
|
||||
// Xapian::Query queryPhrase =Xapian::Query(Xapian::Query::OP_AND, v.begin(), v.end());
|
||||
qDebug()<<QString::fromStdString(query.get_description());
|
||||
qDebug()<<"keywordSearchContent:"<<QString::fromStdString(query.get_description());
|
||||
|
||||
enquire.set_query(query);
|
||||
//dir result
|
||||
|
||||
Xapian::MSet result = enquire.get_mset(begin, begin+num);
|
||||
int resultCount = static_cast<int>(result.get_matches_estimated());
|
||||
if(result.size() == 0)
|
||||
return 0;
|
||||
qDebug()<< "find results count=" <<resultCount;
|
||||
qDebug()<< "keywordSearchContent results count=" <<resultCount;
|
||||
|
||||
if(getContentResult(uniqueSymbol, result, words) == -1)
|
||||
return -1;
|
||||
|
||||
qDebug()<< "--content search finish--";
|
||||
qDebug()<< "--keywordSearchContent search finish--";
|
||||
return resultCount;
|
||||
}
|
||||
catch(const Xapian::Error &e)
|
||||
{
|
||||
qWarning() <<QString::fromStdString(e.get_description());
|
||||
qDebug()<< "--content search finish--";
|
||||
qDebug()<< "--keywordSearchContent search finish--";
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
Xapian::Query FileSearcher::creatQueryForFileSearch(QString keyword, Xapian::Database &db)
|
||||
{
|
||||
Xapian::QueryParser qp;
|
||||
qp.set_default_op(Xapian::Query::OP_PHRASE);
|
||||
qp.set_database(db);
|
||||
// Xapian::QueryParser qp;
|
||||
// qp.set_default_op(Xapian::Query::OP_PHRASE);
|
||||
// qp.set_database(db);
|
||||
auto userInput = keyword;
|
||||
userInput = userInput.replace(".","").simplified();
|
||||
// userInput = 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);
|
||||
// qDebug()<<"spelling_suggestion!"<<QString::fromStdString(s);
|
||||
|
||||
qDebug()<<"queryStr!"<<QString::fromStdString(queryStr);
|
||||
// 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(queryStr,Xapian::QueryParser::FLAG_PHRASE);
|
||||
std::vector<Xapian::Query> v;
|
||||
for(int i=0;i<userInput.size();i++)
|
||||
{
|
||||
v.push_back(Xapian::Query(QString(userInput.at(i)).toStdString()));
|
||||
qDebug()<<QString::fromStdString(Xapian::Query(QString(userInput.at(i)).toStdString()).get_description());
|
||||
// qDebug()<<QString::fromStdString(Xapian::Query(QString(userInput.at(i)).toStdString()).get_description());
|
||||
}
|
||||
Xapian::Query queryPhrase =Xapian::Query(Xapian::Query::OP_PHRASE, v.begin(), v.end());
|
||||
Xapian::Query queryNear =Xapian::Query(Xapian::Query::OP_NEAR, v.begin(), v.end());
|
||||
|
||||
return Xapian::Query(Xapian::Query::OP_AND,queryNear,queryPhrase);
|
||||
Xapian::Query query = Xapian::Query(Xapian::Query::OP_AND,queryNear,queryPhrase);
|
||||
// qDebug()<<QString::fromStdString(query.get_description());
|
||||
return query;
|
||||
}
|
||||
|
||||
Xapian::Query FileSearcher::creatQueryForContentSearch(QString keyword, Xapian::Database &db)
|
||||
|
|
|
@ -273,6 +273,7 @@ void IndexGenerator::HandlePathList(QQueue<QString> *messageList)
|
|||
|
||||
Document IndexGenerator::GenerateDocument(const QVector<QString> &list)
|
||||
{
|
||||
Document doc;
|
||||
// qDebug()<<QString::number(quintptr(QThread::currentThreadId()));
|
||||
//0-filename 1-filepathname 2-file or dir
|
||||
QString index_text = list.at(0);
|
||||
|
@ -303,7 +304,7 @@ Document IndexGenerator::GenerateDocument(const QVector<QString> &list)
|
|||
// qDebug()<<"------------------------------------------finish";
|
||||
// }
|
||||
/*--------------------------------------------------------------------*/
|
||||
Document doc;
|
||||
|
||||
doc.setData(sourcePath);
|
||||
doc.setUniqueTerm(uniqueterm);
|
||||
doc.addTerm(upTerm);
|
||||
|
|
|
@ -7,7 +7,7 @@ DEFINES += LIBSEARCH_LIBRARY
|
|||
|
||||
PKGCONFIG += gio-2.0 glib-2.0 gio-unix-2.0 gsettings-qt
|
||||
|
||||
CONFIG += c++11 link_pkgconfig no_keywords
|
||||
CONFIG += c++11 link_pkgconfig no_keywords lrelease
|
||||
|
||||
|
||||
# The following define makes your compiler emit warnings if you use
|
||||
|
@ -67,3 +67,6 @@ unix {
|
|||
|
||||
INCLUDEPATH += $$PWD/../libchinese-segmentation
|
||||
DEPENDPATH += $$PWD/../libchinese-segmentation
|
||||
|
||||
#DISTFILES += \
|
||||
# ../translations/libsearch/libukui-search_zh_CN.ts
|
||||
|
|
|
@ -93,15 +93,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);
|
||||
});
|
||||
|
||||
|
|
10
src/src.pro
10
src/src.pro
|
@ -71,8 +71,8 @@ LIBS += -L$$OUT_PWD/../libsearch -lukui-search -L$$OUT_PWD/../libchinese-segment
|
|||
INCLUDEPATH += $$PWD/../libsearch
|
||||
DEPENDPATH += $$PWD/../libsearch
|
||||
|
||||
DISTFILES += \
|
||||
../data/ukui-search-menu.desktop \
|
||||
translations/bo.ts \
|
||||
translations/es.qm \
|
||||
translations/zh_CN.qm
|
||||
#DISTFILES += \
|
||||
# ../data/ukui-search-menu.desktop \
|
||||
# $$OUT_PWD/.qm/bo.qm \
|
||||
# $$OUT_PWD/.qm/tr.qm \
|
||||
# $$OUT_PWD/.qm/zh_CN.qm
|
||||
|
|
Loading…
Reference in New Issue