[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

@ -35,6 +35,8 @@ except ImportError:
# the engine
pass
from searx.result_types import EngineResults
if TYPE_CHECKING:
import logging
@ -63,7 +65,6 @@ query_str = ""
limit = 10
paging = True
result_template = 'key-value.html'
_connection = None
@ -79,17 +80,16 @@ def init(engine_settings):
_connection = mariadb.connect(database=database, user=username, password=password, host=host, port=port)
def search(query, params):
def search(query, params) -> EngineResults:
query_params = {'query': query}
query_to_run = query_str + ' LIMIT {0} OFFSET {1}'.format(limit, (params['pageno'] - 1) * limit)
logger.debug("SQL Query: %s", query_to_run)
res = EngineResults()
with _connection.cursor() as cur:
cur.execute(query_to_run, query_params)
results = []
col_names = [i[0] for i in cur.description]
for res in cur:
result = dict(zip(col_names, map(str, res)))
result['template'] = result_template
results.append(result)
return results
for row in cur:
kvmap = dict(zip(col_names, map(str, row)))
res.add(res.types.KeyValue(kvmap=kvmap))
return res