mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-09 09:58:20 -05:00
fixes to the search index
This commit is contained in:
parent
a1f5ddede8
commit
52b3057640
@ -12,7 +12,9 @@ from documents.sanity_checker import SanityFailedError
|
|||||||
|
|
||||||
|
|
||||||
def index_optimize():
|
def index_optimize():
|
||||||
index.open_index().optimize()
|
ix = index.open_index()
|
||||||
|
with AsyncWriter(ix) as writer:
|
||||||
|
writer.commit(optimize=True)
|
||||||
|
|
||||||
|
|
||||||
def index_reindex():
|
def index_reindex():
|
||||||
|
@ -5,6 +5,7 @@ from unittest import mock
|
|||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from pathvalidate import ValidationError
|
from pathvalidate import ValidationError
|
||||||
from rest_framework.test import APITestCase
|
from rest_framework.test import APITestCase
|
||||||
|
from whoosh.writing import AsyncWriter
|
||||||
|
|
||||||
from documents import index
|
from documents import index
|
||||||
from documents.models import Document, Correspondent, DocumentType, Tag
|
from 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)
|
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")
|
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")
|
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
|
# 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.
|
# (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.
|
# 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)
|
self.assertEqual(len(results), 0)
|
||||||
|
|
||||||
def test_search_multi_page(self):
|
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):
|
for i in range(55):
|
||||||
doc = Document.objects.create(checksum=str(i), pk=i+1, title=f"Document {i+1}", content="content")
|
doc = Document.objects.create(checksum=str(i), pk=i+1, title=f"Document {i+1}", content="content")
|
||||||
index.update_document(writer, doc)
|
index.update_document(writer, doc)
|
||||||
@ -248,7 +249,7 @@ class DocumentApiTest(DirectoriesMixin, APITestCase):
|
|||||||
self.assertEqual(len(results), 5)
|
self.assertEqual(len(results), 5)
|
||||||
|
|
||||||
def test_search_invalid_page(self):
|
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):
|
for i in range(15):
|
||||||
doc = Document.objects.create(checksum=str(i), pk=i+1, title=f"Document {i+1}", content="content")
|
doc = Document.objects.create(checksum=str(i), pk=i+1, title=f"Document {i+1}", content="content")
|
||||||
index.update_document(writer, doc)
|
index.update_document(writer, doc)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user