engine_overview.rst 18 KB

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