engine_overview.rst 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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. ============================
  16. It is required to tell searx the type of results the engine provides. The
  17. arguments can be set in the engine file or in the settings file
  18. (normally ``settings.yml``). The arguments in the settings file override
  19. the ones in the engine file.
  20. It does not matter if an option is stored in the engine file or in the
  21. settings. However, the standard way is the following:
  22. .. _engine file:
  23. engine file
  24. -----------
  25. ======================= =========== ===========================================
  26. argument type information
  27. ======================= =========== ===========================================
  28. categories list pages, in which the engine is working
  29. paging boolean support multible pages
  30. language_support boolean support language choosing
  31. time_range_support boolean support search time range
  32. offline boolean engine runs offline
  33. ======================= =========== ===========================================
  34. .. _engine settings:
  35. settings.yml
  36. ------------
  37. ======================= =========== =============================================
  38. argument type information
  39. ======================= =========== =============================================
  40. name string name of search-engine
  41. engine string name of searx-engine
  42. (filename without ``.py``)
  43. shortcut string shortcut of search-engine
  44. timeout string specific timeout for search-engine
  45. display_error_messages boolean display error messages on the web UI
  46. proxies dict set proxies for a specific engine
  47. (e.g. ``proxies : {http: socks5://proxy:port,
  48. https: socks5://proxy:port}``)
  49. ======================= =========== =============================================
  50. overrides
  51. ---------
  52. A few of the options have default values in the engine, but are often
  53. overwritten by the settings. If ``None`` is assigned to an option in the engine
  54. file, it has to be redefined in the settings, otherwise searx will not start
  55. with that engine.
  56. The naming of overrides is arbitrary. But the recommended overrides are the
  57. following:
  58. ======================= =========== ===========================================
  59. argument type information
  60. ======================= =========== ===========================================
  61. base_url string base-url, can be overwritten to use same
  62. engine on other URL
  63. number_of_results int maximum number of results per request
  64. language string ISO code of language and country like en_US
  65. api_key string api-key if required by engine
  66. ======================= =========== ===========================================
  67. example code
  68. ------------
  69. .. code:: python
  70. # engine dependent config
  71. categories = ['general']
  72. paging = True
  73. language_support = True
  74. making a request
  75. ================
  76. To perform a search an URL have to be specified. In addition to specifying an
  77. URL, arguments can be passed to the query.
  78. passed arguments
  79. ----------------
  80. These arguments can be used to construct the search query. Furthermore,
  81. parameters with default value can be redefined for special purposes.
  82. ====================== ============ ========================================================================
  83. argument type default-value, information
  84. ====================== ============ ========================================================================
  85. url string ``''``
  86. method string ``'GET'``
  87. headers set ``{}``
  88. data set ``{}``
  89. cookies set ``{}``
  90. verify boolean ``True``
  91. headers.User-Agent string a random User-Agent
  92. category string current category, like ``'general'``
  93. started datetime current date-time
  94. pageno int current pagenumber
  95. language string specific language code like ``'en_US'``, or ``'all'`` if unspecified
  96. ====================== ============ ========================================================================
  97. parsed arguments
  98. ----------------
  99. The function ``def request(query, params):`` always returns the ``params``
  100. variable. Inside searx, the following paramters can be used to specify a search
  101. request:
  102. ============ =========== =========================================================
  103. argument type information
  104. ============ =========== =========================================================
  105. url string requested url
  106. method string HTTP request method
  107. headers set HTTP header information
  108. data set HTTP data information (parsed if ``method != 'GET'``)
  109. cookies set HTTP cookies
  110. verify boolean Performing SSL-Validity check
  111. ============ =========== =========================================================
  112. example code
  113. ------------
  114. .. code:: python
  115. # search-url
  116. base_url = 'https://example.com/'
  117. search_string = 'search?{query}&page={page}'
  118. # do search-request
  119. def request(query, params):
  120. search_path = search_string.format(
  121. query=urlencode({'q': query}),
  122. page=params['pageno'])
  123. params['url'] = base_url + search_path
  124. return params
  125. returned results
  126. ================
  127. Searx is able to return results of different media-types. Currently the
  128. following media-types are supported:
  129. - default_
  130. - images_
  131. - videos_
  132. - torrent_
  133. - map_
  134. To set another media-type as default, the parameter ``template`` must be set to
  135. the desired type.
  136. default
  137. -------
  138. ========================= =====================================================
  139. result-parameter information
  140. ========================= =====================================================
  141. url string, url of the result
  142. title string, title of the result
  143. content string, general result-text
  144. publishedDate :py:class:`datetime.datetime`, time of publish
  145. ========================= =====================================================
  146. images
  147. ------
  148. To use this template, the parameter:
  149. ========================= =====================================================
  150. result-parameter information
  151. ========================= =====================================================
  152. template is set to ``images.html``
  153. url string, url to the result site
  154. title string, title of the result *(partly implemented)*
  155. content *(partly implemented)*
  156. publishedDate :py:class:`datetime.datetime`,
  157. time of publish *(partly implemented)*
  158. img\_src string, url to the result image
  159. thumbnail\_src string, url to a small-preview image
  160. ========================= =====================================================
  161. videos
  162. ------
  163. ========================= =====================================================
  164. result-parameter information
  165. ========================= =====================================================
  166. template is set to ``videos.html``
  167. url string, url of the result
  168. title string, title of the result
  169. content *(not implemented yet)*
  170. publishedDate :py:class:`datetime.datetime`, time of publish
  171. thumbnail string, url to a small-preview image
  172. ========================= =====================================================
  173. torrent
  174. -------
  175. .. _magnetlink: https://en.wikipedia.org/wiki/Magnet_URI_scheme
  176. ========================= =====================================================
  177. result-parameter information
  178. ========================= =====================================================
  179. template is set to ``torrent.html``
  180. url string, url of the result
  181. title string, title of the result
  182. content string, general result-text
  183. publishedDate :py:class:`datetime.datetime`,
  184. time of publish *(not implemented yet)*
  185. seed int, number of seeder
  186. leech int, number of leecher
  187. filesize int, size of file in bytes
  188. files int, number of files
  189. magnetlink string, magnetlink_ of the result
  190. torrentfile string, torrentfile of the result
  191. ========================= =====================================================
  192. map
  193. ---
  194. ========================= =====================================================
  195. result-parameter information
  196. ========================= =====================================================
  197. url string, url of the result
  198. title string, title of the result
  199. content string, general result-text
  200. publishedDate :py:class:`datetime.datetime`, time of publish
  201. latitude latitude of result (in decimal format)
  202. longitude longitude of result (in decimal format)
  203. boundingbox boundingbox of result (array of 4. values
  204. ``[lat-min, lat-max, lon-min, lon-max]``)
  205. geojson geojson of result (http://geojson.org)
  206. osm.type type of osm-object (if OSM-Result)
  207. osm.id id of osm-object (if OSM-Result)
  208. address.name name of object
  209. address.road street name of object
  210. address.house_number house number of object
  211. address.locality city, place of object
  212. address.postcode postcode of object
  213. address.country country of object
  214. ========================= =====================================================