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/mariadb_server.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'searx/engines/mariadb_server.py') diff --git a/searx/engines/mariadb_server.py b/searx/engines/mariadb_server.py index 7343f4342..26f537373 100644 --- a/searx/engines/mariadb_server.py +++ b/searx/engines/mariadb_server.py @@ -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 -- cgit v1.2.3