Skip to content

Commit

Permalink
Apply weird re-balancing search type to queries
Browse files Browse the repository at this point in the history
  • Loading branch information
pudo committed Jan 19, 2024
1 parent 4cf8933 commit 2a7ba94
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 4 additions & 1 deletion yente/search/queries.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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})
Expand Down
2 changes: 2 additions & 0 deletions yente/search/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 2a7ba94

Please sign in to comment.