diff --git a/service/src/main/inse/projects/eu_cordis_projects_client.py b/service/src/main/inse/projects/eu_cordis_projects_client.py index 707b7c94..c625a60d 100644 --- a/service/src/main/inse/projects/eu_cordis_projects_client.py +++ b/service/src/main/inse/projects/eu_cordis_projects_client.py @@ -1009,6 +1009,7 @@ async def search_eu_cordis_projects( "acronym", "objective", "keywords", + "topics", "frameworkProgramme", "fundingScheme", "status", @@ -1018,12 +1019,28 @@ async def search_eu_cordis_projects( "totalCost", ], "query": query, + "highlight": { + "fields": { + "title": {}, + "acronym": {}, + "objective": {}, + "keywords": {}, + "topics": {}, + }, + "pre_tags": [""], + "post_tags": [""], + "require_field_match": True, + }, "sort": [ { sort_field: { "order": sort_direction, "missing": "_last", - "unmapped_type": "keyword" if sort_field.endswith(".keyword") else "date", + "unmapped_type": ( + "keyword" + if sort_field.endswith(".keyword") + else "date" + ), } } ], diff --git a/service/src/main/inse/projects/projects_search_client.py b/service/src/main/inse/projects/projects_search_client.py index 217e3e7e..b63fa0a9 100644 --- a/service/src/main/inse/projects/projects_search_client.py +++ b/service/src/main/inse/projects/projects_search_client.py @@ -407,6 +407,8 @@ async def search_dfg_projects( "title", "title_de", "title_en", + "abstract_de", + "abstract_en", "funding_start", "funding_end", "Fachliche Zuordnung", @@ -439,23 +441,57 @@ async def search_dfg_projects( if keyword.strip() == "": continue keyword_clauses.append( - { - "multi_match": { - "query": keyword, - "fields": [ - "title", "title_de", "title_en", - "abstract_de", "abstract_en", - "subject_area_de", "subject_area_en", - "subject_classifications.fach", - "subject_classifications.fachkollegium", - "subject_classifications.fachgebiet", - "subject_classifications.fachgebiet_de", - "subject_classifications.wissenschaftsbereich", - ], - "type": "phrase_prefix", - "max_expansions": 100, - } + { + "bool": { + "should": [ + { + "multi_match": { + "query": keyword, + "fields": [ + "title_de", + "title_en", + "abstract_de", + "abstract_en", + ], + "type": "phrase_prefix", + "max_expansions": 100, + } + }, + { + "nested": { + "path": "subject_classifications", + "query": { + "multi_match": { + "query": keyword, + "fields": [ + "subject_classifications.fach", + "subject_classifications.fachkollegium", + "subject_classifications.fachgebiet", + "subject_classifications.fachgebiet_de", + "subject_classifications.wissenschaftsbereich", + ], + "type": "phrase_prefix", + "max_expansions": 100, + } + }, + "inner_hits": { + "name": keyword, + "highlight": { + "fields": { + "subject_classifications.fach": {}, + "subject_classifications.fachkollegium": {}, + "subject_classifications.fachgebiet": {}, + "subject_classifications.fachgebiet_de": {}, + "subject_classifications.wissenschaftsbereich": {}, + } + } + }, + } + }, + ], + "minimum_should_match": 1, } + } ) if keyword_clauses: must_clauses.append({"bool": {"must": keyword_clauses}}) @@ -603,14 +639,28 @@ async def search_dfg_projects( sort_config = {"id": {"order": sort_direction}} body["sort"] = [sort_config] + + #Add highlighting for the title and abstract fields + body["highlight"] = { + "fields": { + "title_de": {}, + "title_en": {}, + "abstract_de": {}, + "abstract_en": {}, + }, + "pre_tags": [""], + "post_tags": [""], + "require_field_match": True, + } # print(f"Executing DFG project search with body: {json.dumps(body, indent=2)}") # === Execute Search === + print(f"Executing DFG project search with body: {body}") response = await elasticsearch.search( index=ESIndex.DFG_PROJECTS, body=body, cluster=ESCluster.INSE, ) - + print(f"Received DFG project search response: {response}") hits = response.get("hits", {}).get("hits", []) if skip_enrichment: @@ -1035,6 +1085,18 @@ async def search_bund_projects_with_filters( sort_config = {"Förderkennzeichen.keyword": {"order": sort_direction}} body["sort"] = [sort_config] + #Add highlighting for the title and abstract fields + body["highlight"] = { + "fields": { + "Verbundprojekt": {}, + "Thema": {}, + "Zuwendungsempfänger": {}, + "Ausführende Stelle": {}, + }, + "pre_tags": [""], + "post_tags": [""], + "require_field_match": True, + } # print(f"Executing BUND project search with body: {json.dumps(body, indent=2)}") # === Execute Search === response = await elasticsearch.search(