engine_overview.rst 13 KB

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