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/postgresql.py | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'searx/engines/postgresql.py') diff --git a/searx/engines/postgresql.py b/searx/engines/postgresql.py index ddd0ef929..78af8783c 100644 --- a/searx/engines/postgresql.py +++ b/searx/engines/postgresql.py @@ -28,6 +28,8 @@ except ImportError: # manually to use the engine. pass +from searx.result_types import EngineResults + engine_type = 'offline' host = "127.0.0.1" @@ -50,7 +52,6 @@ query_str = "" limit = 10 paging = True -result_template = 'key-value.html' _connection = None @@ -72,7 +73,7 @@ def init(engine_settings): ) -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) @@ -82,20 +83,16 @@ def search(query, params): return _fetch_results(cur) -def _fetch_results(cur): - results = [] - titles = [] - +def _fetch_results(cur) -> EngineResults: + res = EngineResults() try: titles = [column_desc.name for column_desc in cur.description] - - for res in cur: - result = dict(zip(titles, map(str, res))) - result['template'] = result_template - results.append(result) + for row in cur: + kvmap = dict(zip(titles, map(str, row))) + res.add(res.types.KeyValue(kvmap=kvmap)) # no results to fetch except psycopg2.ProgrammingError: pass - return results + return res -- cgit v1.2.3