mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-06-24 06:14:19 +00:00
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:
@@ -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:
|
||||
"""
|
||||
|
||||
@@ -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 = [
|
||||
|
||||
Reference in New Issue
Block a user