summaryrefslogtreecommitdiff
path: root/searx/engines/mariadb_server.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/mariadb_server.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/mariadb_server.py')
-rw-r--r--searx/engines/mariadb_server.py16
1 files changed, 8 insertions, 8 deletions
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