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)