.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
demo_offline.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""Within this module we implement a *demo offline engine*. Do not look to
3close to the implementation, its just a simple example. To get in use of this
4*demo* engine add the following entry to your engines list in ``settings.yml``:
5
6.. code:: yaml
7
8 - name: my offline engine
9 engine: demo_offline
10 shortcut: demo
11 disabled: false
12
13"""
14
15import json
16from searx.result_types import EngineResults
17
18engine_type = 'offline'
19categories = ['general']
20disabled = True
21timeout = 2.0
22
23about = {
24 "wikidata_id": None,
25 "official_api_documentation": None,
26 "use_official_api": False,
27 "require_api_key": False,
28 "results": 'JSON',
29}
30
31# if there is a need for globals, use a leading underline
32_my_offline_engine = None
33
34
35def init(engine_settings=None):
36 """Initialization of the (offline) engine. The origin of this demo engine is a
37 simple json string which is loaded in this example while the engine is
38 initialized.
39
40 """
41 global _my_offline_engine # pylint: disable=global-statement
42
43 _my_offline_engine = (
44 '[ {"value": "%s"}'
45 ', {"value":"first item"}'
46 ', {"value":"second item"}'
47 ', {"value":"third item"}'
48 ']' % engine_settings.get('name')
49 )
50
51
52def search(query, request_params) -> EngineResults:
53 """Query (offline) engine and return results. Assemble the list of results from
54 your local engine. In this demo engine we ignore the 'query' term, usual
55 you would pass the 'query' term to your local engine to filter out the
56 results.
57
58 """
59 res = EngineResults()
60
61 result_list = json.loads(_my_offline_engine)
62
63 for row in result_list:
64 entry = {
65 'query': query,
66 'language': request_params['searxng_locale'],
67 'value': row.get("value"),
68 # choose a result template or comment out to use the *default*
69 'template': 'key-value.html',
70 }
71 res.append(entry)
72
73 return res
init(engine_settings=None)