From 2d23c4d05ba1a0deaa69a357fa5fd578c6ba1ec8 Mon Sep 17 00:00:00 2001 From: Kazgatari <56477241+Kazgatari@users.noreply.github.com> Date: Wed, 2 Sep 2026 14:22:05 +0200 Subject: [PATCH] fixed issue with fuzzy project search --- .../university_ranking/trend_strategies.py | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/service/src/main/inse/university_ranking/trend_strategies.py b/service/src/main/inse/university_ranking/trend_strategies.py index 748f9364..99d8759c 100644 --- a/service/src/main/inse/university_ranking/trend_strategies.py +++ b/service/src/main/inse/university_ranking/trend_strategies.py @@ -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()