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

All: Fix filters when language is in Korean #3947

Merged
merged 2 commits into from Oct 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 26 additions & 3 deletions ReactNativeClient/lib/services/searchengine/SearchEngine.js
Expand Up @@ -577,6 +577,22 @@ class SearchEngine {
keys.push(col);
}

//
// The object "allTerms" is used for query construction purposes (this contains all the filter terms)
// Since this is used for the FTS match query, we need to normalize text, title and body terms.
// Note, we're not normalizing terms like tag because these are matched using SQL LIKE operator and so we must preserve their diacritics.
//
// The object "terms" only include text, title, body terms and is used for highlighting.
// By not normalizing the text, title, body in "terms", highlighting still works correctly for words with diacritics.
//

allTerms = allTerms.map(x => {
if (x.name === 'text' || x.name === 'title' || x.name === 'body') {
return Object.assign(x, { value: this.normalizeText_(x.value) });
}
return x;
});

return {
termCount: termCount,
keys: keys,
Expand Down Expand Up @@ -635,7 +651,15 @@ class SearchEngine {
// If preferredSearchType is "fts" we auto-detect anyway
// because it's not always supported.

const st = scriptType(query);
let allTerms = [];
try {
allTerms = filterParser(query);
} catch (error) {
console.warn(error);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we proceed with the rest of the code if there was an error here? What kind of error be thrown in this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, we could throw an error here and exit from this function. But there needs to be a catch statement higher up.

Errors would be invalid filters like -notebook:abc, type:blah , foo:bar etc.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it seems that getting the error displayed somewhere in the UI wouldn't be that easy, so let's keep it as it is now. A warning is a good start and there's the doc to explain how the query should be formatted.

}

const textQuery = allTerms.filter(x => x.name === 'text' || x.name == 'title' || x.name == 'body').map(x => x.value).join(' ');
const st = scriptType(textQuery);

if (!Setting.value('db.ftsEnabled') || ['ja', 'zh', 'ko', 'th'].indexOf(st) >= 0) {
return SearchEngine.SEARCH_TYPE_BASIC;
Expand All @@ -653,12 +677,11 @@ class SearchEngine {
fuzzy: Setting.value('db.fuzzySearchEnabled') === 1,
}, options);

searchString = this.normalizeText_(searchString);

const searchType = this.determineSearchType_(searchString, options);

if (searchType === SearchEngine.SEARCH_TYPE_BASIC) {
// Non-alphabetical languages aren't support by SQLite FTS (except with extensions which are not available in all platforms)
searchString = this.normalizeText_(searchString);
const rows = await this.basicSearch(searchString);
const parsedQuery = await this.parseQuery(searchString);
this.processResults_(rows, parsedQuery, true);
Expand Down