diff --git a/src/plugins/filemanager/dfmplugin-search/3rdparty/fulltext/chinesetokenizer.cpp b/src/plugins/filemanager/dfmplugin-search/3rdparty/fulltext/chinesetokenizer.cpp index bff08c93fc..addb92038a 100644 --- a/src/plugins/filemanager/dfmplugin-search/3rdparty/fulltext/chinesetokenizer.cpp +++ b/src/plugins/filemanager/dfmplugin-search/3rdparty/fulltext/chinesetokenizer.cpp @@ -80,7 +80,6 @@ bool ChineseTokenizer::incrementToken() length = 0; start = offset; - bool last_is_en = false, last_is_num = false; while (true) { wchar_t c; ++offset; @@ -97,41 +96,13 @@ bool ChineseTokenizer::incrementToken() c = ioBuffer[bufferIndex++]; } - if (UnicodeUtil::isLower(c) || UnicodeUtil::isUpper(c)) { - if (last_is_num) { - --bufferIndex; - --offset; - return flush(); - } - - push(c); - if (length == kMaxWordLen) { - return flush(); - } - last_is_en = true; - } else if (UnicodeUtil::isDigit(c)) { - if (last_is_en) { - --bufferIndex; - --offset; - return flush(); - } - - push(c); - if (length == kMaxWordLen) { - return flush(); - } - last_is_num = true; - } else if (UnicodeUtil::isOther(c)) { - if (length > 0) { - --bufferIndex; - --offset; - return flush(); - } - push(c); - return flush(); - } else if (length > 0) { + if (length > 0) { + --bufferIndex; + --offset; return flush(); } + push(c); + return flush(); } } diff --git a/src/plugins/filemanager/dfmplugin-search/searchmanager/searcher/fulltext/fulltextsearcher.cpp b/src/plugins/filemanager/dfmplugin-search/searchmanager/searcher/fulltext/fulltextsearcher.cpp index 0cfb81045d..f9f7675c89 100644 --- a/src/plugins/filemanager/dfmplugin-search/searchmanager/searcher/fulltext/fulltextsearcher.cpp +++ b/src/plugins/filemanager/dfmplugin-search/searchmanager/searcher/fulltext/fulltextsearcher.cpp @@ -394,7 +394,6 @@ bool FullTextSearcherPrivate::doSearch(const QString &path, const QString &keywo } catch (...) { fmWarning() << "Search failed!"; } - return true; } @@ -436,6 +435,19 @@ QString FullTextSearcherPrivate::dealKeyword(const QString &keyword) return newStr.trimmed(); } +QString FullTextSearcherPrivate::dealKeywordEx(const QString &keyword) +{ + auto key = keyword; + for(int i = 0; i < key.length(); i++) { + if(QChar(key[i]).isPrint()) { + key.insert(i, "\\"); + i++; + } + } + + return key; +} + FullTextSearcher::FullTextSearcher(const QUrl &url, const QString &key, QObject *parent) : AbstractSearcher(url, key, parent), d(new FullTextSearcherPrivate(this)) @@ -477,7 +489,7 @@ bool FullTextSearcher::search() return false; const QString path = UrlRoute::urlToPath(searchUrl); - const QString key = d->dealKeyword(keyword); + const QString key = d->dealKeywordEx(keyword).trimmed(); if (path.isEmpty() || key.isEmpty()) { d->status.storeRelease(kCompleted); return false; diff --git a/src/plugins/filemanager/dfmplugin-search/searchmanager/searcher/fulltext/fulltextsearcher_p.h b/src/plugins/filemanager/dfmplugin-search/searchmanager/searcher/fulltext/fulltextsearcher_p.h index a7c9003e90..9f7a156c2b 100644 --- a/src/plugins/filemanager/dfmplugin-search/searchmanager/searcher/fulltext/fulltextsearcher_p.h +++ b/src/plugins/filemanager/dfmplugin-search/searchmanager/searcher/fulltext/fulltextsearcher_p.h @@ -61,6 +61,7 @@ class FullTextSearcherPrivate : public QObject Lucene::DocumentPtr fileDocument(const QString &file); QString dealKeyword(const QString &keyword); + QString dealKeywordEx(const QString &keyword); void doIndexTask(const Lucene::IndexReaderPtr &reader, const Lucene::IndexWriterPtr &writer, const QString &path, TaskType type); void indexDocs(const Lucene::IndexWriterPtr &writer, const QString &file, IndexType type); bool checkUpdate(const Lucene::IndexReaderPtr &reader, const QString &file, IndexType &type);