mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-11-03 03:16:10 -06:00 
			
		
		
		
	Fix note sorting, testing, bump search index version
This commit is contained in:
		@@ -80,7 +80,7 @@ django_checks() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
search_index() {
 | 
					search_index() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	local -r index_version=4
 | 
						local -r index_version=5
 | 
				
			||||||
	local -r index_version_file=${DATA_DIR}/.index_version
 | 
						local -r index_version_file=${DATA_DIR}/.index_version
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if [[ (! -f "${index_version_file}") || $(<"${index_version_file}") != "$index_version" ]]; then
 | 
						if [[ (! -f "${index_version_file}") || $(<"${index_version_file}") != "$index_version" ]]; then
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -54,6 +54,7 @@ def get_schema():
 | 
				
			|||||||
        path_id=NUMERIC(),
 | 
					        path_id=NUMERIC(),
 | 
				
			||||||
        has_path=BOOLEAN(),
 | 
					        has_path=BOOLEAN(),
 | 
				
			||||||
        notes=TEXT(),
 | 
					        notes=TEXT(),
 | 
				
			||||||
 | 
					        num_notes=NUMERIC(sortable=True, signed=False),
 | 
				
			||||||
        owner=TEXT(),
 | 
					        owner=TEXT(),
 | 
				
			||||||
        owner_id=NUMERIC(),
 | 
					        owner_id=NUMERIC(),
 | 
				
			||||||
        has_owner=BOOLEAN(),
 | 
					        has_owner=BOOLEAN(),
 | 
				
			||||||
@@ -138,6 +139,7 @@ def update_document(writer: AsyncWriter, doc: Document):
 | 
				
			|||||||
        path_id=doc.storage_path.id if doc.storage_path else None,
 | 
					        path_id=doc.storage_path.id if doc.storage_path else None,
 | 
				
			||||||
        has_path=doc.storage_path is not None,
 | 
					        has_path=doc.storage_path is not None,
 | 
				
			||||||
        notes=notes,
 | 
					        notes=notes,
 | 
				
			||||||
 | 
					        num_notes=len(notes),
 | 
				
			||||||
        owner=doc.owner.username if doc.owner else None,
 | 
					        owner=doc.owner.username if doc.owner else None,
 | 
				
			||||||
        owner_id=doc.owner.id if doc.owner else None,
 | 
					        owner_id=doc.owner.id if doc.owner else None,
 | 
				
			||||||
        has_owner=doc.owner is not None,
 | 
					        has_owner=doc.owner is not None,
 | 
				
			||||||
@@ -266,6 +268,7 @@ class DelayedQuery:
 | 
				
			|||||||
            "correspondent__name": "correspondent",
 | 
					            "correspondent__name": "correspondent",
 | 
				
			||||||
            "document_type__name": "type",
 | 
					            "document_type__name": "type",
 | 
				
			||||||
            "archive_serial_number": "asn",
 | 
					            "archive_serial_number": "asn",
 | 
				
			||||||
 | 
					            "num_notes": "num_notes",
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if field.startswith("-"):
 | 
					        if field.startswith("-"):
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1150,6 +1150,8 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase):
 | 
				
			|||||||
        self.assertEqual(r.data["count"], 4)
 | 
					        self.assertEqual(r.data["count"], 4)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_search_sorting(self):
 | 
					    def test_search_sorting(self):
 | 
				
			||||||
 | 
					        u1 = User.objects.create_user("user1")
 | 
				
			||||||
 | 
					        u2 = User.objects.create_user("user2")
 | 
				
			||||||
        c1 = Correspondent.objects.create(name="corres Ax")
 | 
					        c1 = Correspondent.objects.create(name="corres Ax")
 | 
				
			||||||
        c2 = Correspondent.objects.create(name="corres Cx")
 | 
					        c2 = Correspondent.objects.create(name="corres Cx")
 | 
				
			||||||
        c3 = Correspondent.objects.create(name="corres Bx")
 | 
					        c3 = Correspondent.objects.create(name="corres Bx")
 | 
				
			||||||
@@ -1159,6 +1161,7 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase):
 | 
				
			|||||||
            content="test",
 | 
					            content="test",
 | 
				
			||||||
            archive_serial_number=2,
 | 
					            archive_serial_number=2,
 | 
				
			||||||
            title="3",
 | 
					            title="3",
 | 
				
			||||||
 | 
					            owner=u1,
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        d2 = Document.objects.create(
 | 
					        d2 = Document.objects.create(
 | 
				
			||||||
            checksum="2",
 | 
					            checksum="2",
 | 
				
			||||||
@@ -1166,6 +1169,7 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase):
 | 
				
			|||||||
            content="test",
 | 
					            content="test",
 | 
				
			||||||
            archive_serial_number=3,
 | 
					            archive_serial_number=3,
 | 
				
			||||||
            title="2",
 | 
					            title="2",
 | 
				
			||||||
 | 
					            owner=u2,
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        d3 = Document.objects.create(
 | 
					        d3 = Document.objects.create(
 | 
				
			||||||
            checksum="3",
 | 
					            checksum="3",
 | 
				
			||||||
@@ -1174,6 +1178,21 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase):
 | 
				
			|||||||
            archive_serial_number=1,
 | 
					            archive_serial_number=1,
 | 
				
			||||||
            title="1",
 | 
					            title="1",
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					        Note.objects.create(
 | 
				
			||||||
 | 
					            note="This is a note.",
 | 
				
			||||||
 | 
					            document=d1,
 | 
				
			||||||
 | 
					            user=u1,
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					        Note.objects.create(
 | 
				
			||||||
 | 
					            note="This is a note.",
 | 
				
			||||||
 | 
					            document=d1,
 | 
				
			||||||
 | 
					            user=u1,
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					        Note.objects.create(
 | 
				
			||||||
 | 
					            note="This is a note.",
 | 
				
			||||||
 | 
					            document=d3,
 | 
				
			||||||
 | 
					            user=u1,
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        with AsyncWriter(index.open_index()) as writer:
 | 
					        with AsyncWriter(index.open_index()) as writer:
 | 
				
			||||||
            for doc in Document.objects.all():
 | 
					            for doc in Document.objects.all():
 | 
				
			||||||
@@ -1202,6 +1221,14 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase):
 | 
				
			|||||||
            search_query("&ordering=-correspondent__name"),
 | 
					            search_query("&ordering=-correspondent__name"),
 | 
				
			||||||
            [d2.id, d3.id, d1.id],
 | 
					            [d2.id, d3.id, d1.id],
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					        self.assertListEqual(
 | 
				
			||||||
 | 
					            search_query("&ordering=num_notes"),
 | 
				
			||||||
 | 
					            [d2.id, d3.id, d1.id],
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					        self.assertListEqual(
 | 
				
			||||||
 | 
					            search_query("&ordering=-num_notes"),
 | 
				
			||||||
 | 
					            [d1.id, d3.id, d2.id],
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_statistics(self):
 | 
					    def test_statistics(self):
 | 
				
			||||||
        doc1 = Document.objects.create(
 | 
					        doc1 = Document.objects.create(
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user