diff options
| author | Markus Heiser <markus.heiser@darmarit.de> | 2025-03-05 17:50:22 +0100 |
|---|---|---|
| committer | Markus Heiser <markus.heiser@darmarIT.de> | 2025-03-15 10:36:33 +0100 |
| commit | f49b2c94a9a9938133dbf94d686f00776ce96cdc (patch) | |
| tree | 7b74aa959100bd85054251221981039d185bc50e /searx/engines/sqlite.py | |
| parent | af5dbdf768d56d26669a54e532bef3238e3de2e4 (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/sqlite.py')
| -rw-r--r-- | searx/engines/sqlite.py | 64 |
1 files changed, 39 insertions, 25 deletions
diff --git a/searx/engines/sqlite.py b/searx/engines/sqlite.py index e9694cf74..e3dd55829 100644 --- a/searx/engines/sqlite.py +++ b/searx/engines/sqlite.py @@ -2,6 +2,14 @@ """SQLite is a small, fast and reliable SQL database engine. It does not require any extra dependency. +Configuration +============= + +The engine has the following (additional) settings: + +- :py:obj:`result_type` + + Example ======= @@ -18,29 +26,32 @@ Query to test: ``!mediathekview concert`` .. code:: yaml - - name: mediathekview - engine: sqlite - disabled: False - categories: general - result_template: default.html - database: searx/data/filmliste-v2.db - query_str: >- - SELECT title || ' (' || time(duration, 'unixepoch') || ')' AS title, - COALESCE( NULLIF(url_video_hd,''), NULLIF(url_video_sd,''), url_video) AS url, - description AS content - FROM film - WHERE title LIKE :wildcard OR description LIKE :wildcard - ORDER BY duration DESC + - name: mediathekview + engine: sqlite + shortcut: mediathekview + categories: [general, videos] + result_type: MainResult + database: searx/data/filmliste-v2.db + query_str: >- + SELECT title || ' (' || time(duration, 'unixepoch') || ')' AS title, + COALESCE( NULLIF(url_video_hd,''), NULLIF(url_video_sd,''), url_video) AS url, + description AS content + FROM film + WHERE title LIKE :wildcard OR description LIKE :wildcard + ORDER BY duration DESC Implementations =============== """ - +import typing import sqlite3 import contextlib -engine_type = 'offline' +from searx.result_types import EngineResults +from searx.result_types import MainResult, KeyValue + +engine_type = "offline" database = "" """Filename of the SQLite DB.""" @@ -48,9 +59,11 @@ database = "" query_str = "" """SQL query that returns the result items.""" +result_type: typing.Literal["MainResult", "KeyValue"] = "KeyValue" +"""The result type can be :py:obj:`MainResult` or :py:obj:`KeyValue`.""" + limit = 10 paging = True -result_template = 'key-value.html' def init(engine_settings): @@ -80,9 +93,8 @@ def sqlite_cursor(): yield cursor -def search(query, params): - results = [] - +def search(query, params) -> EngineResults: + res = EngineResults() query_params = { 'query': query, 'wildcard': r'%' + query.replace(' ', r'%') + r'%', @@ -97,9 +109,11 @@ def search(query, params): col_names = [cn[0] for cn in cur.description] for row in cur.fetchall(): - item = dict(zip(col_names, map(str, row))) - item['template'] = result_template - logger.debug("append result --> %s", item) - results.append(item) - - return results + kvmap = dict(zip(col_names, map(str, row))) + if result_type == "MainResult": + item = MainResult(**kvmap) # type: ignore + else: + item = KeyValue(kvmap=kvmap) + res.add(item) + + return res |