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. language_support boolean support language choosing
  32. time_range_support boolean support search time range
  33. engine_type str ``online`` by default, other possibles values are
  34. ``offline``, ``online_dictionnary``, ``online_currency``
  35. ======================= =========== ========================================================
  36. .. _engine settings:
  37. settings.yml
  38. ------------
  39. ======================= =========== =============================================
  40. argument type information
  41. ======================= =========== =============================================
  42. name string name of search-engine
  43. engine string name of searx-engine
  44. (filename without ``.py``)
  45. shortcut string shortcut of search-engine
  46. timeout string specific timeout for search-engine
  47. display_error_messages boolean display error messages on the web UI
  48. proxies dict set proxies for a specific engine
  49. (e.g. ``proxies : {http: socks5://proxy:port,
  50. https: socks5://proxy:port}``)
  51. ======================= =========== =============================================
  52. overrides
  53. ---------
  54. A few of the options have default values in the engine, but are often
  55. overwritten by the settings. If ``None`` is assigned to an option in the engine
  56. file, it has to be redefined in the settings, otherwise searx will not start
  57. with that engine.
  58. The naming of overrides is arbitrary. But the recommended overrides are the
  59. following:
  60. ======================= =========== ===========================================
  61. argument type information
  62. ======================= =========== ===========================================
  63. base_url string base-url, can be overwritten to use same
  64. engine on other URL
  65. number_of_results int maximum number of results per request
  66. language string ISO code of language and country like en_US
  67. api_key string api-key if required by engine
  68. ======================= =========== ===========================================
  69. example code
  70. ------------
  71. .. code:: python
  72. # engine dependent config
  73. categories = ['general']
  74. paging = True
  75. language_support = 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_dictionnary```, 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 paramters 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. max_redirects int maximum redirects, hard limit
  134. soft_max_redirects int maximum redirects, soft limit. Record an error but don't stop the engine
  135. raise_for_httperror bool True by default: raise an exception if the HTTP code of response is >= 300
  136. =================== =========== ==========================================================================
  137. example code
  138. ------------
  139. .. code:: python
  140. # search-url
  141. base_url = 'https://example.com/'
  142. search_string = 'search?{query}&page={page}'
  143. # do search-request
  144. def request(query, params):
  145. search_path = search_string.format(
  146. query=urlencode({'q': query}),
  147. page=params['pageno'])
  148. params['url'] = base_url + search_path
  149. return params
  150. returned results
  151. ================
  152. Searx is able to return results of different media-types. Currently the
  153. following media-types are supported:
  154. - default_
  155. - images_
  156. - videos_
  157. - torrent_
  158. - map_
  159. To set another media-type as default, the parameter ``template`` must be set to
  160. the desired type.
  161. default
  162. -------
  163. ========================= =====================================================
  164. result-parameter information
  165. ========================= =====================================================
  166. url string, url of the result
  167. title string, title of the result
  168. content string, general result-text
  169. publishedDate :py:class:`datetime.datetime`, time of publish
  170. ========================= =====================================================
  171. images
  172. ------
  173. To use this template, the parameter:
  174. ========================= =====================================================
  175. result-parameter information
  176. ========================= =====================================================
  177. template is set to ``images.html``
  178. url string, url to the result site
  179. title string, title of the result *(partly implemented)*
  180. content *(partly implemented)*
  181. publishedDate :py:class:`datetime.datetime`,
  182. time of publish *(partly implemented)*
  183. img\_src string, url to the result image
  184. thumbnail\_src string, url to a small-preview image
  185. ========================= =====================================================
  186. videos
  187. ------
  188. ========================= =====================================================
  189. result-parameter information
  190. ========================= =====================================================
  191. template is set to ``videos.html``
  192. url string, url of the result
  193. title string, title of the result
  194. content *(not implemented yet)*
  195. publishedDate :py:class:`datetime.datetime`, time of publish
  196. thumbnail string, url to a small-preview image
  197. ========================= =====================================================
  198. torrent
  199. -------
  200. .. _magnetlink: https://en.wikipedia.org/wiki/Magnet_URI_scheme
  201. ========================= =====================================================
  202. result-parameter information
  203. ========================= =====================================================
  204. template is set to ``torrent.html``
  205. url string, url of the result
  206. title string, title of the result
  207. content string, general result-text
  208. publishedDate :py:class:`datetime.datetime`,
  209. time of publish *(not implemented yet)*
  210. seed int, number of seeder
  211. leech int, number of leecher
  212. filesize int, size of file in bytes
  213. files int, number of files
  214. magnetlink string, magnetlink_ of the result
  215. torrentfile string, torrentfile of the result
  216. ========================= =====================================================
  217. map
  218. ---
  219. ========================= =====================================================
  220. result-parameter information
  221. ========================= =====================================================
  222. url string, url of the result
  223. title string, title of the result
  224. content string, general result-text
  225. publishedDate :py:class:`datetime.datetime`, time of publish
  226. latitude latitude of result (in decimal format)
  227. longitude longitude of result (in decimal format)
  228. boundingbox boundingbox of result (array of 4. values
  229. ``[lat-min, lat-max, lon-min, lon-max]``)
  230. geojson geojson of result (https://geojson.org/)
  231. osm.type type of osm-object (if OSM-Result)
  232. osm.id id of osm-object (if OSM-Result)
  233. address.name name of object
  234. address.road street name of object
  235. address.house_number house number of object
  236. address.locality city, place of object
  237. address.postcode postcode of object
  238. address.country country of object
  239. ========================= =====================================================