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

Functions

bool setup ("OnlineParams" engine_settings)
bool init (dict[str, t.Any] engine_settings)
None request (str query, "OnlineParams" params)
EngineResults response ("SXNG_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>`_

Configuration
=============

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

Implementations
===============

Function Documentation

◆ init()

bool searx.engines.demo_online.init ( dict[str, t.Any] engine_settings)
Initialization of the engine.

For more details see :py:obj:`searx.enginelib.Engine.init`.

Definition at line 69 of file demo_online.py.

69def init(engine_settings: dict[str, t.Any]) -> bool: # pylint: disable=unused-argument
70 """Initialization of the engine.
71
72 For more details see :py:obj:`searx.enginelib.Engine.init`."""
73 return True
74
75

◆ request()

None searx.engines.demo_online.request ( str query,
"OnlineParams" 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 76 of file demo_online.py.

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>`__."""
79 args = urlencode(
80 {
81 "q": query,
82 "page": params["pageno"],
83 "fields": "id,title,artist_display,medium_display,image_id,date_display,dimensions,artist_titles",
84 "limit": page_size,
85 }
86 )
87 params["url"] = f"{search_api}?{args}"
88
89

◆ response()

EngineResults searx.engines.demo_online.response ( "SXNG_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 90 of file demo_online.py.

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
93 images.
94
95 """
96 res = EngineResults()
97 json_data = resp.json()
98
99 res.add(
100 res.types.Answer(
101 answer="this is a dummy answer ..",
102 url="https://example.org",
103 )
104 )
105
106 for result in json_data["data"]:
107
108 if not result["image_id"]:
109 continue
110
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",
118 }
119
120 res.add(res.types.LegacyResult(**kwargs))
121
122 return res

◆ setup()

bool searx.engines.demo_online.setup ( "OnlineParams" engine_settings)
Dynamic setup of the engine settings.

For more details see :py:obj:`searx.enginelib.Engine.setup`.

Definition at line 60 of file demo_online.py.

60def setup(engine_settings: "OnlineParams") -> bool:
61 """Dynamic setup of the engine settings.
62
63 For more details see :py:obj:`searx.enginelib.Engine.setup`."""
64 global _my_online_engine # pylint: disable=global-statement
65 _my_online_engine = engine_settings.get("name")
66 return True
67
68

Variable Documentation

◆ _my_online_engine

searx.engines.demo_online._my_online_engine = None
protected

Definition at line 57 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 46 of file demo_online.py.

◆ categories

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

Definition at line 36 of file demo_online.py.

◆ disabled

bool searx.engines.demo_online.disabled = True

Definition at line 37 of file demo_online.py.

◆ engine_type

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

Definition at line 34 of file demo_online.py.

◆ image_api

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

Definition at line 44 of file demo_online.py.

◆ page_size

int searx.engines.demo_online.page_size = 20

Definition at line 41 of file demo_online.py.

◆ paging

bool searx.engines.demo_online.paging = True

Definition at line 40 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 43 of file demo_online.py.

◆ send_accept_language_header

bool searx.engines.demo_online.send_accept_language_header = True

Definition at line 35 of file demo_online.py.

◆ timeout

float searx.engines.demo_online.timeout = 2.0

Definition at line 38 of file demo_online.py.