From b4b0f802e15353b587b15e19ee66ef4899c66171 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Fri, 7 Mar 2025 13:31:23 -0800 Subject: [PATCH] Fix: correct all results with whoosh queries (#9331) --- src/paperless/views.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/paperless/views.py b/src/paperless/views.py index fdd7c21a4..050bb3f61 100644 --- a/src/paperless/views.py +++ b/src/paperless/views.py @@ -32,6 +32,7 @@ from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response from rest_framework.viewsets import ModelViewSet +from documents.index import DelayedQuery from documents.permissions import PaperlessObjectPermissions from paperless.filters import GroupFilterSet from paperless.filters import UserFilterSet @@ -66,17 +67,17 @@ class StandardPagination(PageNumberPagination): ) def get_all_result_ids(self): - ids = [] - if hasattr(self.page.paginator.object_list, "saved_results"): - results_page = self.page.paginator.object_list.saved_results[0] - if results_page is not None: - for i in range(len(results_page.results.docs())): - try: - fields = results_page.results.fields(i) - if "id" in fields: - ids.append(fields["id"]) - except Exception: - pass + query = self.page.paginator.object_list + if isinstance(query, DelayedQuery): + try: + ids = [ + query.searcher.ixreader.stored_fields( + doc_num, + )["id"] + for doc_num in query.saved_results.get(0).results.docs() + ] + except Exception: + pass else: ids = self.page.paginator.object_list.values_list("pk", flat=True) return ids