engine_overview.rst 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. .. _engines-dev:
  2. ===============
  3. Engine overview
  4. ===============
  5. .. _metasearch-engine: https://en.wikipedia.org/wiki/Metasearch_engine
  6. searx is a metasearch-engine_, so it uses different search engines to provide
  7. better results.
  8. Because there is no general search API which could be used for every search
  9. engine, an adapter has to be built between searx and the external search
  10. engines. Adapters are stored under the folder :origin:`searx/engines`.
  11. .. contents::
  12. :depth: 3
  13. :backlinks: entry
  14. .. _general engine configuration:
  15. general engine configuration
  16. ============================
  17. It is required to tell searx the type of results the engine provides. The
  18. arguments can be set in the engine file or in the settings file
  19. (normally ``settings.yml``). The arguments in the settings file override
  20. the ones in the engine file.
  21. It does not matter if an option is stored in the engine file or in the
  22. settings. However, the standard way is the following:
  23. .. _engine file:
  24. engine file
  25. -----------
  26. ======================= =========== ========================================================
  27. argument type information
  28. ======================= =========== ========================================================
  29. categories list pages, in which the engine is working
  30. paging boolean support multible pages
  31. time_range_support boolean support search time range
  32. engine_type str ``online`` by default, other possibles values are
  33. ``offline``, ``online_dictionnary``, ``online_currency``
  34. ======================= =========== ========================================================
  35. .. _engine settings:
  36. settings.yml
  37. ------------
  38. ======================= =========== =============================================
  39. argument type information
  40. ======================= =========== =============================================
  41. name string name of search-engine
  42. engine string name of searx-engine
  43. (filename without ``.py``)
  44. enable_http bool enable HTTP
  45. (by default only HTTPS is enabled).
  46. shortcut string shortcut of search-engine
  47. timeout string specific timeout for search-engine
  48. display_error_messages boolean display error messages on the web UI
  49. proxies dict set proxies for a specific engine
  50. (e.g. ``proxies : {http: socks5://proxy:port,
  51. https: socks5://proxy:port}``)
  52. ======================= =========== =============================================
  53. overrides
  54. ---------
  55. A few of the options have default values in the engine, but are often
  56. overwritten by the settings. If ``None`` is assigned to an option in the engine
  57. file, it has to be redefined in the settings, otherwise searx will not start
  58. with that engine.
  59. The naming of overrides is arbitrary. But the recommended overrides are the
  60. following:
  61. ======================= =========== ===========================================
  62. argument type information
  63. ======================= =========== ===========================================
  64. base_url string base-url, can be overwritten to use same
  65. engine on other URL
  66. number_of_results int maximum number of results per request
  67. language string ISO code of language and country like en_US
  68. api_key string api-key if required by engine
  69. ======================= =========== ===========================================
  70. example code
  71. ------------
  72. .. code:: python
  73. # engine dependent config
  74. categories = ['general']
  75. paging = True
  76. .. _engine request:
  77. making a request
  78. ================
  79. To perform a search an URL have to be specified. In addition to specifying an
  80. URL, arguments can be passed to the query.
  81. passed arguments
  82. ----------------
  83. These arguments can be used to construct the search query. Furthermore,
  84. parameters with default value can be redefined for special purposes.
  85. If the ``engine_type`` is ``online```:
  86. ====================== ============== ========================================================================
  87. argument type default-value, information
  88. ====================== ============== ========================================================================
  89. url str ``''``
  90. method str ``'GET'``
  91. headers set ``{}``
  92. data set ``{}``
  93. cookies set ``{}``
  94. verify bool ``True``
  95. headers.User-Agent str a random User-Agent
  96. category str current category, like ``'general'``
  97. safesearch int ``0``, between ``0`` and ``2`` (normal, moderate, strict)
  98. time_range Optional[str] ``None``, can be ``day``, ``week``, ``month``, ``year``
  99. pageno int current pagenumber
  100. language str specific language code like ``'en_US'``, or ``'all'`` if unspecified
  101. ====================== ============== ========================================================================
  102. If the ``engine_type`` is ``online_dictionnary```, in addition to the ``online`` arguments:
  103. ====================== ============ ========================================================================
  104. argument type default-value, information
  105. ====================== ============ ========================================================================
  106. from_lang str specific language code like ``'en_US'``
  107. to_lang str specific language code like ``'en_US'``
  108. query str the text query without the languages
  109. ====================== ============ ========================================================================
  110. If the ``engine_type`` is ``online_currency```, in addition to the ``online`` arguments:
  111. ====================== ============ ========================================================================
  112. argument type default-value, information
  113. ====================== ============ ========================================================================
  114. amount float the amount to convert
  115. from str ISO 4217 code
  116. to str ISO 4217 code
  117. from_name str currency name
  118. to_name str currency name
  119. ====================== ============ ========================================================================
  120. parsed arguments
  121. ----------------
  122. The function ``def request(query, params):`` always returns the ``params``
  123. variable. Inside searx, the following paramters can be used to specify a search
  124. request:
  125. =================== =========== ==========================================================================
  126. argument type information
  127. =================== =========== ==========================================================================
  128. url str requested url
  129. method str HTTP request method
  130. headers set HTTP header information
  131. data set HTTP data information
  132. cookies set HTTP cookies
  133. verify bool Performing SSL-Validity check
  134. allow_redirects bool Follow redirects
  135. max_redirects int maximum redirects, hard limit
  136. soft_max_redirects int maximum redirects, soft limit. Record an error but don't stop the engine
  137. raise_for_httperror bool True by default: raise an exception if the HTTP code of response is >= 300
  138. =================== =========== ==========================================================================
  139. example code
  140. ------------
  141. .. code:: python
  142. # search-url
  143. base_url = 'https://example.com/'
  144. search_string = 'search?{query}&page={page}'
  145. # do search-request
  146. def request(query, params):
  147. search_path = search_string.format(
  148. query=urlencode({'q': query}),
  149. page=params['pageno'])
  150. params['url'] = base_url + search_path
  151. return params
  152. .. _engine results:
  153. returned results
  154. ================
  155. Searx is able to return results of different media-types. Currently the
  156. following media-types are supported:
  157. - default_
  158. - images_
  159. - videos_
  160. - torrent_
  161. - map_
  162. To set another media-type as default, the parameter ``template`` must be set to
  163. the desired type.
  164. default
  165. -------
  166. ========================= =====================================================
  167. result-parameter information
  168. ========================= =====================================================
  169. url string, url of the result
  170. title string, title of the result
  171. content string, general result-text
  172. publishedDate :py:class:`datetime.datetime`, time of publish
  173. ========================= =====================================================
  174. images
  175. ------
  176. To use this template, the parameter:
  177. ========================= =====================================================
  178. result-parameter information
  179. ========================= =====================================================
  180. template is set to ``images.html``
  181. url string, url to the result site
  182. title string, title of the result *(partly implemented)*
  183. content *(partly implemented)*
  184. publishedDate :py:class:`datetime.datetime`,
  185. time of publish *(partly implemented)*
  186. img\_src string, url to the result image
  187. thumbnail\_src string, url to a small-preview image
  188. ========================= =====================================================
  189. videos
  190. ------
  191. ========================= =====================================================
  192. result-parameter information
  193. ========================= =====================================================
  194. template is set to ``videos.html``
  195. url string, url of the result
  196. title string, title of the result
  197. content *(not implemented yet)*
  198. publishedDate :py:class:`datetime.datetime`, time of publish
  199. thumbnail string, url to a small-preview image
  200. ========================= =====================================================
  201. torrent
  202. -------
  203. .. _magnetlink: https://en.wikipedia.org/wiki/Magnet_URI_scheme
  204. ========================= =====================================================
  205. result-parameter information
  206. ========================= =====================================================
  207. template is set to ``torrent.html``
  208. url string, url of the result
  209. title string, title of the result
  210. content string, general result-text
  211. publishedDate :py:class:`datetime.datetime`,
  212. time of publish *(not implemented yet)*
  213. seed int, number of seeder
  214. leech int, number of leecher
  215. filesize int, size of file in bytes
  216. files int, number of files
  217. magnetlink string, magnetlink_ of the result
  218. torrentfile string, torrentfile of the result
  219. ========================= =====================================================
  220. map
  221. ---
  222. ========================= =====================================================
  223. result-parameter information
  224. ========================= =====================================================
  225. url string, url of the result
  226. title string, title of the result
  227. content string, general result-text
  228. publishedDate :py:class:`datetime.datetime`, time of publish
  229. latitude latitude of result (in decimal format)
  230. longitude longitude of result (in decimal format)
  231. boundingbox boundingbox of result (array of 4. values
  232. ``[lat-min, lat-max, lon-min, lon-max]``)
  233. geojson geojson of result (https://geojson.org/)
  234. osm.type type of osm-object (if OSM-Result)
  235. osm.id id of osm-object (if OSM-Result)
  236. address.name name of object
  237. address.road street name of object
  238. address.house_number house number of object
  239. address.locality city, place of object
  240. address.postcode postcode of object
  241. address.country country of object
  242. ========================= =====================================================