engine_overview.rst 13 KB

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