fix: rank repealed search results last

This commit is contained in:
2026-09-16 14:07:28 +03:00
parent dffe072ce2
commit c2537cf445
9 changed files with 37 additions and 17 deletions

View File

@@ -17,7 +17,7 @@ from search.reviews import ReviewSnapshots, ReviewStore
API_VERSION = "v1"
SEARCH_ALGORITHM_VERSION = "search-3"
SEARCH_ALGORITHM_VERSION = "search-4"
LANGUAGES = {"ru", "ky"}
CODE = re.compile(r"^[0-9]+$")
MAX_PAGE_SIZE = 100
@@ -144,8 +144,14 @@ class Api:
"collapse": {"field": "document_code"},
"highlight": {"fields": {f"text_{language}": {"number_of_fragments": 1}}},
}
body["sort"] = [{"_script": {
"type": "number",
"order": "asc",
"script": {"lang": "painless", "source": "doc['status_code'].size() == 0 ? 1 : (doc['status_code'].value == 'active' ? 0 : (doc['status_code'].value == 'repealed' ? 2 : 1))"},
}}]
if sort == "date":
body["sort"] = [{"date_adopted": "desc"}, {"_score": "desc"}]
body["sort"].append({"date_adopted": "desc"})
body["sort"].append({"_score": "desc"})
response = self.query_opensearch(body)
try:
hits = response["hits"]["hits"]