.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
16
17engine_type = 'offline'
18categories = ['general']
19disabled = True
20timeout = 2.0
21
22about = {
23 "wikidata_id": None,
24 "official_api_documentation": None,
25 "use_official_api": False,
26 "require_api_key": False,
27 "results": 'JSON',
28}
29
30# if there is a need for globals, use a leading underline
31_my_offline_engine = None
32
33
34def init(engine_settings=None):
35 """Initialization of the (offline) engine. The origin of this demo engine is a
36 simple json string which is loaded in this example while the engine is
37 initialized.
38
39 """
40 global _my_offline_engine # pylint: disable=global-statement
41
42 _my_offline_engine = (
43 '[ {"value": "%s"}'
44 ', {"value":"first item"}'
45 ', {"value":"second item"}'
46 ', {"value":"third item"}'
47 ']' % engine_settings.get('name')
48 )
49
50
51def search(query, request_params):
52 """Query (offline) engine and return results. Assemble the list of results from
53 your local engine. In this demo engine we ignore the 'query' term, usual
54 you would pass the 'query' term to your local engine to filter out the
55 results.
56
57 """
58 ret_val = []
59
60 result_list = json.loads(_my_offline_engine)
61
62 for row in result_list:
63 entry = {
64 'query': query,
65 'language': request_params['searxng_locale'],
66 'value': row.get("value"),
67 # choose a result template or comment out to use the *default*
68 'template': 'key-value.html',
69 }
70 ret_val.append(entry)
71
72 return ret_val
init(engine_settings=None)