From f49b2c94a9a9938133dbf94d686f00776ce96cdc Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Wed, 5 Mar 2025 17:50:22 +0100 Subject: [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 --- searx/engines/demo_offline.py | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'searx/engines/demo_offline.py') 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 -- cgit v1.2.3