geolexica / geolexica-server

Generalized backend for Geolexica sites
2 stars 1 forks source link

Handle multi-word search queries #135

Closed skalee closed 3 years ago

skalee commented 4 years ago

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().

ronaldtse commented 4 years ago

Thanks @skalee , feel free to merge when ready.

skalee commented 4 years ago

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.

skalee commented 3 years ago

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.