engine_overview.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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. ================== =========== ========================================================================
  115. example code
  116. ------------
  117. .. code:: python
  118. # search-url
  119. base_url = 'https://example.com/'
  120. search_string = 'search?{query}&page={page}'
  121. # do search-request
  122. def request(query, params):
  123. search_path = search_string.format(
  124. query=urlencode({'q': query}),
  125. page=params['pageno'])
  126. params['url'] = base_url + search_path
  127. return params
  128. returned results
  129. ================
  130. Searx is able to return results of different media-types. Currently the
  131. following media-types are supported:
  132. - default_
  133. - images_
  134. - videos_
  135. - torrent_
  136. - map_
  137. To set another media-type as default, the parameter ``template`` must be set to
  138. the desired type.
  139. default
  140. -------
  141. ========================= =====================================================
  142. result-parameter information
  143. ========================= =====================================================
  144. url string, url of the result
  145. title string, title of the result
  146. content string, general result-text
  147. publishedDate :py:class:`datetime.datetime`, time of publish
  148. ========================= =====================================================
  149. images
  150. ------
  151. To use this template, the parameter:
  152. ========================= =====================================================
  153. result-parameter information
  154. ========================= =====================================================
  155. template is set to ``images.html``
  156. url string, url to the result site
  157. title string, title of the result *(partly implemented)*
  158. content *(partly implemented)*
  159. publishedDate :py:class:`datetime.datetime`,
  160. time of publish *(partly implemented)*
  161. img\_src string, url to the result image
  162. thumbnail\_src string, url to a small-preview image
  163. ========================= =====================================================
  164. videos
  165. ------
  166. ========================= =====================================================
  167. result-parameter information
  168. ========================= =====================================================
  169. template is set to ``videos.html``
  170. url string, url of the result
  171. title string, title of the result
  172. content *(not implemented yet)*
  173. publishedDate :py:class:`datetime.datetime`, time of publish
  174. thumbnail string, url to a small-preview image
  175. ========================= =====================================================
  176. torrent
  177. -------
  178. .. _magnetlink: https://en.wikipedia.org/wiki/Magnet_URI_scheme
  179. ========================= =====================================================
  180. result-parameter information
  181. ========================= =====================================================
  182. template is set to ``torrent.html``
  183. url string, url of the result
  184. title string, title of the result
  185. content string, general result-text
  186. publishedDate :py:class:`datetime.datetime`,
  187. time of publish *(not implemented yet)*
  188. seed int, number of seeder
  189. leech int, number of leecher
  190. filesize int, size of file in bytes
  191. files int, number of files
  192. magnetlink string, magnetlink_ of the result
  193. torrentfile string, torrentfile of the result
  194. ========================= =====================================================
  195. map
  196. ---
  197. ========================= =====================================================
  198. result-parameter information
  199. ========================= =====================================================
  200. url string, url of the result
  201. title string, title of the result
  202. content string, general result-text
  203. publishedDate :py:class:`datetime.datetime`, time of publish
  204. latitude latitude of result (in decimal format)
  205. longitude longitude of result (in decimal format)
  206. boundingbox boundingbox of result (array of 4. values
  207. ``[lat-min, lat-max, lon-min, lon-max]``)
  208. geojson geojson of result (http://geojson.org)
  209. osm.type type of osm-object (if OSM-Result)
  210. osm.id id of osm-object (if OSM-Result)
  211. address.name name of object
  212. address.road street name of object
  213. address.house_number house number of object
  214. address.locality city, place of object
  215. address.postcode postcode of object
  216. address.country country of object
  217. ========================= =====================================================