engine_overview.rst 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  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. .. list-table:: Parameter of the **images** media type
  209. :header-rows: 2
  210. :width: 100%
  211. * - result-parameter
  212. - Python type
  213. - information
  214. * - template
  215. - :py:class:`str`
  216. - is set to ``images.html``
  217. * - url
  218. - :py:class:`str`
  219. - url to the result site
  220. * - title
  221. - :py:class:`str`
  222. - title of the result
  223. * - content
  224. - :py:class:`str`
  225. - description of the image
  226. * - publishedDate
  227. - :py:class:`datetime <datetime.datetime>`
  228. - time of publish
  229. * - img_src
  230. - :py:class:`str`
  231. - url to the result image
  232. * - thumbnail_src
  233. - :py:class:`str`
  234. - url to a small-preview image
  235. * - resolution
  236. - :py:class:`str`
  237. - the resolution of the image (e.g. ``1920 x 1080`` pixel)
  238. * - img_format
  239. - :py:class:`str`
  240. - the format of the image (e.g. ``png``)
  241. * - filesize
  242. - :py:class:`str`
  243. - size of bytes in :py:obj:`human readable <searx.humanize_bytes>` notation
  244. (e.g. ``MB`` for 1024 \* 1024 Bytes filesize).
  245. .. _template videos:
  246. ``videos``
  247. ----------
  248. .. table:: Parameter of the **videos** media type:
  249. :width: 100%
  250. ========================= =====================================================
  251. result-parameter information
  252. ------------------------- -----------------------------------------------------
  253. template is set to ``videos.html``
  254. ========================= =====================================================
  255. url string, url of the result
  256. title string, title of the result
  257. content *(not implemented yet)*
  258. publishedDate :py:class:`datetime.datetime`, time of publish
  259. thumbnail string, url to a small-preview image
  260. ========================= =====================================================
  261. .. _template torrent:
  262. ``torrent``
  263. -----------
  264. .. _magnetlink: https://en.wikipedia.org/wiki/Magnet_URI_scheme
  265. .. table:: Parameter of the **torrent** media type:
  266. :width: 100%
  267. ========================= =====================================================
  268. result-parameter information
  269. ------------------------- -----------------------------------------------------
  270. template is set to ``torrent.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`,
  276. time of publish *(not implemented yet)*
  277. seed int, number of seeder
  278. leech int, number of leecher
  279. filesize int, size of file in bytes
  280. files int, number of files
  281. magnetlink string, magnetlink_ of the result
  282. torrentfile string, torrentfile of the result
  283. ========================= =====================================================
  284. .. _template map:
  285. ``map``
  286. -------
  287. .. table:: Parameter of the **map** media type:
  288. :width: 100%
  289. ========================= =====================================================
  290. result-parameter information
  291. ------------------------- -----------------------------------------------------
  292. template is set to ``map.html``
  293. ========================= =====================================================
  294. url string, url of the result
  295. title string, title of the result
  296. content string, general result-text
  297. publishedDate :py:class:`datetime.datetime`, time of publish
  298. latitude latitude of result (in decimal format)
  299. longitude longitude of result (in decimal format)
  300. boundingbox boundingbox of result (array of 4. values
  301. ``[lat-min, lat-max, lon-min, lon-max]``)
  302. geojson geojson of result (https://geojson.org/)
  303. osm.type type of osm-object (if OSM-Result)
  304. osm.id id of osm-object (if OSM-Result)
  305. address.name name of object
  306. address.road street name of object
  307. address.house_number house number of object
  308. address.locality city, place of object
  309. address.postcode postcode of object
  310. address.country country of object
  311. ========================= =====================================================
  312. .. _template paper:
  313. ``paper``
  314. ---------
  315. .. _BibTeX format: https://www.bibtex.com/g/bibtex-format/
  316. .. _BibTeX field types: https://en.wikipedia.org/wiki/BibTeX#Field_types
  317. .. list-table:: Parameter of the **paper** media type /
  318. see `BibTeX field types`_ and `BibTeX format`_
  319. :header-rows: 2
  320. :width: 100%
  321. * - result-parameter
  322. - Python type
  323. - information
  324. * - template
  325. - :py:class:`str`
  326. - is set to ``paper.html``
  327. * - title
  328. - :py:class:`str`
  329. - title of the result
  330. * - content
  331. - :py:class:`str`
  332. - abstract
  333. * - comments
  334. - :py:class:`str`
  335. - free text display in italic below the content
  336. * - tags
  337. - :py:class:`List <list>`\ [\ :py:class:`str`\ ]
  338. - free tag list
  339. * - publishedDate
  340. - :py:class:`datetime <datetime.datetime>`
  341. - last publication date
  342. * - type
  343. - :py:class:`str`
  344. - short description of medium type, e.g. *book*, *pdf* or *html* ...
  345. * - authors
  346. - :py:class:`List <list>`\ [\ :py:class:`str`\ ]
  347. - list of authors of the work (authors with a "s")
  348. * - editor
  349. - :py:class:`str`
  350. - list of editors of a book
  351. * - publisher
  352. - :py:class:`str`
  353. - name of the publisher
  354. * - journal
  355. - :py:class:`str`
  356. - name of the journal or magazine the article was
  357. published in
  358. * - volume
  359. - :py:class:`str`
  360. - volume number
  361. * - pages
  362. - :py:class:`str`
  363. - page range where the article is
  364. * - number
  365. - :py:class:`str`
  366. - number of the report or the issue number for a journal article
  367. * - doi
  368. - :py:class:`str`
  369. - DOI number (like ``10.1038/d41586-018-07848-2``)
  370. * - issn
  371. - :py:class:`List <list>`\ [\ :py:class:`str`\ ]
  372. - ISSN number like ``1476-4687``
  373. * - isbn
  374. - :py:class:`List <list>`\ [\ :py:class:`str`\ ]
  375. - ISBN number like ``9780201896831``
  376. * - pdf_url
  377. - :py:class:`str`
  378. - URL to the full article, the PDF version
  379. * - html_url
  380. - :py:class:`str`
  381. - URL to full article, HTML version
  382. .. _template packages:
  383. ``packages``
  384. ------------
  385. .. list-table:: Parameter of the **packages** media type
  386. :header-rows: 2
  387. :width: 100%
  388. * - result-parameter
  389. - Python type
  390. - information
  391. * - template
  392. - :py:class:`str`
  393. - is set to ``packages.html``
  394. * - title
  395. - :py:class:`str`
  396. - title of the result
  397. * - content
  398. - :py:class:`str`
  399. - abstract
  400. * - package_name
  401. - :py:class:`str`
  402. - the name of the package
  403. * - version
  404. - :py:class:`str`
  405. - the current version of the package
  406. * - maintainer
  407. - :py:class:`str`
  408. - the maintainer or author of the project
  409. * - publishedDate
  410. - :py:class:`datetime <datetime.datetime>`
  411. - date of latest update or release
  412. * - tags
  413. - :py:class:`List <list>`\ [\ :py:class:`str`\ ]
  414. - free tag list
  415. * - popularity
  416. - :py:class:`str`
  417. - the popularity of the package, e.g. rating or download count
  418. * - license_name
  419. - :py:class:`str`
  420. - the name of the license
  421. * - license_url
  422. - :py:class:`str`
  423. - the web location of a license copy
  424. * - homepage
  425. - :py:class:`str`
  426. - the url of the project's homepage
  427. * - source_code_url
  428. - :py:class:`str`
  429. - the location of the project's source code