mirror of
https://github.com/searxng/searxng.git
synced 2025-07-13 00:09:18 +02:00
[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>
This commit is contained in:
parent
af5dbdf768
commit
f49b2c94a9
13 changed files with 160 additions and 172 deletions
|
@ -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"])
|
||||
|
||||
return resp_json
|
||||
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 res
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue