summaryrefslogtreecommitdiff
path: root/searx/engines/mongodb.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/mongodb.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/mongodb.py')
-rw-r--r--searx/engines/mongodb.py23
1 files changed, 12 insertions, 11 deletions
diff --git a/searx/engines/mongodb.py b/searx/engines/mongodb.py
index 57eaa8537..b6aef3dbd 100644
--- a/searx/engines/mongodb.py
+++ b/searx/engines/mongodb.py
@@ -37,6 +37,7 @@ Implementations
===============
"""
+from __future__ import annotations
import re
@@ -47,6 +48,8 @@ except ImportError:
# to use the engine
pass
+from searx.result_types import EngineResults
+
engine_type = 'offline'
@@ -63,7 +66,6 @@ key = None
paging = True
results_per_page = 20
exact_match_only = False
-result_template = 'key-value.html'
_client = None
@@ -74,7 +76,7 @@ def init(_):
def connect():
global _client # pylint: disable=global-statement
- kwargs = {'port': port}
+ kwargs: dict[str, str | int] = {'port': port}
if username:
kwargs['username'] = username
if password:
@@ -82,8 +84,8 @@ def connect():
_client = MongoClient(host, **kwargs)[database][collection]
-def search(query, params):
- results = []
+def search(query, params) -> EngineResults:
+ res = EngineResults()
if exact_match_only:
q = {'$eq': query}
else:
@@ -92,11 +94,10 @@ def search(query, params):
query = _client.find({key: q}).skip((params['pageno'] - 1) * results_per_page).limit(results_per_page)
- results.append({'number_of_results': query.count()})
- for r in query:
- del r['_id']
- r = {str(k): str(v) for k, v in r.items()}
- r['template'] = result_template
- results.append(r)
+ res.add(res.types.LegacyResult(number_of_results=query.count()))
+ for row in query:
+ del row['_id']
+ kvmap = {str(k): str(v) for k, v in row.items()}
+ res.add(res.types.KeyValue(kvmap=kvmap))
- return results
+ return res