summaryrefslogtreecommitdiff
path: root/searx/engines/demo_offline.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/demo_offline.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/demo_offline.py')
-rw-r--r--searx/engines/demo_offline.py31
1 files changed, 18 insertions, 13 deletions
diff --git a/searx/engines/demo_offline.py b/searx/engines/demo_offline.py
index ffcdb46a9..2cef4f0d0 100644
--- a/searx/engines/demo_offline.py
+++ b/searx/engines/demo_offline.py
@@ -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