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

Functions

bool setup (dict[str, t.Any] engine_settings)
bool init (dict[str, t.Any] engine_settings)
EngineResults search (str query, "RequestParams" 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.

Configuration
=============

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

Implementations
===============

Function Documentation

◆ init()

bool searx.engines.demo_offline.init ( dict[str, t.Any] engine_settings)
Initialization of the engine.

For more details see :py:obj:`searx.enginelib.Engine.init`.

Definition at line 77 of file demo_offline.py.

77def init(engine_settings: dict[str, t.Any]) -> bool: # pylint: disable=unused-argument
78 """Initialization of the engine.
79
80 For more details see :py:obj:`searx.enginelib.Engine.init`.
81 """
82 return True
83
84

◆ search()

EngineResults searx.engines.demo_offline.search ( str query,
"RequestParams" 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 85 of file demo_offline.py.

85def search(query: str, params: "RequestParams") -> EngineResults:
86 """Query (offline) engine and return results. Assemble the list of results
87 from your local engine.
88
89 In this demo engine we ignore the 'query' term, usual you would pass the
90 'query' term to your local engine to filter out the results.
91 """
92 res = EngineResults()
93
94 count: int = CACHE.get("count", 0)
95 data_rows: list[dict[str, str]] = json.loads(_my_offline_engine)
96
97 for row in data_rows:
98 count += 1
99 kvmap = {
100 'query': query,
101 'language': params['searxng_locale'],
102 'value': row.get("value"),
103 }
104 res.add(
105 res.types.KeyValue(
106 caption=f"Demo Offline Engine Result #{count}",
107 key_title="Name",
108 value_title="Value",
109 kvmap=kvmap,
110 )
111 )
112 res.add(res.types.LegacyResult(number_of_results=count))
113
114 # cache counter value for 20sec
115 CACHE.set("count", count, expire=20)
116 return res

◆ setup()

bool searx.engines.demo_offline.setup ( dict[str, t.Any] engine_settings)
Dynamic setup of the engine settings.

The origin of this demo engine is a simple json string which is loaded in
this example while the engine is initialized.

For more details see :py:obj:`searx.enginelib.Engine.setup`.

Definition at line 54 of file demo_offline.py.

54def setup(engine_settings: dict[str, t.Any]) -> bool:
55 """Dynamic setup of the engine settings.
56
57 The origin of this demo engine is a simple json string which is loaded in
58 this example while the engine is initialized.
59
60 For more details see :py:obj:`searx.enginelib.Engine.setup`.
61 """
62 global _my_offline_engine, CACHE # pylint: disable=global-statement
63
64 CACHE = EngineCache(engine_settings["name"])
65
66 _my_offline_engine = (
67 '[ {"value": "%s"}'
68 ', {"value":"first item"}'
69 ', {"value":"second item"}'
70 ', {"value":"third item"}'
71 ']' % engine_settings.get('name')
72 )
73
74 return True
75
76

Variable Documentation

◆ _my_offline_engine

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

Definition at line 47 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 38 of file demo_offline.py.

◆ categories

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

Definition at line 34 of file demo_offline.py.

◆ disabled

bool searx.engines.demo_offline.disabled = True

Definition at line 35 of file demo_offline.py.

◆ engine_type

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

Definition at line 33 of file demo_offline.py.

◆ timeout

float searx.engines.demo_offline.timeout = 2.0

Definition at line 36 of file demo_offline.py.