fix: prioritize current company registration act
This commit is contained in:
@@ -22,7 +22,7 @@ LEGAL_FORM_ALIASES = {
|
||||
"жоопкерчилиги чектелген коом": ("жчк",),
|
||||
},
|
||||
}
|
||||
COMPANY_REGISTRATION_DOCUMENTS = ("667", "4")
|
||||
COMPANY_REGISTRATION_DOCUMENTS = (("230044970", 3000), ("667", 2000), ("4", 1000))
|
||||
|
||||
|
||||
def query_variants(language: str, query: str) -> list[str]:
|
||||
@@ -75,7 +75,7 @@ def company_registration_clauses(language: str, query: str) -> list[dict]:
|
||||
}
|
||||
}
|
||||
|
||||
return [clause(COMPANY_REGISTRATION_DOCUMENTS[0], 2000), clause(COMPANY_REGISTRATION_DOCUMENTS[1], 1000)]
|
||||
return [clause(code, boost) for code, boost in COMPANY_REGISTRATION_DOCUMENTS]
|
||||
|
||||
|
||||
def build_search_query(language: str, query: str) -> dict:
|
||||
@@ -93,7 +93,7 @@ def build_search_query(language: str, query: str) -> dict:
|
||||
]
|
||||
planned = {"should": [*full_text, *intent_clauses], "minimum_should_match": 1}
|
||||
if intent_clauses:
|
||||
planned["filter"] = [{"terms": {"document_code": list(COMPANY_REGISTRATION_DOCUMENTS)}}]
|
||||
planned["filter"] = [{"terms": {"document_code": [code for code, _ in COMPANY_REGISTRATION_DOCUMENTS]}}]
|
||||
return {"bool": planned}
|
||||
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ class SearchApiTest(unittest.TestCase):
|
||||
body = json.loads(request.call_args.args[2])
|
||||
planned = body["query"]["bool"]["must"]["bool"]
|
||||
self.assertEqual(planned["minimum_should_match"], 1)
|
||||
self.assertIn({"terms": {"document_code": ["667", "4"]}}, planned["filter"])
|
||||
self.assertIn({"terms": {"document_code": ["230044970", "667", "4"]}}, planned["filter"])
|
||||
self.assertTrue(any("constant_score" in clause for clause in planned["should"]))
|
||||
self.assertTrue(any("общество с ограниченной ответственностью" in clause.get("multi_match", {}).get("query", "") for clause in planned["should"]))
|
||||
|
||||
|
||||
@@ -55,13 +55,13 @@ class SearchRelevanceTest(unittest.TestCase):
|
||||
body = json.loads(build_search_body(language, query, 10))
|
||||
search_query = body["query"]["bool"]["must"]["bool"]
|
||||
self.assertEqual(search_query["minimum_should_match"], 1)
|
||||
self.assertEqual(search_query["filter"], [{"terms": {"document_code": list(COMPANY_REGISTRATION_DOCUMENTS)}}])
|
||||
self.assertEqual(search_query["filter"], [{"terms": {"document_code": [code for code, _ in COMPANY_REGISTRATION_DOCUMENTS]}}])
|
||||
self.assertTrue(all(clause.get("multi_match", {}).get("operator") == "OR" for clause in search_query["should"] if "multi_match" in clause))
|
||||
boosts = [clause["constant_score"] for clause in search_query["should"] if "constant_score" in clause]
|
||||
self.assertEqual([item["boost"] for item in boosts], [2000, 1000])
|
||||
self.assertEqual([item["boost"] for item in boosts], [boost for _, boost in COMPANY_REGISTRATION_DOCUMENTS])
|
||||
self.assertEqual(
|
||||
[item["filter"]["bool"]["filter"][0]["term"]["document_code"] for item in boosts],
|
||||
list(COMPANY_REGISTRATION_DOCUMENTS),
|
||||
[code for code, _ in COMPANY_REGISTRATION_DOCUMENTS],
|
||||
)
|
||||
self.assertTrue(all(item["filter"]["bool"]["filter"][1] == {"term": {f"status_{language}": status}} for item in boosts))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user