engine_overview.rst 11 KB

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