summaryrefslogtreecommitdiff
path: root/searx/engines/command.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/command.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/command.py')
-rw-r--r--searx/engines/command.py19
1 files changed, 9 insertions, 10 deletions
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()