mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-11-21 13:02:40 +00:00
Fix: break autocomplete frequency ties alphabetically for stable output
Equal-frequency words were non-deterministically ordered; sort key is now (-count, word) so ties resolve alphabetically. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
897f7d2199
commit
8107b7d209
1 file changed
+3
-3
@@ -538,11 +538,11 @@ class TantivyBackend:
|
||||
if "autocomplete_word" in doc_dict:
|
||||
word_counts.update(doc_dict["autocomplete_word"])
|
||||
|
||||
# Filter to prefix matches, then sort by document frequency descending
|
||||
# so the most-used matching word comes first.
|
||||
# Filter to prefix matches, sort by document frequency descending;
|
||||
# break ties alphabetically for stable, deterministic output.
|
||||
matches = sorted(
|
||||
(w for w in word_counts if w.startswith(normalized_term)),
|
||||
key=lambda w: -word_counts[w],
|
||||
key=lambda w: (-word_counts[w], w),
|
||||
)
|
||||
|
||||
return matches[:limit]
|
||||
|
||||
Reference in new issue
Block a user