fix(B-1): keyword_matcher Strategy 3 requires ALL keyword words to match
Strategy 3 (Fuzzy/Levenshtein) previously returned True if ANY single keyword word matched ANY text word. For multi-word keywords like 'hermes-gateway', this caused false 100% matches when only 'hermes' appeared in text like 'hermes deployment pipeline'. Fix: ALL keyword words must find a fuzzy match in the text. Single-word keywords still work (one word must match). Words shorter than MIN_FUZZY_LEN that reach Strategy 3 cause the keyword to NOT match (they were already checked by Strategy 1/2). Added 5 unit tests: - test_strategy3_multiword_all_words_match - test_strategy3_multiword_only_one_word_matches (the B-1 scenario) - test_strategy3_multiword_no_words_match - test_strategy3_single_word_still_works (regression) - test_strategy3_multiword_fuzzy_typo Applied to both match_keyword() and match_keyword_with_stems(). Ref: Rainer's review .hermes/reviews/rainer/test-anpassung-2026-07-29.md
This commit is contained in:
@@ -260,6 +260,38 @@ class TestMatchKeyword:
|
||||
"""'ddp' vs 'DDP-Client' → MATCH"""
|
||||
assert match_keyword("ddp", "DDP-Client") is True
|
||||
|
||||
# ── Strategy 3: Multi-word fuzzy matching (B-1 fix) ───────────────
|
||||
|
||||
def test_strategy3_multiword_all_words_match(self):
|
||||
"""Multi-word keyword: ALL words must fuzzy-match for Strategy 3."""
|
||||
# 'hermes gateway' (normalized from 'hermes-gateway') vs
|
||||
# 'hermes gateway' → both words match → MATCH
|
||||
assert match_keyword("hermes-gateway", "hermes gateway") is True
|
||||
|
||||
def test_strategy3_multiword_only_one_word_matches(self):
|
||||
"""Multi-word keyword: single word match is NOT enough for Strategy 3."""
|
||||
# 'hermes gateway' (normalized from 'hermes-gateway') vs
|
||||
# 'hermes deployment pipeline' → only 'hermes' matches, 'gateway' doesn't
|
||||
# → NO MATCH (B-1 fix)
|
||||
assert match_keyword("hermes-gateway", "hermes deployment pipeline") is False
|
||||
|
||||
def test_strategy3_multiword_no_words_match(self):
|
||||
"""Multi-word keyword: no words match → NO MATCH."""
|
||||
assert match_keyword("hermes-gateway", "unrelated text here") is False
|
||||
|
||||
def test_strategy3_single_word_still_works(self):
|
||||
"""Single-word keywords still work with Strategy 3 (regression check)."""
|
||||
# 'hermes' (single word) vs 'hermes' → MATCH
|
||||
assert match_keyword("hermes", "hermes") is True
|
||||
# 'hermes' vs 'hermes deployment' → MATCH (exact substring, Strategy 1)
|
||||
assert match_keyword("hermes", "hermes deployment") is True
|
||||
|
||||
def test_strategy3_multiword_fuzzy_typo(self):
|
||||
"""Multi-word keyword with minor typo in one word still matches."""
|
||||
# 'hermes gateway' vs 'hermes gatewy' (typo in 'gateway')
|
||||
# 'hermes' exact match (Strategy 1), 'gatewy' fuzzy-matches 'gateway' (dist=1)
|
||||
assert match_keyword("hermes-gateway", "hermes gatewy") is True
|
||||
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════════════════
|
||||
# match_keyword_exact() Tests
|
||||
|
||||
Reference in New Issue
Block a user