From 28c79e113a452fb5fc9d3e44bba701aa87893c63 Mon Sep 17 00:00:00 2001 From: Steven Tischer Date: Thu, 28 May 2026 16:38:35 +0200 Subject: [PATCH] refactor(backend): integrate elasticsearch service into search_persons function --- service/src/main/inse/logic.py | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/service/src/main/inse/logic.py b/service/src/main/inse/logic.py index b7aaad0f..504f4ed1 100644 --- a/service/src/main/inse/logic.py +++ b/service/src/main/inse/logic.py @@ -20,6 +20,7 @@ import json from . import schema from . import model from . import config +from .integrations import elasticsearch logger = logging.getLogger(__name__) topic_cache_filename: str = "topic_hierarchy_cache.json" @@ -200,11 +201,6 @@ def count_topic_hierarchy(topic_names: List[str]) -> dict: def search_persons(author_id: Optional[str] = None, query: Optional[str] = None, include: Optional[set[str]] = None) -> model.PersonSearchResult: - headers = { - "Authorization": f"ApiKey {config.settings.elasticsearch_api_key}", - "Content-Type": "application/json" - } - if author_id: query_field = "_id" query_value = author_id @@ -214,19 +210,11 @@ def search_persons(author_id: Optional[str] = None, query: Optional[str] = None, else: return "Either author_id or query must be provided" - payload = { - "query": { - "query_string": { - "default_field": query_field, - "query": query_value - } - } - } - - with httpx.Client() as client: - response = client.post(config.settings.elasticsearch_url + '/openalex-authors/_search', json=payload, headers=headers) - response.raise_for_status() - data = response.json() + data = elasticsearch.search( + index="openalex-authors", + query_field=query_field, + query_value=query_value + ) include_set = {tag.strip().lower() for tag in include} if include else set() persons = []