Search matches words in any order (#111) #141
Merged
+39
−5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The search used to look for the whole text as one phrase, so "noir pinot" found far fewer wines than "pinot noir", and "creek zinfandel" found nothing.
The backend now splits the search text into words and requires each word to be somewhere in the wine's name, winery, region or grapes. The order of the words no longer matters.
Changes
backend/src/wine-query.ts: one search condition per word instead of one for the whole text. A search uses at most 10 words, so a single request cannot make the query very large.backend/src/wine-query.test.ts: tests for word order, a repeated word, a search with only spaces, and the 10-word limit.README.md: the feature table describes the new behaviour, and the known issue about "noir pinot" is removed.Testing
npm run checkpasses.I loaded the Full dataset's 100 646 wines into a local database and timed the queries the backend sends:
The slowest searches are those with only one or two letters, such as "de". They cannot use the search index, which was also the case before this change.
These times are from a laptop, not the VM. The VM is slower, so the issue's goal of under 100 ms on the VM is likely met but not measured there.
Closes #111