forked from Icycoide/searxng
[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
|
@ -13,6 +13,7 @@ close to the implementation, its just a simple example. To get in use of this
|
|||
"""
|
||||
|
||||
import json
|
||||
|
||||
from searx.result_types import EngineResults
|
||||
|
||||
engine_type = 'offline'
|
||||
|
@ -29,7 +30,7 @@ about = {
|
|||
}
|
||||
|
||||
# if there is a need for globals, use a leading underline
|
||||
_my_offline_engine = None
|
||||
_my_offline_engine: str = ""
|
||||
|
||||
|
||||
def init(engine_settings=None):
|
||||
|
@ -50,24 +51,28 @@ def init(engine_settings=None):
|
|||
|
||||
|
||||
def search(query, request_params) -> EngineResults:
|
||||
"""Query (offline) engine and return results. Assemble the list of results from
|
||||
your local engine. In this demo engine we ignore the 'query' term, usual
|
||||
you would pass the 'query' term to your local engine to filter out the
|
||||
"""Query (offline) engine and return results. Assemble the list of results
|
||||
from your local engine. In this demo engine we ignore the 'query' term,
|
||||
usual you would pass the 'query' term to your local engine to filter out the
|
||||
results.
|
||||
|
||||
"""
|
||||
res = EngineResults()
|
||||
|
||||
result_list = json.loads(_my_offline_engine)
|
||||
|
||||
for row in result_list:
|
||||
entry = {
|
||||
count = 0
|
||||
for row in json.loads(_my_offline_engine):
|
||||
count += 1
|
||||
kvmap = {
|
||||
'query': query,
|
||||
'language': request_params['searxng_locale'],
|
||||
'value': row.get("value"),
|
||||
# choose a result template or comment out to use the *default*
|
||||
'template': 'key-value.html',
|
||||
}
|
||||
res.append(entry)
|
||||
|
||||
res.add(
|
||||
res.types.KeyValue(
|
||||
caption=f"Demo Offline Engine Result #{count}",
|
||||
key_title="Name",
|
||||
value_title="Value",
|
||||
kvmap=kvmap,
|
||||
)
|
||||
)
|
||||
res.add(res.types.LegacyResult(number_of_results=count))
|
||||
return res
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue