Switch from bigrams to trigrams for search #342
Merged
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.
Trigrams can provide more accurate search results than bigrams. For example, using bigrams, searching for "sel" would attempt to match the ngrams " s", "se", and "el". For the Rails API (at
7c65a4b83b583f4f
), the top result isActiveModel::Serializers
due to "Model" matching "el" and ":Serial" matching " s" and "se". However, using trigrams, "sel" would attempt to match " se" and "sel". In that case, for the Rails API, the top result isActiveRecord::QueryMethods#select
.The downside to using trigrams is that the search index increases from 2.9 MB to 8.6 MB. But the data compresses well, so when gzipped the size only increases from 474 kB to 670 kB. And browser heap snapshot size stays reasonably small, increasing from 6.8 MB to 11.1 MB in Firefox and 8.0 MB to 22.2 MB in Chrome.