A community-supported supercharged document management system: scan, index and archive all your documents
Python aiangulararchivingdjangodmsdocument-managementdocument-management-systemllmmachine-learningocroptical-character-recognitionpdf
fixes to the search index
jonaswinkler52b30576408e
diff --git a/src/documents/tasks.py b/src/documents/tasks.pyindex 3c9baad08..cd47892be 100644--- a/src/documents/tasks.py+++ b/src/documents/tasks.py@@ -12,7 +12,9 @@ from documents.sanity_checker import SanityFailedErrordef index_optimize():- index.open_index().optimize()+ ix = index.open_index()+ with AsyncWriter(ix) as writer:+ writer.commit(optimize=True)def index_reindex():diff --git a/src/documents/tests/test_api.py b/src/documents/tests/test_api.pyindex bb0581656..dabae6d82 100644--- a/src/documents/tests/test_api.py+++ b/src/documents/tests/test_api.py@@ -5,6 +5,7 @@ from unittest import mockfrom django.contrib.auth.models import Userfrom pathvalidate import ValidationErrorfrom rest_framework.test import APITestCase+from whoosh.writing import AsyncWriterfrom documents import indexfrom documents.models import Document, Correspondent, DocumentType, Tag@@ -173,7 +174,7 @@ class DocumentApiTest(DirectoriesMixin, APITestCase):d1=Document.objects.create(title="invoice", content="the thing i bought at a shop and paid with bank account", checksum="A", pk=1)d2=Document.objects.create(title="bank statement 1", content="things i paid for in august", pk=2, checksum="B")d3=Document.objects.create(title="bank statement 3", content="things i paid for in september", pk=3, checksum="C")- with index.open_index(False).writer() as writer:+ with AsyncWriter(index.open_index()) as writer:# Note to future self: there is a reason we dont use a model signal handler to update the index: some operations edit many documents at once# (retagger, renamer) and we don't want to open a writer for each of these, but rather perform the entire operation with one writer.# That's why we cant open the writer in a model on_save handler or something.@@ -209,7 +210,7 @@ class DocumentApiTest(DirectoriesMixin, APITestCase):self.assertEqual(len(results), 0)def test_search_multi_page(self):- with index.open_index(False).writer() as writer:+ with AsyncWriter(index.open_index()) as writer:for i in range(55):doc = Document.objects.create(checksum=str(i), pk=i+1, title=f"Document {i+1}", content="content")index.update_document(writer, doc)@@ -248,7 +249,7 @@ class DocumentApiTest(DirectoriesMixin, APITestCase):self.assertEqual(len(results), 5)def test_search_invalid_page(self):- with index.open_index(False).writer() as writer:+ with AsyncWriter(index.open_index()) as writer:for i in range(15):doc = Document.objects.create(checksum=str(i), pk=i+1, title=f"Document {i+1}", content="content")index.update_document(writer, doc)