engine_overview.rst 10 KB

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