.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.engines.demo_offline Namespace Reference

Functions

None init (dict[str, t.Any] engine_settings)
EngineResults search (str query, dict[str, t.Any] params)

Variables

str engine_type = "offline"
list categories = ["general"]
bool disabled = True
float timeout = 2.0
dict about
str _my_offline_engine = ""

Detailed Description

Within this module we implement a *demo offline engine*.  Do not look to
close to the implementation, its just a simple example.  To get in use of this
*demo* engine add the following entry to your engines list in ``settings.yml``:

.. code:: yaml

  - name: my offline engine
    engine: demo_offline
    shortcut: demo
    disabled: false

Function Documentation

◆ init()

None searx.engines.demo_offline.init ( dict[str, t.Any] engine_settings)
Initialization of the (offline) engine.  The origin of this demo engine is a
simple json string which is loaded in this example while the engine is
initialized.

Definition at line 42 of file demo_offline.py.

42def init(engine_settings: dict[str, t.Any]) -> None:
43 """Initialization of the (offline) engine. The origin of this demo engine is a
44 simple json string which is loaded in this example while the engine is
45 initialized."""
46 global _my_offline_engine, CACHE # pylint: disable=global-statement
47
48 CACHE = EngineCache(engine_settings["name"])
49
50 _my_offline_engine = (
51 '[ {"value": "%s"}'
52 ', {"value":"first item"}'
53 ', {"value":"second item"}'
54 ', {"value":"third item"}'
55 ']' % engine_settings.get('name')
56 )
57
58

◆ search()

EngineResults searx.engines.demo_offline.search ( str query,
dict[str, t.Any] params )
Query (offline) engine and return results.  Assemble the list of results
from your local engine.  In this demo engine we ignore the 'query' term,
usual you would pass the 'query' term to your local engine to filter out the
results.

Definition at line 59 of file demo_offline.py.

59def search(query: str, params: dict[str, t.Any]) -> EngineResults:
60 """Query (offline) engine and return results. Assemble the list of results
61 from your local engine. In this demo engine we ignore the 'query' term,
62 usual you would pass the 'query' term to your local engine to filter out the
63 results.
64 """
65 res = EngineResults()
66
67 count: int = CACHE.get("count", 0)
68 data_rows: list[dict[str, str]] = json.loads(_my_offline_engine)
69
70 for row in data_rows:
71 count += 1
72 kvmap = {
73 'query': query,
74 'language': params['searxng_locale'],
75 'value': row.get("value"),
76 }
77 res.add(
78 res.types.KeyValue(
79 caption=f"Demo Offline Engine Result #{count}",
80 key_title="Name",
81 value_title="Value",
82 kvmap=kvmap,
83 )
84 )
85 res.add(res.types.LegacyResult(number_of_results=count))
86
87 # cache counter value for 20sec
88 CACHE.set("count", count, expire=20)
89 return res

Variable Documentation

◆ _my_offline_engine

str searx.engines.demo_offline._my_offline_engine = ""
protected

Definition at line 35 of file demo_offline.py.

◆ about

dict searx.engines.demo_offline.about
Initial value:
1= {
2 "wikidata_id": None,
3 "official_api_documentation": None,
4 "use_official_api": False,
5 "require_api_key": False,
6 "results": 'JSON',
7}

Definition at line 26 of file demo_offline.py.

◆ categories

list searx.engines.demo_offline.categories = ["general"]

Definition at line 22 of file demo_offline.py.

◆ disabled

bool searx.engines.demo_offline.disabled = True

Definition at line 23 of file demo_offline.py.

◆ engine_type

str searx.engines.demo_offline.engine_type = "offline"

Definition at line 21 of file demo_offline.py.

◆ timeout

float searx.engines.demo_offline.timeout = 2.0

Definition at line 24 of file demo_offline.py.