engine_overview.rst 11 KB

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