fix: retain fallback for act topic searches
This commit is contained in:
1 parent
cf510f08f8
commit
3afac00394
2 files changed
+27
-10
No files matched your search
+17
-10
@@ -37,16 +37,23 @@ def relaxed_query_text(language: str, query: str) -> str:
|
||||
value = query.strip()
|
||||
for prefix in BOILERPLATE_PREFIXES[language]:
|
||||
if value.casefold().startswith(prefix):
|
||||
return value[len(prefix):].strip()
|
||||
return value
|
||||
|
||||
|
||||
def is_named_act_query(language: str, query: str) -> bool:
|
||||
act_terms = {
|
||||
"ru": r"кодекс\w*|конституци\w*|закон\s+(?:кыргызской\s+республики|кр)|гк|ук|нк|коап|гпк|упк|уик",
|
||||
"ky": r"кодекс\w*|конституци\w*|мыйзам\w*|жк|үк|салык\s+кодекси",
|
||||
value = value[len(prefix):].strip()
|
||||
break
|
||||
act_patterns = {
|
||||
"ru": (
|
||||
r"\b(?:кодекс\w*|конституци\w*|закон\w*|гк|ук|нк|коап|гпк|упк|уик)\b",
|
||||
r"\b(?:гражданск\w*|уголовн\w*|налогов\w*|труд\w*|семейн\w*|административн\w*|процессуальн\w*|правонарушени\w*|кыргызск\w*|республик\w*|кр|о|об|и)\b",
|
||||
),
|
||||
"ky": (
|
||||
r"\b(?:кодекс\w*|конституци\w*|мыйзам\w*|жк|үк)\b",
|
||||
r"\b(?:жарандык\w*|кылмыш\w*|салык\w*|эмгек\w*|үй-бүлө\w*|административдик\w*|процесстик\w*|бузуу\w*|кыргыз\w*|республика\w*|кр)\b",
|
||||
),
|
||||
}
|
||||
return bool(re.search(rf"\b(?:{act_terms[language]})\b", query.casefold()))
|
||||
marker, title_terms = act_patterns[language]
|
||||
if re.search(marker, value.casefold()):
|
||||
value = re.sub(rf"{marker}|{title_terms}", " ", value, flags=re.IGNORECASE)
|
||||
value = re.sub(r"[^\w\-]+", " ", value).strip()
|
||||
return value
|
||||
|
||||
|
||||
def query_variants(language: str, query: str) -> list[str]:
|
||||
@@ -136,7 +143,7 @@ def build_search_query(language: str, query: str) -> dict:
|
||||
for variant in variants
|
||||
]
|
||||
relaxed_text = []
|
||||
if not registration_clauses and not is_named_act_query(language, query):
|
||||
if not registration_clauses:
|
||||
seen_relaxed = set()
|
||||
for variant in variants:
|
||||
value = relaxed_query_text(language, variant)
|
||||
|
||||
@@ -89,6 +89,16 @@ class SearchRelevanceTest(unittest.TestCase):
|
||||
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))
|
||||
|
||||
for language, query, expected in (
|
||||
("ru", "Налоговый кодекс ответственность за неуплату налога", "ответственность за неуплату налога"),
|
||||
("ru", "закон о труде порядок выплаты зарплаты", "порядок выплаты зарплаты"),
|
||||
("ky", "Кыргыз Республикасынын Конституциясы укуктарды чектөө тартиби", "укуктарды чектөө тартиби"),
|
||||
):
|
||||
body = json.loads(build_search_body(language, query, 10))
|
||||
clauses = body["query"]["bool"]["must"]["bool"]["should"]
|
||||
fallback = next(item["multi_match"] for item in clauses if item.get("multi_match", {}).get("boost") == 0.1)
|
||||
self.assertEqual(fallback["query"], expected)
|
||||
|
||||
def test_company_registration_intent_boosts_current_documents(self):
|
||||
for language, query, status in (
|
||||
("ru", "как открыть ОсОО", "Действует"),
|
||||
|
||||
Reference in new issue
Block a user