fix: require all tokens for short fallbacks
This commit is contained in:
1 parent
3b56445bb2
commit
6f8b668907
2 files changed
+15
-3
No files matched your search
@@ -42,7 +42,11 @@ def relaxed_query_text(language: str, query: str) -> str:
|
||||
|
||||
|
||||
def is_named_act_query(language: str, query: str) -> bool:
|
||||
return language == "ru" and bool(re.search(r"\b(?:кодекс\w*|конституци\w*|закон\s+кыргызской\s+республики)\b", query.casefold()))
|
||||
act_terms = {
|
||||
"ru": r"кодекс\w*|конституци\w*|закон\s+(?:кыргызской\s+республики|кр)|гк|ук|нк|коап|гпк|упк|уик",
|
||||
"ky": r"кодекс\w*|конституци\w*|мыйзам\w*|жк|үк|салык\s+кодекси",
|
||||
}
|
||||
return bool(re.search(rf"\b(?:{act_terms[language]})\b", query.casefold()))
|
||||
|
||||
|
||||
def query_variants(language: str, query: str) -> list[str]:
|
||||
@@ -142,13 +146,14 @@ 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": "75%",
|
||||
"minimum_should_match": minimum_should_match,
|
||||
"boost": 0.1,
|
||||
}
|
||||
})
|
||||
|
||||
@@ -75,7 +75,14 @@ class SearchRelevanceTest(unittest.TestCase):
|
||||
|
||||
short_template = json.loads(build_search_body("ru", "как регулируется взыскание алиментов", 10))
|
||||
short_clauses = short_template["query"]["bool"]["must"]["bool"]["should"]
|
||||
self.assertTrue(any(item.get("multi_match", {}).get("query") == "взыскание алиментов" and item["multi_match"].get("boost") == 0.1 for item in short_clauses))
|
||||
short_fallback = next(item["multi_match"] for item in short_clauses if item.get("multi_match", {}).get("boost") == 0.1)
|
||||
self.assertEqual(short_fallback["query"], "взыскание алиментов")
|
||||
self.assertEqual(short_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"]
|
||||
self.assertFalse(any(item.get("multi_match", {}).get("boost") == 0.1 for item in act_clauses))
|
||||
|
||||
def test_company_registration_intent_boosts_current_documents(self):
|
||||
for language, query, status in (
|
||||
|
||||
Reference in new issue
Block a user