feat(ebook-search): implement async phrase matching for chunks and add ChunkPhraseHit model

This commit is contained in:
2026-07-24 11:38:51 -04:00
parent e010756e09
commit 9f126fedc7
4 changed files with 74 additions and 28 deletions
@@ -33,9 +33,11 @@ from python.ebook_search.protected_phrases.matching import (
detect_protected_phrases_for_query,
index_chunk_phrase_mentions,
load_phrase_lookup,
phrase_hits_for_chunks,
resolve_overlaps,
)
from python.ebook_search.protected_phrases.models import (
ChunkPhraseHit,
LLMJudgment,
PhraseCandidate,
PhraseMatch,
@@ -353,6 +355,9 @@ async def test_index_chunk_phrase_mentions_uses_normalized_window_lookup(
assert mention.chunk_id == chunk.id
assert mention.phrase_id == phrase.id
assert chunk.text[mention.start_char : mention.end_char] == "lock-in"
assert await phrase_hits_for_chunks(session, chunk_ids=[chunk.id], phrase_ids=[phrase.id]) == {
chunk.id: (ChunkPhraseHit(phrase_id=phrase.id, phrase_text="lock in", mention_count=1),)
}
@pytest.mark.usefixtures("worker_pool")