engine_overview.rst 10 KB

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