From 11707a54a694c3a49e590358a5723c339c8f7b90 Mon Sep 17 00:00:00 2001 From: iaom Date: Thu, 14 Dec 2023 14:04:38 +0800 Subject: [PATCH] =?UTF-8?q?fix(search-interface):=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E6=8E=A5=E5=8F=A3=E9=80=82=E9=85=8D=E6=96=B0?= =?UTF-8?q?=E5=9B=BD=E6=A0=87=E5=AD=97=E4=BD=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../searchtasks/file-search-task.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/libsearch/searchinterface/searchtasks/file-search-task.cpp b/libsearch/searchinterface/searchtasks/file-search-task.cpp index 8a870af..a17e11f 100644 --- a/libsearch/searchinterface/searchtasks/file-search-task.cpp +++ b/libsearch/searchinterface/searchtasks/file-search-task.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include "index-status-recorder.h" #include "dir-watcher.h" #include "common.h" @@ -178,10 +179,17 @@ Xapian::Query FileSearchWorker::creatQueryForFileSearch() { for (QString &keyword : m_searchController->getKeyword()) { if (!keyword.isEmpty()) { std::vector queryOfKeyword; - for(auto &c : keyword) { - queryOfKeyword.emplace_back(Xapian::Query(QUrl::toPercentEncoding(c).toStdString())); + QString inputKeyWord = keyword.toLower(); + 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()); } }