updated project search queries for highlighting found content

This commit is contained in:
2026-08-13 15:29:37 +02:00
parent 81c4094708
commit 41037efd6f
2 changed files with 97 additions and 18 deletions
@@ -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": ["<em>"],
"post_tags": ["</em>"],
"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"
),
}
}
],
@@ -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": ["<em>"],
"post_tags": ["</em>"],
"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": ["<em>"],
"post_tags": ["</em>"],
"require_field_match": True,
}
# print(f"Executing BUND project search with body: {json.dumps(body, indent=2)}")
# === Execute Search ===
response = await elasticsearch.search(