engine_overview.rst 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. .. _engines-dev:
  2. ===============
  3. Engine Overview
  4. ===============
  5. .. _metasearch-engine: https://en.wikipedia.org/wiki/Metasearch_engine
  6. .. sidebar:: Further reading ..
  7. - :ref:`general engine settings`
  8. - :ref:`settings engine`
  9. .. contents::
  10. :depth: 3
  11. :backlinks: entry
  12. searx 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 searx 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 searx 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 searx-engine (filename 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. .. sidebar:: engine's global names
  66. Global names with a leading underline are *private to the engine* and will
  67. not be overwritten.
  68. A few of the options have default values in the namespace of engine's python
  69. modul, but are often overwritten by the settings. If ``None`` is assigned to an
  70. option in the engine file, it has to be redefined in the settings, otherwise
  71. searx will not start with that engine.
  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. .. table:: If the ``engine_type`` is ``online``
  101. :width: 100%
  102. ====================== ============== ========================================================================
  103. argument type default-value, information
  104. ====================== ============== ========================================================================
  105. url str ``''``
  106. method str ``'GET'``
  107. headers set ``{}``
  108. data set ``{}``
  109. cookies set ``{}``
  110. verify bool ``True``
  111. headers.User-Agent str a random User-Agent
  112. category str current category, like ``'general'``
  113. safesearch int ``0``, between ``0`` and ``2`` (normal, moderate, strict)
  114. time_range Optional[str] ``None``, can be ``day``, ``week``, ``month``, ``year``
  115. pageno int current pagenumber
  116. language str specific language code like ``'en_US'``, or ``'all'`` if unspecified
  117. ====================== ============== ========================================================================
  118. .. table:: If the ``engine_type`` is ``online_dictionary``, in addition to the
  119. ``online`` arguments:
  120. :width: 100%
  121. ====================== ============== ========================================================================
  122. argument type default-value, information
  123. ====================== ============== ========================================================================
  124. from_lang str specific language code like ``'en_US'``
  125. to_lang str specific language code like ``'en_US'``
  126. query str the text query without the languages
  127. ====================== ============== ========================================================================
  128. .. table:: If the ``engine_type`` is ``online_currency```, in addition to the
  129. ``online`` arguments:
  130. :width: 100%
  131. ====================== ============== ========================================================================
  132. argument type default-value, information
  133. ====================== ============== ========================================================================
  134. amount float the amount to convert
  135. from str ISO 4217 code
  136. to str ISO 4217 code
  137. from_name str currency name
  138. to_name str currency name
  139. ====================== ============== ========================================================================
  140. Specify Request
  141. ---------------
  142. The function :py:func:`def request(query, params):
  143. <searx.engines.demo_online.request>` always returns the ``params`` variable, the
  144. following parameters can be used to specify a search request:
  145. .. table::
  146. :width: 100%
  147. =================== =========== ==========================================================================
  148. argument type information
  149. =================== =========== ==========================================================================
  150. url str requested url
  151. method str HTTP request method
  152. headers set HTTP header information
  153. data set HTTP data information
  154. cookies set HTTP cookies
  155. verify bool Performing SSL-Validity check
  156. allow_redirects bool Follow redirects
  157. max_redirects int maximum redirects, hard limit
  158. soft_max_redirects int maximum redirects, soft limit. Record an error but don't stop the engine
  159. raise_for_httperror bool True by default: raise an exception if the HTTP code of response is >= 300
  160. =================== =========== ==========================================================================
  161. .. _engine results:
  162. .. _engine media types:
  163. Media Types
  164. ===========
  165. Each result item of an engine can be of different media-types. Currently the
  166. following media-types are supported. To set another media-type as ``default``,
  167. the parameter ``template`` must be set to the desired type.
  168. .. table:: Parameter of the **default** media type:
  169. :width: 100%
  170. ========================= =====================================================
  171. result-parameter information
  172. ========================= =====================================================
  173. url string, url of the result
  174. title string, title of the result
  175. content string, general result-text
  176. publishedDate :py:class:`datetime.datetime`, time of publish
  177. ========================= =====================================================
  178. .. table:: Parameter of the **images** media type:
  179. :width: 100%
  180. ========================= =====================================================
  181. result-parameter information
  182. ------------------------- -----------------------------------------------------
  183. template is set to ``images.html``
  184. ========================= =====================================================
  185. url string, url to the result site
  186. title string, title of the result *(partly implemented)*
  187. content *(partly implemented)*
  188. publishedDate :py:class:`datetime.datetime`,
  189. time of publish *(partly implemented)*
  190. img\_src string, url to the result image
  191. thumbnail\_src string, url to a small-preview image
  192. ========================= =====================================================
  193. .. table:: Parameter of the **videos** media type:
  194. :width: 100%
  195. ========================= =====================================================
  196. result-parameter information
  197. ------------------------- -----------------------------------------------------
  198. template is set to ``videos.html``
  199. ========================= =====================================================
  200. url string, url of the result
  201. title string, title of the result
  202. content *(not implemented yet)*
  203. publishedDate :py:class:`datetime.datetime`, time of publish
  204. thumbnail string, url to a small-preview image
  205. ========================= =====================================================
  206. .. _magnetlink: https://en.wikipedia.org/wiki/Magnet_URI_scheme
  207. .. table:: Parameter of the **torrent** media type:
  208. :width: 100%
  209. ========================= =====================================================
  210. result-parameter information
  211. ------------------------- -----------------------------------------------------
  212. template is set to ``torrent.html``
  213. ========================= =====================================================
  214. url string, url of the result
  215. title string, title of the result
  216. content string, general result-text
  217. publishedDate :py:class:`datetime.datetime`,
  218. time of publish *(not implemented yet)*
  219. seed int, number of seeder
  220. leech int, number of leecher
  221. filesize int, size of file in bytes
  222. files int, number of files
  223. magnetlink string, magnetlink_ of the result
  224. torrentfile string, torrentfile of the result
  225. ========================= =====================================================
  226. .. table:: Parameter of the **map** media type:
  227. :width: 100%
  228. ========================= =====================================================
  229. result-parameter information
  230. ------------------------- -----------------------------------------------------
  231. template is set to ``map.html``
  232. ========================= =====================================================
  233. url string, url of the result
  234. title string, title of the result
  235. content string, general result-text
  236. publishedDate :py:class:`datetime.datetime`, time of publish
  237. latitude latitude of result (in decimal format)
  238. longitude longitude of result (in decimal format)
  239. boundingbox boundingbox of result (array of 4. values
  240. ``[lat-min, lat-max, lon-min, lon-max]``)
  241. geojson geojson of result (https://geojson.org/)
  242. osm.type type of osm-object (if OSM-Result)
  243. osm.id id of osm-object (if OSM-Result)
  244. address.name name of object
  245. address.road street name of object
  246. address.house_number house number of object
  247. address.locality city, place of object
  248. address.postcode postcode of object
  249. address.country country of object
  250. ========================= =====================================================