From f49b2c94a9a9938133dbf94d686f00776ce96cdc Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Wed, 5 Mar 2025 17:50:22 +0100 Subject: [mod] migrate all key-value.html templates to KeyValue type The engines now all use KeyValue results and return the results in a EngineResults object. The sqlite engine can return MainResult results in addition to KeyValue results (based on engine's config in settings.yml), Signed-off-by: Markus Heiser --- searx/engines/elasticsearch.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'searx/engines/elasticsearch.py') diff --git a/searx/engines/elasticsearch.py b/searx/engines/elasticsearch.py index c721114a7..6331a992e 100644 --- a/searx/engines/elasticsearch.py +++ b/searx/engines/elasticsearch.py @@ -43,6 +43,8 @@ authentication configured to read from ``my-index`` index. from json import loads, dumps from searx.exceptions import SearxEngineAPIException +from searx.result_types import EngineResults +from searx.extended_types import SXNG_Response base_url = 'http://localhost:9200' @@ -145,23 +147,20 @@ def _custom_query(query): return custom_query -def response(resp): - results = [] +def response(resp: SXNG_Response) -> EngineResults: + res = EngineResults() resp_json = loads(resp.text) if 'error' in resp_json: - raise SearxEngineAPIException(resp_json['error']) - - for result in resp_json['hits']['hits']: - r = {key: str(value) if not key.startswith('_') else value for key, value in result['_source'].items()} - r['template'] = 'key-value.html' + raise SearxEngineAPIException(resp_json["error"]) + for result in resp_json["hits"]["hits"]: + kvmap = {key: str(value) if not key.startswith("_") else value for key, value in result["_source"].items()} if show_metadata: - r['metadata'] = {'index': result['_index'], 'id': result['_id'], 'score': result['_score']} - - results.append(r) + kvmap["metadata"] = {"index": result["_index"], "id": result["_id"], "score": result["_score"]} + res.add(res.types.KeyValue(kvmap=kvmap)) - return results + return res _available_query_types = { -- cgit v1.2.3