.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
demo_online.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 online engine*. Do not look to
3
close to the implementation, its just a simple example which queries `The Art
4
Institute of Chicago <https://www.artic.edu>`_
5
6
To get in use of this *demo* engine add the following entry to your engines
7
list in ``settings.yml``:
8
9
.. code:: yaml
10
11
- name: my online engine
12
engine: demo_online
13
shortcut: demo
14
disabled: false
15
16
"""
17
18
from
json
import
loads
19
from
urllib.parse
import
urlencode
20
from
searx.result_types
import
EngineResults
21
22
engine_type =
'online'
23
send_accept_language_header =
True
24
categories = [
'general'
]
25
disabled =
True
26
timeout = 2.0
27
categories = [
'images'
]
28
paging =
True
29
page_size = 20
30
31
search_api =
'https://api.artic.edu/api/v1/artworks/search?'
32
image_api =
'https://www.artic.edu/iiif/2/'
33
34
about = {
35
"website"
:
'https://www.artic.edu'
,
36
"wikidata_id"
:
'Q239303'
,
37
"official_api_documentation"
:
'http://api.artic.edu/docs/'
,
38
"use_official_api"
:
True
,
39
"require_api_key"
:
False
,
40
"results"
:
'JSON'
,
41
}
42
43
44
# if there is a need for globals, use a leading underline
45
_my_online_engine =
None
46
47
48
def
init
(engine_settings):
49
"""Initialization of the (online) engine. If no initialization is needed, drop
50
this init function.
51
52
"""
53
global
_my_online_engine
# pylint: disable=global-statement
54
_my_online_engine = engine_settings.get(
'name'
)
55
56
57
def
request
(query, params):
58
"""Build up the ``params`` for the online request. In this example we build a
59
URL to fetch images from `artic.edu <https://artic.edu>`__
60
61
"""
62
args = urlencode(
63
{
64
'q'
: query,
65
'page'
: params[
'pageno'
],
66
'fields'
:
'id,title,artist_display,medium_display,image_id,date_display,dimensions,artist_titles'
,
67
'limit'
: page_size,
68
}
69
)
70
params[
'url'
] = search_api + args
71
return
params
72
73
74
def
response
(resp) -> EngineResults:
75
"""Parse out the result items from the response. In this example we parse the
76
response from `api.artic.edu <https://artic.edu>`__ and filter out all
77
images.
78
79
"""
80
res =
EngineResults
()
81
json_data = loads(resp.text)
82
83
res.add(
84
res.types.Answer(
85
answer=
"this is a dummy answer .."
,
86
url=
"https://example.org"
,
87
)
88
)
89
90
for
result
in
json_data[
'data'
]:
91
92
if
not
result[
'image_id'
]:
93
continue
94
95
res.append(
96
{
97
'url'
:
'https://artic.edu/artworks/%(id)s'
% result,
98
'title'
: result[
'title'
] +
" (%(date_display)s) // %(artist_display)s"
% result,
99
'content'
:
"%(medium_display)s // %(dimensions)s"
% result,
100
'author'
:
', '
.join(result[
'artist_titles'
]),
101
'img_src'
: image_api +
'/%(image_id)s/full/843,/0/default.jpg'
% result,
102
'template'
:
'images.html'
,
103
}
104
)
105
106
return
res
searx.result_types.EngineResults
Definition
__init__.py:44
searx.engines.demo_online.response
EngineResults response(resp)
Definition
demo_online.py:74
searx.engines.demo_online.request
request(query, params)
Definition
demo_online.py:57
searx.engines.demo_online.init
init(engine_settings)
Definition
demo_online.py:48
searx.result_types
Definition
__init__.py:1
searxng
searx
engines
demo_online.py
Generated on Mon Feb 17 2025 20:49:38 for .oO SearXNG Developer Documentation Oo. by
1.13.2