A community-supported supercharged document management system: scan, index and archive all your documents
Python aiangulararchivingdjangodmsdocument-managementdocument-management-systemllmmachine-learningocroptical-character-recognitionpdf
Fix: Don't create a new note highlight generator per note in the loop (#12512)
Trenton H5f5fb263c960
diff --git a/src/documents/search/_backend.py b/src/documents/search/_backend.pyindex 405c24360..2005a436f 100644--- a/src/documents/search/_backend.py+++ b/src/documents/search/_backend.py@@ -532,6 +532,7 @@ class TantivyBackend:# Build result hits with highlightshits: list[SearchHit] = []snippet_generator = None+ notes_snippet_generator = Nonefor rank, (doc_address, score) in enumerate(page_hits, start=offset + 1):# Get the actual document from the searcher using the doc address@@ -558,13 +559,16 @@ class TantivyBackend:# Try notes highlightsif "notes" in doc_dict:- notes_generator = tantivy.SnippetGenerator.create(- searcher,- final_query,- self._schema,- "notes",+ if notes_snippet_generator is None:+ notes_snippet_generator = tantivy.SnippetGenerator.create(+ searcher,+ final_query,+ self._schema,+ "notes",+ )+ notes_snippet = notes_snippet_generator.snippet_from_doc(+ actual_doc,)- notes_snippet = notes_generator.snippet_from_doc(actual_doc)if notes_snippet:highlights["notes"] = str(notes_snippet)