engine_overview.rst 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  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. length :py:class:`datetime.timedelta`, duration of result
  261. views string, view count in humanized number format
  262. ========================= =====================================================
  263. .. _template torrent:
  264. ``torrent``
  265. -----------
  266. .. _magnetlink: https://en.wikipedia.org/wiki/Magnet_URI_scheme
  267. .. table:: Parameter of the **torrent** media type:
  268. :width: 100%
  269. ========================= =====================================================
  270. result-parameter information
  271. ------------------------- -----------------------------------------------------
  272. template is set to ``torrent.html``
  273. ========================= =====================================================
  274. url string, url of the result
  275. title string, title of the result
  276. content string, general result-text
  277. publishedDate :py:class:`datetime.datetime`,
  278. time of publish *(not implemented yet)*
  279. seed int, number of seeder
  280. leech int, number of leecher
  281. filesize int, size of file in bytes
  282. files int, number of files
  283. magnetlink string, magnetlink_ of the result
  284. torrentfile string, torrentfile of the result
  285. ========================= =====================================================
  286. .. _template map:
  287. ``map``
  288. -------
  289. .. table:: Parameter of the **map** media type:
  290. :width: 100%
  291. ========================= =====================================================
  292. result-parameter information
  293. ------------------------- -----------------------------------------------------
  294. template is set to ``map.html``
  295. ========================= =====================================================
  296. url string, url of the result
  297. title string, title of the result
  298. content string, general result-text
  299. publishedDate :py:class:`datetime.datetime`, time of publish
  300. latitude latitude of result (in decimal format)
  301. longitude longitude of result (in decimal format)
  302. boundingbox boundingbox of result (array of 4. values
  303. ``[lat-min, lat-max, lon-min, lon-max]``)
  304. geojson geojson of result (https://geojson.org/)
  305. osm.type type of osm-object (if OSM-Result)
  306. osm.id id of osm-object (if OSM-Result)
  307. address.name name of object
  308. address.road street name of object
  309. address.house_number house number of object
  310. address.locality city, place of object
  311. address.postcode postcode of object
  312. address.country country of object
  313. ========================= =====================================================
  314. .. _template paper:
  315. ``paper``
  316. ---------
  317. .. _BibTeX format: https://www.bibtex.com/g/bibtex-format/
  318. .. _BibTeX field types: https://en.wikipedia.org/wiki/BibTeX#Field_types
  319. .. list-table:: Parameter of the **paper** media type /
  320. see `BibTeX field types`_ and `BibTeX format`_
  321. :header-rows: 2
  322. :width: 100%
  323. * - result-parameter
  324. - Python type
  325. - information
  326. * - template
  327. - :py:class:`str`
  328. - is set to ``paper.html``
  329. * - title
  330. - :py:class:`str`
  331. - title of the result
  332. * - content
  333. - :py:class:`str`
  334. - abstract
  335. * - comments
  336. - :py:class:`str`
  337. - free text display in italic below the content
  338. * - tags
  339. - :py:class:`List <list>`\ [\ :py:class:`str`\ ]
  340. - free tag list
  341. * - publishedDate
  342. - :py:class:`datetime <datetime.datetime>`
  343. - last publication date
  344. * - type
  345. - :py:class:`str`
  346. - short description of medium type, e.g. *book*, *pdf* or *html* ...
  347. * - authors
  348. - :py:class:`List <list>`\ [\ :py:class:`str`\ ]
  349. - list of authors of the work (authors with a "s")
  350. * - editor
  351. - :py:class:`str`
  352. - list of editors of a book
  353. * - publisher
  354. - :py:class:`str`
  355. - name of the publisher
  356. * - journal
  357. - :py:class:`str`
  358. - name of the journal or magazine the article was
  359. published in
  360. * - volume
  361. - :py:class:`str`
  362. - volume number
  363. * - pages
  364. - :py:class:`str`
  365. - page range where the article is
  366. * - number
  367. - :py:class:`str`
  368. - number of the report or the issue number for a journal article
  369. * - doi
  370. - :py:class:`str`
  371. - DOI number (like ``10.1038/d41586-018-07848-2``)
  372. * - issn
  373. - :py:class:`List <list>`\ [\ :py:class:`str`\ ]
  374. - ISSN number like ``1476-4687``
  375. * - isbn
  376. - :py:class:`List <list>`\ [\ :py:class:`str`\ ]
  377. - ISBN number like ``9780201896831``
  378. * - pdf_url
  379. - :py:class:`str`
  380. - URL to the full article, the PDF version
  381. * - html_url
  382. - :py:class:`str`
  383. - URL to full article, HTML version
  384. .. _template packages:
  385. ``packages``
  386. ------------
  387. .. list-table:: Parameter of the **packages** media type
  388. :header-rows: 2
  389. :width: 100%
  390. * - result-parameter
  391. - Python type
  392. - information
  393. * - template
  394. - :py:class:`str`
  395. - is set to ``packages.html``
  396. * - title
  397. - :py:class:`str`
  398. - title of the result
  399. * - content
  400. - :py:class:`str`
  401. - abstract
  402. * - package_name
  403. - :py:class:`str`
  404. - the name of the package
  405. * - version
  406. - :py:class:`str`
  407. - the current version of the package
  408. * - maintainer
  409. - :py:class:`str`
  410. - the maintainer or author of the project
  411. * - publishedDate
  412. - :py:class:`datetime <datetime.datetime>`
  413. - date of latest update or release
  414. * - tags
  415. - :py:class:`List <list>`\ [\ :py:class:`str`\ ]
  416. - free tag list
  417. * - popularity
  418. - :py:class:`str`
  419. - the popularity of the package, e.g. rating or download count
  420. * - license_name
  421. - :py:class:`str`
  422. - the name of the license
  423. * - license_url
  424. - :py:class:`str`
  425. - the web location of a license copy
  426. * - homepage
  427. - :py:class:`str`
  428. - the url of the project's homepage
  429. * - source_code_url
  430. - :py:class:`str`
  431. - the location of the project's source code
  432. * - links
  433. - :py:class:`dict`
  434. - additional links in the form of ``{'link_name': 'http://example.com'}``