Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: There are issues with searching for special characters and numbers based on keywords in the file content #2290

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,6 @@ bool FullTextSearcherPrivate::doSearch(const QString &path, const QString &keywo
} catch (...) {
fmWarning() << "Search failed!";
}

return true;
}

Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading