feat: cross-chat search FTS snippet highlighting (T111.1)
Replace the ``pov_summary`` column in ``search_all_memories``'s SELECT with ``snippet(memories_fts, 0, '<mark>', '</mark>', '…', 32)`` so each match in a result row is wrapped in ``<mark>`` for the search-results UI. The original ``pov_summary`` is still returned alongside as a non-highlighted fallback. Template renders ``r.snippet|safe`` — the only HTML in the snippet output is the configured ``<mark>`` markers, so it is safe to bypass Jinja's auto-escape.
This commit is contained in:
@@ -136,6 +136,22 @@ def test_result_links_navigate_to_chat(client, tmp_path):
|
||||
assert 'href="/chats/chat_a"' in resp.text
|
||||
|
||||
|
||||
def test_search_results_include_fts_snippet_with_highlight(client, tmp_path):
|
||||
"""T111.1: FTS snippet() wraps each match in ``<mark>...</mark>`` so
|
||||
the result row visually highlights the term that matched.
|
||||
|
||||
The seeded ``pov_summary`` is ``the rabbit darted across chat_a``;
|
||||
SQLite's ``snippet()`` returns the column text with each match token
|
||||
wrapped — searching for ``rabbit`` yields a snippet containing
|
||||
``<mark>rabbit</mark>``. Assertion is just that the marker appears
|
||||
(the snippet may be truncated with an ellipsis when the indexed text
|
||||
runs longer than the configured token window)."""
|
||||
_seed_two_chats_with_memories(tmp_path / "test.db")
|
||||
resp = client.get("/search?q=rabbit")
|
||||
assert resp.status_code == 200
|
||||
assert "<mark>rabbit</mark>" in resp.text
|
||||
|
||||
|
||||
def test_search_results_use_batched_lookups(client, tmp_path):
|
||||
"""T106: hydration must not fan out to per-row ``get_bot``/
|
||||
``get_chat``/``get_scene`` calls.
|
||||
|
||||
Reference in New Issue
Block a user