fixed issue with fuzzy project search
LocationBasedServices/smartguide/pipeline/head This commit looks good
LocationBasedServices/smartguide/pipeline/pr-dev This commit looks good

This commit is contained in:
Kazgatari
2026-09-02 14:22:05 +02:00
parent 375ae720d9
commit 2d23c4d05b
@@ -676,6 +676,7 @@ class ProjectsTrendStrategy(TrendStrategy):
query_institutions=ids_to_resolve,
query_countries=countries,
query_regions=regions,
topics=topics,
include_aliases=True,
)
@@ -685,6 +686,8 @@ class ProjectsTrendStrategy(TrendStrategy):
resolved_country_names = meta["country_names"]
resolved_continent_names = meta["continent_names"]
continent_country_codes = meta["continent_country_codes"]
resolved_topic_ids = meta["resolved_topic_ids"]
resolved_topic_names = meta["resolved_topic_names"]
location_mappings = continent_country_codes.copy()
@@ -755,7 +758,28 @@ class ProjectsTrendStrategy(TrendStrategy):
if fuzzy:
for t in topics:
topic_project_ids[t] = {ind: [] for ind in indices_mapping}
map_query = {"term": {"topic_matches.topic_display_name.keyword": t}}
canonical_id = resolved_topic_ids.get(t)
if not canonical_id:
clean_id = clean_inst_id(t)
canonical_id = f"https://openalex.org/{clean_id}" if clean_id.startswith("T") else t
display_name = resolved_topic_names.get(t) or resolved_topic_names.get(canonical_id)
should_clauses = [
{"term": {"topic_matches.topic_id": canonical_id}},
{"term": {"topic_matches.topic_id.keyword": canonical_id}},
]
if display_name:
should_clauses.append({"match_phrase": {"topic_matches.topic_display_name": display_name}})
elif not (t.startswith("https://openalex.org/") or (clean_inst_id(t).startswith("T") and clean_inst_id(t)[1:].isdigit())):
should_clauses.append({"match_phrase": {"topic_matches.topic_display_name": t}})
map_query = {
"bool": {
"should": should_clauses,
"minimum_should_match": 1,
}
}
async def scan_topic_projects(mapping_index: str) -> tuple[str, list[str]]:
p_ids = set()