autocomplete: tune autocorrect algorithm.

Tune autocorrect to produce fewer false positives. Before we used
trigram similarity. Now we use Levenshtein edit distance with a dynamic
typo threshold. Trigram similarity was able to correct large
transpositions (e.g. `miku_hatsune` -> `hatsune_miku`), but it was bad
at correcting small typos. Levenshtein is good at small typos, but can't
correct large transpositions.
This commit is contained in:
evazion
2020-12-13 00:45:22 -06:00
parent 119268e118
commit 6a46aeb55c
5 changed files with 31 additions and 7 deletions

View File

@@ -100,7 +100,7 @@ class AutocompleteService
end
def tag_autocorrect_matches(string)
tags = Tag.nonempty.fuzzy_name_matches(string).order_similarity(string).limit(limit)
tags = Tag.nonempty.autocorrect_matches(string).limit(limit)
tags.map do |tag|
{ type: "tag", label: tag.pretty_name, value: tag.name, category: tag.category, post_count: tag.post_count }