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

Functions

 init (engine_settings)
 
EngineResults search (query, request_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()

searx.engines.demo_offline.init ( 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 41 of file demo_offline.py.

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

◆ search()

EngineResults searx.engines.demo_offline.search ( query,
request_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 58 of file demo_offline.py.

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

Variable Documentation

◆ _my_offline_engine

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

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

◆ categories

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

Definition at line 21 of file demo_offline.py.

◆ disabled

bool searx.engines.demo_offline.disabled = True

Definition at line 22 of file demo_offline.py.

◆ engine_type

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

Definition at line 20 of file demo_offline.py.

◆ timeout

float searx.engines.demo_offline.timeout = 2.0

Definition at line 23 of file demo_offline.py.