Enhancement: always place search term first in autocomplete results (#6142)

This commit is contained in:
shamoon 2024-03-21 12:03:17 -07:00 committed by GitHub
parent ebe1479503
commit fc68f79cc8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 28 additions and 2 deletions

View file

@ -468,10 +468,14 @@ def autocomplete(
termCounts = Counter()
if results.has_matched_terms():
for hit in results:
for _, term in hit.matched_terms():
termCounts[term] += 1
for _, match in hit.matched_terms():
termCounts[match] += 1
terms = [t for t, _ in termCounts.most_common(limit)]
term_encoded = term.encode("UTF-8")
if term_encoded in terms:
terms.insert(0, terms.pop(terms.index(term_encoded)))
return terms