engine_overview.rst 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. .. _engines-dev:
  2. ===============
  3. Engine Overview
  4. ===============
  5. .. _metasearch-engine: https://en.wikipedia.org/wiki/Metasearch_engine
  6. .. sidebar:: Further reading ..
  7. - :ref:`configured engines`
  8. - :ref:`settings engine`
  9. .. contents::
  10. :depth: 3
  11. :backlinks: entry
  12. SearXNG is a metasearch-engine_, so it uses different search engines to provide
  13. better results.
  14. Because there is no general search API which could be used for every search
  15. engine, an adapter has to be built between SearXNG and the external search
  16. engines. Adapters are stored under the folder :origin:`searx/engines`.
  17. .. _general engine configuration:
  18. General Engine Configuration
  19. ============================
  20. It is required to tell SearXNG the type of results the engine provides. The
  21. arguments can be set in the engine file or in the settings file (normally
  22. ``settings.yml``). The arguments in the settings file override the ones in the
  23. engine file.
  24. It does not matter if an option is stored in the engine file or in the settings.
  25. However, the standard way is the following:
  26. .. _engine file:
  27. Engine File
  28. -----------
  29. .. table:: Common options in the engine module
  30. :width: 100%
  31. ======================= =========== ========================================================
  32. argument type information
  33. ======================= =========== ========================================================
  34. categories list pages, in which the engine is working
  35. paging boolean support multible pages
  36. time_range_support boolean support search time range
  37. engine_type str - ``online`` :ref:`[ref] <demo online engine>` by
  38. default, other possibles values are:
  39. - ``offline`` :ref:`[ref] <offline engines>`
  40. - ``online_dictionary``
  41. - ``online_currency``
  42. ======================= =========== ========================================================
  43. .. _engine settings:
  44. Engine ``settings.yml``
  45. -----------------------
  46. For a more detailed description, see :ref:`settings engine` in the :ref:`settings.yml`.
  47. .. table:: Common options in the engine setup (``settings.yml``)
  48. :width: 100%
  49. ======================= =========== ==================================================
  50. argument type information
  51. ======================= =========== ==================================================
  52. name string name of search-engine
  53. engine string name of searxng-engine (file name without ``.py``)
  54. enable_http bool enable HTTP (by default only HTTPS is enabled).
  55. shortcut string shortcut of search-engine
  56. timeout string specific timeout for search-engine
  57. display_error_messages boolean display error messages on the web UI
  58. proxies dict set proxies for a specific engine
  59. (e.g. ``proxies : {http: socks5://proxy:port,
  60. https: socks5://proxy:port}``)
  61. ======================= =========== ==================================================
  62. .. _engine overrides:
  63. Overrides
  64. ---------
  65. A few of the options have default values in the namespace of engine's python
  66. modul, but are often overwritten by the settings. If ``None`` is assigned to an
  67. option in the engine file, it has to be redefined in the settings, otherwise
  68. SearXNG will not start with that engine (global names with a leading underline can
  69. be ``None``).
  70. Here is an very simple example of the global names in the namespace of engine's
  71. module:
  72. .. code:: python
  73. # engine dependent config
  74. categories = ['general']
  75. paging = True
  76. _non_overwritten_global = 'foo'
  77. .. table:: The naming of overrides is arbitrary / recommended overrides are:
  78. :width: 100%
  79. ======================= =========== ===========================================
  80. argument type information
  81. ======================= =========== ===========================================
  82. base_url string base-url, can be overwritten to use same
  83. engine on other URL
  84. number_of_results int maximum number of results per request
  85. language string ISO code of language and country like en_US
  86. api_key string api-key if required by engine
  87. ======================= =========== ===========================================
  88. .. _engine request:
  89. Making a Request
  90. ================
  91. To perform a search an URL have to be specified. In addition to specifying an
  92. URL, arguments can be passed to the query.
  93. .. _engine request arguments:
  94. Passed Arguments (request)
  95. --------------------------
  96. These arguments can be used to construct the search query. Furthermore,
  97. parameters with default value can be redefined for special purposes.
  98. .. table:: If the ``engine_type`` is ``online``
  99. :width: 100%
  100. ====================== ============== ========================================================================
  101. argument type default-value, information
  102. ====================== ============== ========================================================================
  103. url str ``''``
  104. method str ``'GET'``
  105. headers set ``{}``
  106. data set ``{}``
  107. cookies set ``{}``
  108. verify bool ``True``
  109. headers.User-Agent str a random User-Agent
  110. category str current category, like ``'general'``
  111. safesearch int ``0``, between ``0`` and ``2`` (normal, moderate, strict)
  112. time_range Optional[str] ``None``, can be ``day``, ``week``, ``month``, ``year``
  113. pageno int current pagenumber
  114. language str specific language code like ``'en_US'``, or ``'all'`` if unspecified
  115. ====================== ============== ========================================================================
  116. .. table:: If the ``engine_type`` is ``online_dictionary``, in addition to the
  117. ``online`` arguments:
  118. :width: 100%
  119. ====================== ============== ========================================================================
  120. argument type default-value, information
  121. ====================== ============== ========================================================================
  122. from_lang str specific language code like ``'en_US'``
  123. to_lang str specific language code like ``'en_US'``
  124. query str the text query without the languages
  125. ====================== ============== ========================================================================
  126. .. table:: If the ``engine_type`` is ``online_currency```, in addition to the
  127. ``online`` arguments:
  128. :width: 100%
  129. ====================== ============== ========================================================================
  130. argument type default-value, information
  131. ====================== ============== ========================================================================
  132. amount float the amount to convert
  133. from str ISO 4217 code
  134. to str ISO 4217 code
  135. from_name str currency name
  136. to_name str currency name
  137. ====================== ============== ========================================================================
  138. Specify Request
  139. ---------------
  140. The function :py:func:`def request(query, params):
  141. <searx.engines.demo_online.request>` always returns the ``params`` variable, the
  142. following parameters can be used to specify a search request:
  143. .. table::
  144. :width: 100%
  145. =================== =========== ==========================================================================
  146. argument type information
  147. =================== =========== ==========================================================================
  148. url str requested url
  149. method str HTTP request method
  150. headers set HTTP header information
  151. data set HTTP data information
  152. cookies set HTTP cookies
  153. verify bool Performing SSL-Validity check
  154. allow_redirects bool Follow redirects
  155. max_redirects int maximum redirects, hard limit
  156. soft_max_redirects int maximum redirects, soft limit. Record an error but don't stop the engine
  157. raise_for_httperror bool True by default: raise an exception if the HTTP code of response is >= 300
  158. =================== =========== ==========================================================================
  159. .. _engine results:
  160. .. _engine media types:
  161. Media Types
  162. ===========
  163. Each result item of an engine can be of different media-types. Currently the
  164. following media-types are supported. To set another media-type as ``default``,
  165. the parameter ``template`` must be set to the desired type.
  166. .. table:: Parameter of the **default** media type:
  167. :width: 100%
  168. ========================= =====================================================
  169. result-parameter information
  170. ========================= =====================================================
  171. url string, url of the result
  172. title string, title of the result
  173. content string, general result-text
  174. publishedDate :py:class:`datetime.datetime`, time of publish
  175. ========================= =====================================================
  176. .. table:: Parameter of the **images** media type:
  177. :width: 100%
  178. ========================= =====================================================
  179. result-parameter information
  180. ------------------------- -----------------------------------------------------
  181. template is set to ``images.html``
  182. ========================= =====================================================
  183. url string, url to the result site
  184. title string, title of the result *(partly implemented)*
  185. content *(partly implemented)*
  186. publishedDate :py:class:`datetime.datetime`,
  187. time of publish *(partly implemented)*
  188. img\_src string, url to the result image
  189. thumbnail\_src string, url to a small-preview image
  190. ========================= =====================================================
  191. .. table:: Parameter of the **videos** media type:
  192. :width: 100%
  193. ========================= =====================================================
  194. result-parameter information
  195. ------------------------- -----------------------------------------------------
  196. template is set to ``videos.html``
  197. ========================= =====================================================
  198. url string, url of the result
  199. title string, title of the result
  200. content *(not implemented yet)*
  201. publishedDate :py:class:`datetime.datetime`, time of publish
  202. thumbnail string, url to a small-preview image
  203. ========================= =====================================================
  204. .. _magnetlink: https://en.wikipedia.org/wiki/Magnet_URI_scheme
  205. .. table:: Parameter of the **torrent** media type:
  206. :width: 100%
  207. ========================= =====================================================
  208. result-parameter information
  209. ------------------------- -----------------------------------------------------
  210. template is set to ``torrent.html``
  211. ========================= =====================================================
  212. url string, url of the result
  213. title string, title of the result
  214. content string, general result-text
  215. publishedDate :py:class:`datetime.datetime`,
  216. time of publish *(not implemented yet)*
  217. seed int, number of seeder
  218. leech int, number of leecher
  219. filesize int, size of file in bytes
  220. files int, number of files
  221. magnetlink string, magnetlink_ of the result
  222. torrentfile string, torrentfile of the result
  223. ========================= =====================================================
  224. .. table:: Parameter of the **map** media type:
  225. :width: 100%
  226. ========================= =====================================================
  227. result-parameter information
  228. ------------------------- -----------------------------------------------------
  229. template is set to ``map.html``
  230. ========================= =====================================================
  231. url string, url of the result
  232. title string, title of the result
  233. content string, general result-text
  234. publishedDate :py:class:`datetime.datetime`, time of publish
  235. latitude latitude of result (in decimal format)
  236. longitude longitude of result (in decimal format)
  237. boundingbox boundingbox of result (array of 4. values
  238. ``[lat-min, lat-max, lon-min, lon-max]``)
  239. geojson geojson of result (https://geojson.org/)
  240. osm.type type of osm-object (if OSM-Result)
  241. osm.id id of osm-object (if OSM-Result)
  242. address.name name of object
  243. address.road street name of object
  244. address.house_number house number of object
  245. address.locality city, place of object
  246. address.postcode postcode of object
  247. address.country country of object
  248. ========================= =====================================================
  249. .. _BibTeX format: https://www.bibtex.com/g/bibtex-format/
  250. .. _BibTeX field types: https://en.wikipedia.org/wiki/BibTeX#Field_types
  251. .. list-table:: Parameter of the **paper** media type /
  252. see `BibTeX field types`_ and `BibTeX format`_
  253. :header-rows: 2
  254. :width: 100%
  255. * - result-parameter
  256. - Python type
  257. - information
  258. * - template
  259. - :py:class:`str`
  260. - is set to ``paper.html``
  261. * - title
  262. - :py:class:`str`
  263. - title of the result
  264. * - content
  265. - :py:class:`str`
  266. - abstract
  267. * - comments
  268. - :py:class:`str`
  269. - free text display in italic below the content
  270. * - tags
  271. - :py:class:`List <list>`\ [\ :py:class:`str`\ ]
  272. - free tag list
  273. * - publishedDate
  274. - :py:class:`datetime <datetime.datetime>`
  275. - last publication date
  276. * - type
  277. - :py:class:`str`
  278. - short description of medium type, e.g. *book*, *pdf* or *html* ...
  279. * - authors
  280. - :py:class:`List <list>`\ [\ :py:class:`str`\ ]
  281. - list of authors of the work (authors with a "s")
  282. * - editor
  283. - :py:class:`str`
  284. - list of editors of a book
  285. * - publisher
  286. - :py:class:`str`
  287. - name of the publisher
  288. * - journal
  289. - :py:class:`str`
  290. - name of the journal or magazine the article was
  291. published in
  292. * - volume
  293. - :py:class:`str`
  294. - volume number
  295. * - pages
  296. - :py:class:`str`
  297. - page range where the article is
  298. * - number
  299. - :py:class:`str`
  300. - number of the report or the issue number for a journal article
  301. * - doi
  302. - :py:class:`str`
  303. - DOI number (like ``10.1038/d41586-018-07848-2``)
  304. * - issn
  305. - :py:class:`List <list>`\ [\ :py:class:`str`\ ]
  306. - ISSN number like ``1476-4687``
  307. * - isbn
  308. - :py:class:`List <list>`\ [\ :py:class:`str`\ ]
  309. - ISBN number like ``9780201896831``
  310. * - pdf_url
  311. - :py:class:`str`
  312. - URL to the full article, the PDF version
  313. * - html_url
  314. - :py:class:`str`
  315. - URL to full article, HTML version