From ffd72cbababe36b93366fcbfc4b6b4087ed09085 Mon Sep 17 00:00:00 2001 From: iaom Date: Tue, 19 Apr 2022 09:16:20 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B4=A2=E5=BC=95=E6=90=9C=E7=B4=A2=E7=9A=84?= =?UTF-8?q?=E6=9D=83=E9=87=8D=E7=9B=B8=E5=90=8C=E7=9A=84=E7=BB=93=E6=9E=9C?= =?UTF-8?q?=E9=A1=B9=E6=8C=89=E7=85=A7=E4=BF=AE=E6=94=B9=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E6=96=B0->=E6=97=A7=E6=8E=92=E5=88=97=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libsearch/index/construct-document.cpp | 1 + libsearch/index/document.cpp | 5 +++++ libsearch/index/document.h | 1 + libsearch/index/first-index.cpp | 5 ++++- libsearch/index/index-generator.cpp | 4 +++- libsearch/index/search-manager.cpp | 16 +++++++++++++--- 6 files changed, 27 insertions(+), 5 deletions(-) diff --git a/libsearch/index/construct-document.cpp b/libsearch/index/construct-document.cpp index c35b8b9..fc81e42 100644 --- a/libsearch/index/construct-document.cpp +++ b/libsearch/index/construct-document.cpp @@ -66,6 +66,7 @@ void ConstructDocumentForPath::run() { doc.setUniqueTerm(uniqueterm); doc.addTerm(upTerm); doc.addValue(1, m_list.at(2)); + doc.addSortableSerialiseValue(2, m_list.at(3)); /* QStringList temp; // temp.append(index_text); temp.append(pinyin_text_list)*/; diff --git a/libsearch/index/document.cpp b/libsearch/index/document.cpp index e430d31..98ed782 100644 --- a/libsearch/index/document.cpp +++ b/libsearch/index/document.cpp @@ -74,6 +74,11 @@ void Document::addValue(unsigned slot, QString value) m_document.add_value(slot, value.toStdString()); } +void Document::addSortableSerialiseValue(unsigned slot, QString value) +{ + m_document.add_value(slot, Xapian::sortable_serialise(value.toDouble())); +} + void Document::setUniqueTerm(QString term) { if(term.isEmpty()) return; diff --git a/libsearch/index/document.h b/libsearch/index/document.h index 1949bb3..40139d1 100644 --- a/libsearch/index/document.h +++ b/libsearch/index/document.h @@ -48,6 +48,7 @@ public: void addTerm(QString term); void addTerm(std::string term); void addValue(unsigned slot, QString value); + void addSortableSerialiseValue(unsigned slot, QString value); void setUniqueTerm(QString term); void setUniqueTerm(std::string term); std::string getUniqueTerm(); diff --git a/libsearch/index/first-index.cpp b/libsearch/index/first-index.cpp index 886f984..44e5fb5 100644 --- a/libsearch/index/first-index.cpp +++ b/libsearch/index/first-index.cpp @@ -56,7 +56,10 @@ FirstIndex::~FirstIndex() { void FirstIndex::DoSomething(const QFileInfo& fileInfo) { // qDebug() << "there are some shit here"<m_indexData->enqueue(QVector() << fileInfo.fileName() << fileInfo.absoluteFilePath() << QString((fileInfo.isDir() && (!fileInfo.isSymLink())) ? "1" : "0")); + this->m_indexData->enqueue(QVector() << fileInfo.fileName() + << fileInfo.absoluteFilePath() + << QString((fileInfo.isDir() && (!fileInfo.isSymLink())) ? "1" : "0") + << fileInfo.lastModified().toString("yyyyMMddHHmmss")); if (fileInfo.fileName().split(".", QString::SkipEmptyParts).length() < 2) return; if (true == targetFileTypeMap[fileInfo.fileName().split(".").last()] diff --git a/libsearch/index/index-generator.cpp b/libsearch/index/index-generator.cpp index d705be3..1fb3710 100644 --- a/libsearch/index/index-generator.cpp +++ b/libsearch/index/index-generator.cpp @@ -610,7 +610,9 @@ bool IndexGenerator::updateIndex(QVector *pendingFiles) deleteList->append(file.path()); continue; } - fileIndexInfo->append(QVector() << file.path().section("/" , -1) << file.path() << QString(file.isDir() ? "1" : "0")); + fileIndexInfo->append(QVector() << file.path().section("/" , -1) + << file.path() << QString(file.isDir() ? "1" : "0") + << QFileInfo(file.path()).lastModified().toString("yyyyMMddHHmmss")); if (file.path().split(".").isEmpty()){ continue; } diff --git a/libsearch/index/search-manager.cpp b/libsearch/index/search-manager.cpp index ddff0d1..c3385d2 100644 --- a/libsearch/index/search-manager.cpp +++ b/libsearch/index/search-manager.cpp @@ -143,6 +143,8 @@ int FileSearch::keywordSearchfile() { qDebug() << "keywordSearchfile:" << QString::fromStdString(queryFile.get_description()); enquire.set_query(queryFile); + enquire.set_docid_order(enquire.DONT_CARE); + enquire.set_sort_by_relevance_then_value(2, true); Xapian::MSet result = enquire.get_mset(m_begin, m_num, 0, m_matchDecider); int resultCount = result.size(); qDebug() << "keywordSearchfile results count=" << resultCount; @@ -175,8 +177,10 @@ int FileSearch::getResult(Xapian::MSet &result) { for(auto it = result.begin(); it != result.end(); ++it) { Xapian::Document doc = it.get_document(); std::string data = doc.get_data(); - Xapian::weight docScoreWeight = it.get_weight(); - Xapian::percent docScorePercent = it.get_percent(); +// Xapian::weight docScoreWeight = it.get_weight(); +// Xapian::percent docScorePercent = it.get_percent(); +// std::string date = doc.get_value(2); + QString path = QString::fromStdString(data); std::string().swap(data); @@ -208,7 +212,13 @@ int FileSearch::getResult(Xapian::MSet &result) { break; } } - //qDebug() << "doc=" << path << ",weight=" << docScoreWeight << ",percent=" << docScorePercent; +// qDebug() << "doc=" << path +// << ",weight=" +// << docScoreWeight +// << ",percent=" +// << docScorePercent +// << "date" +// << QString::fromStdString(date); } // if(!pathTobeDelete->isEmpty()) // deleteAllIndex(pathTobeDelete)