[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:
Markus Heiser 2025-03-05 17:50:22 +01:00 committed by Markus Heiser
parent af5dbdf768
commit f49b2c94a9
13 changed files with 160 additions and 172 deletions

View file

@ -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()