fix: guard relaxed search from stopwords

This commit is contained in:
agent committed 2026-09-25 09:03:50 +03:00
1 parent 6f8b668907
commit a3d82b45b5
2 files changed
+7 -3

No files matched your search

+1 -2
View File
@@ -146,14 +146,13 @@ def build_search_query(language: str, query: str) -> dict:
if len(words) < 3 and not any(len(word) >= 5 for word in words):
continue
seen_relaxed.add(value)
minimum_should_match = 2 if len(words) == 2 else "75%"
relaxed_text.append({
"multi_match": {
"query": value,
"fields": [f"document_name_{language}^4", f"text_{language}"],
"type": "cross_fields",
"operator": "OR",
"minimum_should_match": minimum_should_match,
"minimum_should_match": 2,
"boost": 0.1,
}
})
+6 -1
View File
@@ -57,7 +57,7 @@ class SearchRelevanceTest(unittest.TestCase):
self.assertEqual(strict[0]["query"], "правовое регулирование расторжение договора аренды")
self.assertEqual(relaxed[0]["query"], "расторжение договора аренды")
self.assertEqual(relaxed[0]["operator"], "OR")
self.assertEqual(relaxed[0]["minimum_should_match"], "75%")
self.assertEqual(relaxed[0]["minimum_should_match"], 2)
self.assertNotIn("boost", strict[0])
def test_relaxed_match_supports_kyrgyz_and_avoids_short_named_acts(self):
@@ -79,6 +79,11 @@ class SearchRelevanceTest(unittest.TestCase):
self.assertEqual(short_fallback["query"], "взыскание алиментов")
self.assertEqual(short_fallback["minimum_should_match"], 2)
stopword_query = json.loads(build_search_body("ru", "правовое регулирование права и обязанности", 10))
stopword_clauses = stopword_query["query"]["bool"]["must"]["bool"]["should"]
stopword_fallback = next(item["multi_match"] for item in stopword_clauses if item.get("multi_match", {}).get("boost") == 0.1)
self.assertEqual(stopword_fallback["minimum_should_match"], 2)
for language, query in (("ru", "изменения ГК КР"), ("ky", "Кыргыз Республикасынын Конституциясы")):
act_body = json.loads(build_search_body(language, query, 10))
act_clauses = act_body["query"]["bool"]["must"]["bool"]["should"]