summaryrefslogtreecommitdiff
path: root/searx/engines/elasticsearch.py
diff options
context:
space:
mode:
authorMarkus Heiser <markus.heiser@darmarit.de>2025-03-05 17:50:22 +0100
committerMarkus Heiser <markus.heiser@darmarIT.de>2025-03-15 10:36:33 +0100
commitf49b2c94a9a9938133dbf94d686f00776ce96cdc (patch)
tree7b74aa959100bd85054251221981039d185bc50e /searx/engines/elasticsearch.py
parentaf5dbdf768d56d26669a54e532bef3238e3de2e4 (diff)
[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 <markus.heiser@darmarit.de>
Diffstat (limited to 'searx/engines/elasticsearch.py')
-rw-r--r--searx/engines/elasticsearch.py21
1 files changed, 10 insertions, 11 deletions
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 = {