fix(search-interface):文件搜索接口适配新国标字体

This commit is contained in:
iaom 2023-12-14 14:04:38 +08:00
parent 9d6f19d4af
commit 11707a54a6
1 changed files with 11 additions and 3 deletions

View File

@ -26,6 +26,7 @@
#include <QDateTime> #include <QDateTime>
#include <gio/gio.h> #include <gio/gio.h>
#include <QUrl> #include <QUrl>
#include <QTextBoundaryFinder>
#include "index-status-recorder.h" #include "index-status-recorder.h"
#include "dir-watcher.h" #include "dir-watcher.h"
#include "common.h" #include "common.h"
@ -178,10 +179,17 @@ Xapian::Query FileSearchWorker::creatQueryForFileSearch() {
for (QString &keyword : m_searchController->getKeyword()) { for (QString &keyword : m_searchController->getKeyword()) {
if (!keyword.isEmpty()) { if (!keyword.isEmpty()) {
std::vector<Xapian::Query> queryOfKeyword; std::vector<Xapian::Query> queryOfKeyword;
for(auto &c : keyword) { QString inputKeyWord = keyword.toLower();
queryOfKeyword.emplace_back(Xapian::Query(QUrl::toPercentEncoding(c).toStdString())); QTextBoundaryFinder bf(QTextBoundaryFinder::Grapheme, inputKeyWord.toLower());
int start = 0;
for(; bf.position() != -1; bf.toNextBoundary()) {
int end = bf.position();
if(bf.boundaryReasons() & QTextBoundaryFinder::EndOfItem) {
queryOfKeyword.emplace_back(QUrl::toPercentEncoding(inputKeyWord.toLower().mid(start, end - start)).toStdString());
}
start = end;
} }
queries.emplace_back(Xapian::Query(Xapian::Query::OP_PHRASE, queryOfKeyword.begin(), queryOfKeyword.end())); queries.emplace_back(Xapian::Query::OP_PHRASE, queryOfKeyword.begin(), queryOfKeyword.end());
} }
} }