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/command.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'searx/engines/command.py') diff --git a/searx/engines/command.py b/searx/engines/command.py index 176388e3a..29950ae4e 100644 --- a/searx/engines/command.py +++ b/searx/engines/command.py @@ -81,6 +81,7 @@ from subprocess import Popen, PIPE from threading import Thread from searx import logger +from searx.result_types import EngineResults engine_type = 'offline' @@ -93,7 +94,6 @@ query_enum = [] environment_variables = {} working_dir = realpath('.') result_separator = '\n' -result_template = 'key-value.html' timeout = 4.0 _command_logger = logger.getChild('command') @@ -126,17 +126,17 @@ def init(engine_settings): environment_variables = engine_settings['environment_variables'] -def search(query, params): +def search(query, params) -> EngineResults: + res = EngineResults() cmd = _get_command_to_run(query) if not cmd: - return [] + return res - results = [] - reader_thread = Thread(target=_get_results_from_process, args=(results, cmd, params['pageno'])) + reader_thread = Thread(target=_get_results_from_process, args=(res, cmd, params['pageno'])) reader_thread.start() reader_thread.join(timeout=timeout) - return results + return res def _get_command_to_run(query): @@ -153,7 +153,7 @@ def _get_command_to_run(query): return cmd -def _get_results_from_process(results, cmd, pageno): +def _get_results_from_process(res: EngineResults, cmd, pageno): leftover = '' count = 0 start, end = __get_results_limits(pageno) @@ -173,12 +173,11 @@ def _get_results_from_process(results, cmd, pageno): continue if start <= count and count <= end: # pylint: disable=chained-comparison - result['template'] = result_template - results.append(result) + res.add(res.types.KeyValue(kvmap=result)) count += 1 if end < count: - return results + return res line = process.stdout.readline() -- cgit v1.2.3