fix: limit global search to 9 IDs and fix more_like_this_ids off-by-one

Global search only displays 3 results but was fetching all matching IDs
and hydrating them via in_bulk. Now passes limit=9 to search_ids().

more_like_this_ids could return limit-1 results when the original doc
appeared in the result set. Now fetches limit+1 and slices after
filtering.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Trenton Holmes
2026-04-06 13:49:23 -07:00
parent 67261287d2
commit 86ac3ba9f1
2 changed files with 5 additions and 2 deletions
+4 -2
View File
@@ -762,14 +762,16 @@ class TantivyBackend:
final_query = self._apply_permission_filter(mlt_query, user)
effective_limit = limit if limit is not None else searcher.num_docs
results = searcher.search(final_query, limit=effective_limit)
# Fetch one extra to account for excluding the original document
results = searcher.search(final_query, limit=effective_limit + 1)
ids = []
for _score, doc_address in results.hits:
result_doc_id = searcher.doc(doc_address).to_dict()["id"][0]
if result_doc_id != doc_id:
ids.append(result_doc_id)
return ids
return ids[:limit] if limit is not None else ids
def batch_update(self, lock_timeout: float = 30.0) -> WriteBatch:
"""
+1
View File
@@ -3136,6 +3136,7 @@ class GlobalSearchView(PassUserMixin):
query,
user=user,
search_mode=SearchMode.TEXT,
limit=OBJECT_LIMIT * 3,
)
docs_by_id = all_docs.in_bulk(matching_ids)
docs = [