engine_overview.rst 20 KB

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