A community-supported supercharged document management system: scan, index and archive all your documents
Python aiangulararchivingdjangodmsdocument-managementdocument-management-systemllmmachine-learningocroptical-character-recognitionpdf
Fix: dont include doc content on global search results (#14488)
shamoon11c32d352ee6
diff --git a/src/documents/tests/test_api_search.py b/src/documents/tests/test_api_search.pyindex d7a07f5ed..b4ba9df95 100644--- a/src/documents/tests/test_api_search.py+++ b/src/documents/tests/test_api_search.py@@ -2137,29 +2137,6 @@ class TestDocumentSearchApi(DirectoriesMixin, APITestCase):self.assertEqual(len(response.data["documents"]), 1)self.assertEqual(response.data["documents"][0]["id"], title_match.id)- def test_global_search_returns_latest_version_content(self) -> None:- root = Document.objects.create(- title="bank statement",- content="superseded content",- checksum="GSV1",- pk=23,- )- Document.objects.create(- title="bank statement v2",- content="latest content",- checksum="GSV2",- pk=24,- root_document=root,- version_index=1,- )-- self.client.force_authenticate(self.user)-- response = self.client.get("/api/search/?query=bank&db_only=true")- self.assertEqual(response.status_code, status.HTTP_200_OK)- returned = {doc["id"]: doc["content"] for doc in response.data["documents"]}- self.assertEqual(returned.get(root.id), "latest content")-def test_global_search_filters_owned_mail_objects(self) -> None:user1 = UserFactory(username="mail-search-user")user2 = UserFactory(username="other-mail-search-user")diff --git a/src/documents/tests/test_document_list_effective_content_annotation.py b/src/documents/tests/test_document_list_effective_content_annotation.pyindex 4656bff5f..9a1b0978d 100644--- a/src/documents/tests/test_document_list_effective_content_annotation.py+++ b/src/documents/tests/test_document_list_effective_content_annotation.py@@ -423,35 +423,3 @@ class TestTrashAndGlobalSearchEffectiveContentIsNeverPerInstance:[result] = [r for r in response.data["results"] if r["id"] == root.id]assert result["content"] == "own-content"assert _get_effective_content_fallback_queries(ctx) == []-- def test_global_search_db_only_shows_latest_version_content_with_no_extra_query(- self,- admin_client: APIClient,- ) -> None:- """- GIVEN:- - A root document, findable by title, whose own content differs- from its latest version's- WHEN:- - Using the global search endpoint's db_only mode- THEN:- - The response shows the latest version's content, resolved by- GlobalSearchView's own effective_content annotation- - There is no per-instance fallback query- """- root = DocumentFactory(title="findme", content="own-content")- DocumentFactory(- root_document=root,- version_index=1,- content="version-content",- )-- with CaptureQueriesContext(connection) as ctx:- response = admin_client.get(- "/api/search/?query=findme&db_only=true",- )-- assert response.status_code == status.HTTP_200_OK- [result] = [d for d in response.data["documents"] if d["id"] == root.id]- assert result["content"] == "version-content"- assert _get_effective_content_fallback_queries(ctx) == []diff --git a/src/documents/views.py b/src/documents/views.pyindex aaeec8ade..a7e4350e8 100644--- a/src/documents/views.py+++ b/src/documents/views.py@@ -3932,7 +3932,12 @@ class GlobalSearchView(PassUserMixin):"request": request,}- docs_serializer = DocumentSerializer(docs, many=True, context=context)+ docs_serializer = DocumentSerializer(+ docs,+ many=True,+ context=context,+ fields=("id", "title", "created"),+ )saved_views_serializer = SavedViewSerializer(saved_views,many=True,