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

Handle multi-word search queries #135

Merged
merged 3 commits into from
Nov 21, 2020
Merged

Handle multi-word search queries #135

merged 3 commits into from
Nov 21, 2020

Conversation

skalee
Copy link
Contributor

@skalee skalee commented Jul 25, 2020

In search, match every word of the query separately. This solves issues with reordered or missing words in a search query, which used to prevent terms from being matched. Fixes #131.

This pull request brings also some code-style improvements: SearchQuery class has been extracted to contain added logic, and string.indexOf() has been replaced with string.includes().

@skalee skalee changed the title Fix handling multi-word search queries #131 Handle multi-word search queries Jul 25, 2020
@ronaldtse
Copy link
Member

Thanks @skalee , feel free to merge when ready.

@skalee
Copy link
Contributor Author

skalee commented Jul 31, 2020

There is a problem with Unicode property escapes in regular expressions like /\p{Letter}+/ug, which are supported in modern browsers only, and which Babel is unable to rewrite using older syntax. Unfortunately, in JavaScript \w does not match non-Latin characters, not even in Unicode mode.

This probably can be worked around by defining a set of usual separator characters (\s, -, etc.), but if possible, I'd rather find some way to make Unicode property escapes working. I don't know yet, maybe it's just a matter of reconfiguring Babel or something.

That's why it's a draft. Apart from that, it works.

Use JavaScript's string.includes() instead of indexOf(), as it is way
more meaningful and clean.
In search, match every word of the query separately.  This solves issues
with reordered or missing words in a search query, which used to prevent
terms from being matched.
@skalee
Copy link
Contributor Author

skalee commented Nov 20, 2020

Looks like in the meantime they've added a new plugin (https://www.npmjs.com/package/@babel/plugin-proposal-unicode-property-regex) to Babel and since then it works even in IE10.

@skalee skalee marked this pull request as ready for review November 20, 2020 11:32
@skalee skalee merged commit 25908b2 into master Nov 21, 2020
@skalee skalee deleted the multi-word branch November 21, 2020 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix handling multi-word search queries
2 participants