From 2a7ba94f52b7fc0415ed825729ed7bd52707a5de Mon Sep 17 00:00:00 2001 From: Friedrich Lindenberg Date: Fri, 19 Jan 2024 11:03:59 +0100 Subject: [PATCH] Apply weird re-balancing search type to queries --- yente/search/queries.py | 5 ++++- yente/search/search.py | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/yente/search/queries.py b/yente/search/queries.py index bb8507bd..4c140902 100644 --- a/yente/search/queries.py +++ b/yente/search/queries.py @@ -1,3 +1,4 @@ +from pprint import pprint # noqa from typing import Any, Dict, Generator, List, Tuple, Union, Optional from followthemoney.schema import Schema from followthemoney.proxy import EntityProxy @@ -65,6 +66,7 @@ def names_query(entity: EntityProxy, fuzzy: bool = True) -> List[Clause]: NAMES_FIELD: { "query": name, "operator": "AND", + "boost": 3.0, } } if fuzzy: @@ -74,7 +76,8 @@ def names_query(entity: EntityProxy, fuzzy: bool = True) -> List[Clause]: term = {NAME_KEY_FIELD: {"value": key, "boost": 4.0}} shoulds.append({"term": term}) for token in set(index_name_parts(names)): - shoulds.append({"term": {NAME_PART_FIELD: {"value": token}}}) + term = {NAME_PART_FIELD: {"value": token, 'boost': 1.0}} + shoulds.append({"term": term}) for phoneme in set(phonetic_names(names)): term = {NAME_PHONETIC_FIELD: {"value": phoneme, "boost": 0.8}} shoulds.append({"term": term}) diff --git a/yente/search/search.py b/yente/search/search.py index 8ea3b2e8..03a44047 100644 --- a/yente/search/search.py +++ b/yente/search/search.py @@ -99,6 +99,8 @@ async def search_entities( sort=sort, from_=offset, aggregations=aggregations, + # https://discuss.elastic.co/t/querying-an-alias-throws-off-scoring-completely/351423/4 + search_type="dfs_query_then_fetch", ) return response except ApiError as ae: