fix: reuse notes snippet generator across docs in highlight_hits()

The notes SnippetGenerator was being recreated per document instead of
lazily initialized once like the content generator.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Trenton Holmes
2026-04-06 13:23:14 -07:00
parent e3076b8d62
commit ca077ba1e3
+9 -7
View File
@@ -536,6 +536,7 @@ class TantivyBackend:
searcher = self._index.searcher()
snippet_generator = None
notes_snippet_generator = None
hits: list[SearchHit] = []
for rank, doc_id in enumerate(doc_ids, start=1):
@@ -571,13 +572,14 @@ class TantivyBackend:
highlights["content"] = str(content_snippet)
if "notes" in doc_dict:
notes_generator = tantivy.SnippetGenerator.create(
searcher,
user_query,
self._schema,
"notes",
)
notes_snippet = notes_generator.snippet_from_doc(actual_doc)
if notes_snippet_generator is None:
notes_snippet_generator = tantivy.SnippetGenerator.create(
searcher,
user_query,
self._schema,
"notes",
)
notes_snippet = notes_snippet_generator.snippet_from_doc(actual_doc)
if notes_snippet:
highlights["notes"] = str(notes_snippet)