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

Functions

 init (engine_settings)
 
 request (query, params)
 
 response (resp)
 

Variables

str engine_type = 'online'
 
bool send_accept_language_header = True
 
list categories = ['general']
 
bool disabled = True
 
float timeout = 2.0
 
bool paging = True
 
int page_size = 20
 
str search_api = 'https://api.artic.edu/api/v1/artworks/search?'
 
str image_api = 'https://www.artic.edu/iiif/2/'
 
dict about
 
 _my_online_engine = None
 

Detailed Description

Within this module we implement a *demo online engine*.  Do not look to
close to the implementation, its just a simple example which queries `The Art
Institute of Chicago <https://www.artic.edu>`_

To get in use of this *demo* engine add the following entry to your engines
list in ``settings.yml``:

.. code:: yaml

  - name: my online engine
    engine: demo_online
    shortcut: demo
    disabled: false

Function Documentation

◆ init()

searx.engines.demo_online.init ( engine_settings)
Initialization of the (online) engine.  If no initialization is needed, drop
this init function.

Definition at line 47 of file demo_online.py.

47def init(engine_settings):
48 """Initialization of the (online) engine. If no initialization is needed, drop
49 this init function.
50
51 """
52 global _my_online_engine # pylint: disable=global-statement
53 _my_online_engine = engine_settings.get('name')
54
55

◆ request()

searx.engines.demo_online.request ( query,
params )
Build up the ``params`` for the online request.  In this example we build a
URL to fetch images from `artic.edu <https://artic.edu>`__

Definition at line 56 of file demo_online.py.

56def request(query, params):
57 """Build up the ``params`` for the online request. In this example we build a
58 URL to fetch images from `artic.edu <https://artic.edu>`__
59
60 """
61 args = urlencode(
62 {
63 'q': query,
64 'page': params['pageno'],
65 'fields': 'id,title,artist_display,medium_display,image_id,date_display,dimensions,artist_titles',
66 'limit': page_size,
67 }
68 )
69 params['url'] = search_api + args
70 return params
71
72

◆ response()

searx.engines.demo_online.response ( resp)
Parse out the result items from the response.  In this example we parse the
response from `api.artic.edu <https://artic.edu>`__ and filter out all
images.

Definition at line 73 of file demo_online.py.

73def response(resp):
74 """Parse out the result items from the response. In this example we parse the
75 response from `api.artic.edu <https://artic.edu>`__ and filter out all
76 images.
77
78 """
79 results = []
80 json_data = loads(resp.text)
81
82 for result in json_data['data']:
83
84 if not result['image_id']:
85 continue
86
87 results.append(
88 {
89 'url': 'https://artic.edu/artworks/%(id)s' % result,
90 'title': result['title'] + " (%(date_display)s) // %(artist_display)s" % result,
91 'content': "%(medium_display)s // %(dimensions)s" % result,
92 'author': ', '.join(result['artist_titles']),
93 'img_src': image_api + '/%(image_id)s/full/843,/0/default.jpg' % result,
94 'template': 'images.html',
95 }
96 )
97
98 return results

Variable Documentation

◆ _my_online_engine

searx.engines.demo_online._my_online_engine = None
protected

Definition at line 44 of file demo_online.py.

◆ about

dict searx.engines.demo_online.about
Initial value:
1= {
2 "website": 'https://www.artic.edu',
3 "wikidata_id": 'Q239303',
4 "official_api_documentation": 'http://api.artic.edu/docs/',
5 "use_official_api": True,
6 "require_api_key": False,
7 "results": 'JSON',
8}

Definition at line 33 of file demo_online.py.

◆ categories

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

Definition at line 23 of file demo_online.py.

◆ disabled

bool searx.engines.demo_online.disabled = True

Definition at line 24 of file demo_online.py.

◆ engine_type

str searx.engines.demo_online.engine_type = 'online'

Definition at line 21 of file demo_online.py.

◆ image_api

str searx.engines.demo_online.image_api = 'https://www.artic.edu/iiif/2/'

Definition at line 31 of file demo_online.py.

◆ page_size

int searx.engines.demo_online.page_size = 20

Definition at line 28 of file demo_online.py.

◆ paging

bool searx.engines.demo_online.paging = True

Definition at line 27 of file demo_online.py.

◆ search_api

str searx.engines.demo_online.search_api = 'https://api.artic.edu/api/v1/artworks/search?'

Definition at line 30 of file demo_online.py.

◆ send_accept_language_header

bool searx.engines.demo_online.send_accept_language_header = True

Definition at line 22 of file demo_online.py.

◆ timeout

float searx.engines.demo_online.timeout = 2.0

Definition at line 25 of file demo_online.py.