autocomplete: fix ranking of exact matches.
Fix a bug where searching for `sakana~` ranked `sakana~_(meme)` beneath random artist tags containing the word `sakana`. Now, if the search contains punctuation, we rank exact matches first, even for small tags. Before we ranked exact matches for small tags lower than inexact matches for large tags. If the search contains punctuation, it's a strong signal the user is looking for an exact match.
This commit is contained in:
@@ -157,7 +157,14 @@ class AutocompleteService
|
||||
exact = name == string ? 1 : 0
|
||||
substr = name.include?(string) ? 1 : 0
|
||||
|
||||
[-large, -exact, -substr, -post_count, result[:value]]
|
||||
# If the search contains punctuation, rank exact matches first then substring matches. Otherwise, if it
|
||||
# doesn't contain any punctuation, rank exact matches among large tags before small tags. This is so we
|
||||
# rank exact matches first, but not if they're random small character or artist tags with simple names.
|
||||
if string.match?(/[^a-zA-Z0-9]/)
|
||||
[-exact, -substr, -post_count, result[:value]]
|
||||
else
|
||||
[-large, -exact, -substr, -post_count, result[:value]]
|
||||
end
|
||||
end
|
||||
|
||||
results.take(limit)
|
||||
|
||||
Reference in New Issue
Block a user