diff options
| author | Markus Heiser <markus.heiser@darmarit.de> | 2025-03-05 17:50:22 +0100 |
|---|---|---|
| committer | Markus Heiser <markus.heiser@darmarIT.de> | 2025-03-15 10:36:33 +0100 |
| commit | f49b2c94a9a9938133dbf94d686f00776ce96cdc (patch) | |
| tree | 7b74aa959100bd85054251221981039d185bc50e /searx/engines/solr.py | |
| parent | af5dbdf768d56d26669a54e532bef3238e3de2e4 (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/solr.py')
| -rw-r--r-- | searx/engines/solr.py | 35 |
1 files changed, 15 insertions, 20 deletions
diff --git a/searx/engines/solr.py b/searx/engines/solr.py index 4b80d5729..b23cbe92e 100644 --- a/searx/engines/solr.py +++ b/searx/engines/solr.py @@ -29,9 +29,10 @@ This is an example configuration for searching in the collection # pylint: disable=global-statement -from json import loads from urllib.parse import urlencode from searx.exceptions import SearxEngineAPIException +from searx.result_types import EngineResults +from searx.extended_types import SXNG_Response base_url = 'http://localhost:8983' @@ -72,27 +73,21 @@ def request(query, params): return params -def response(resp): - resp_json = __get_response(resp) - - results = [] - for result in resp_json['response']['docs']: - r = {key: str(value) for key, value in result.items()} - if len(r) == 0: - continue - r['template'] = 'key-value.html' - results.append(r) - - return results - - -def __get_response(resp): +def response(resp: SXNG_Response) -> EngineResults: try: - resp_json = loads(resp.text) + resp_json = resp.json() except Exception as e: raise SearxEngineAPIException("failed to parse response") from e - if 'error' in resp_json: - raise SearxEngineAPIException(resp_json['error']['msg']) + if "error" in resp_json: + raise SearxEngineAPIException(resp_json["error"]["msg"]) + + res = EngineResults() + + for result in resp_json["response"]["docs"]: + kvmap = {key: str(value) for key, value in result.items()} + if not kvmap: + continue + res.add(res.types.KeyValue(kvmap=kvmap)) - return resp_json + return res |