2"""Within this module we implement a *demo online engine*. Do not look to
3close to the implementation, its just a simple example which queries `The Art
4Institute of Chicago <https://www.artic.edu>`_
9To get in use of this *demo* engine add the following entry to your engines
10list in ``settings.yml``:
14 - name: my online engine
26from urllib.parse
import urlencode
35send_accept_language_header =
True
36categories = [
"general"]
39categories = [
"images"]
43search_api =
"https://api.artic.edu/api/v1/artworks/search"
44image_api =
"https://www.artic.edu/iiif/2/"
47 "website":
"https://www.artic.edu",
48 "wikidata_id":
"Q239303",
49 "official_api_documentation":
"http://api.artic.edu/docs/",
50 "use_official_api":
True,
51 "require_api_key":
False,
57_my_online_engine =
None
60def setup(engine_settings:
"OnlineParams") -> bool:
61 """Dynamic setup of the engine settings.
63 For more details see :py:obj:`searx.enginelib.Engine.setup`."""
64 global _my_online_engine
65 _my_online_engine = engine_settings.get(
"name")
69def init(engine_settings: dict[str, t.Any]) -> bool:
70 """Initialization of the engine.
72 For more details see :py:obj:`searx.enginelib.Engine.init`."""
76def request(query: str, params:
"OnlineParams") ->
None:
77 """Build up the ``params`` for the online request. In this example we build a
78 URL to fetch images from `artic.edu <https://artic.edu>`__."""
82 "page": params[
"pageno"],
83 "fields":
"id,title,artist_display,medium_display,image_id,date_display,dimensions,artist_titles",
87 params[
"url"] = f
"{search_api}?{args}"
90def response(resp:
"SXNG_Response") -> EngineResults:
91 """Parse out the result items from the response. In this example we parse the
92 response from `api.artic.edu <https://artic.edu>`__ and filter out all
97 json_data = resp.json()
101 answer=
"this is a dummy answer ..",
102 url=
"https://example.org",
106 for result
in json_data[
"data"]:
108 if not result[
"image_id"]:
111 kwargs: dict[str, t.Any] = {
112 "url":
"https://artic.edu/artworks/%(id)s" % result,
113 "title": result[
"title"] +
" (%(date_display)s) // %(artist_display)s" % result,
114 "content":
"%(medium_display)s // %(dimensions)s" % result,
115 "author":
", ".join(result[
"artist_titles"]),
116 "img_src": image_api +
"/%(image_id)s/full/843,/0/default.jpg" % result,
117 "template":
"images.html",
120 res.add(res.types.LegacyResult(**kwargs))
None request(str query, "OnlineParams" params)
EngineResults response("SXNG_Response" resp)
bool init(dict[str, t.Any] engine_settings)
bool setup("OnlineParams" engine_settings)