engine_overview.rst 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. Engine overview
  2. ===============
  3. searx is a `metasearch-engine <https://en.wikipedia.org/wiki/Metasearch_engine>`__,
  4. so it uses different search engines to provide better results.
  5. Because there is no general search API which could be used for every
  6. search engine, an adapter has to be built between searx and the
  7. external search engines. Adapters are stored under the folder
  8. :origin:`searx/engines`.
  9. .. contents::
  10. :depth: 3
  11. general engine configuration
  12. ----------------------------
  13. It is required to tell searx the type of results the engine provides. The
  14. arguments can be set in the engine file or in the settings file
  15. (normally ``settings.yml``). The arguments in the settings file override
  16. the ones in the engine file.
  17. It does not matter if an option is stored in the engine file or in the
  18. settings. However, the standard way is the following:
  19. engine file
  20. ~~~~~~~~~~~
  21. +----------------------+-----------+-----------------------------------------+
  22. | argument | type | information |
  23. +======================+===========+=========================================+
  24. | categories | list | pages, in which the engine is working |
  25. +----------------------+-----------+-----------------------------------------+
  26. | paging | boolean | support multible pages |
  27. +----------------------+-----------+-----------------------------------------+
  28. | language\_support | boolean | support language choosing |
  29. +----------------------+-----------+-----------------------------------------+
  30. | time\_range\_support | boolean | support search time range |
  31. +----------------------+-----------+-----------------------------------------+
  32. | offline | boolean | engine runs offline |
  33. +----------------------+-----------+-----------------------------------------+
  34. settings.yml
  35. ~~~~~~~~~~~~
  36. +------------+----------+-----------------------------------------------+
  37. | argument | type | information |
  38. +============+==========+===============================================+
  39. | name | string | name of search-engine |
  40. +------------+----------+-----------------------------------------------+
  41. | engine | string | name of searx-engine (filename without .py) |
  42. +------------+----------+-----------------------------------------------+
  43. | shortcut | string | shortcut of search-engine |
  44. +------------+----------+-----------------------------------------------+
  45. | timeout | string | specific timeout for search-engine |
  46. +------------+----------+-----------------------------------------------+
  47. overrides
  48. ~~~~~~~~~
  49. A few of the options have default values in the engine, but are
  50. often overwritten by the settings. If ``None`` is assigned to an option
  51. in the engine file, it has to be redefined in the settings,
  52. otherwise searx will not start with that engine.
  53. The naming of overrides is arbitrary. But the recommended
  54. overrides are the following:
  55. +-----------------------+----------+----------------------------------------------------------------+
  56. | argument | type | information |
  57. +=======================+==========+================================================================+
  58. | base\_url | string | base-url, can be overwritten to use same engine on other URL |
  59. +-----------------------+----------+----------------------------------------------------------------+
  60. | number\_of\_results | int | maximum number of results per request |
  61. +-----------------------+----------+----------------------------------------------------------------+
  62. | language | string | ISO code of language and country like en\_US |
  63. +-----------------------+----------+----------------------------------------------------------------+
  64. | api\_key | string | api-key if required by engine |
  65. +-----------------------+----------+----------------------------------------------------------------+
  66. example code
  67. ~~~~~~~~~~~~
  68. .. code:: python
  69. # engine dependent config
  70. categories = ['general']
  71. paging = True
  72. language_support = True
  73. making a request
  74. ----------------
  75. To perform a search an URL have to be specified. In addition to
  76. specifying an URL, arguments can be passed to the query.
  77. passed arguments
  78. ~~~~~~~~~~~~~~~~
  79. These arguments can be used to construct the search query. Furthermore,
  80. parameters with default value can be redefined for special purposes.
  81. +----------------------+------------+------------------------------------------------------------------------+
  82. | argument | type | default-value, information |
  83. +======================+============+========================================================================+
  84. | url | string | ``''`` |
  85. +----------------------+------------+------------------------------------------------------------------------+
  86. | method | string | ``'GET'`` |
  87. +----------------------+------------+------------------------------------------------------------------------+
  88. | headers | set | ``{}`` |
  89. +----------------------+------------+------------------------------------------------------------------------+
  90. | data | set | ``{}`` |
  91. +----------------------+------------+------------------------------------------------------------------------+
  92. | cookies | set | ``{}`` |
  93. +----------------------+------------+------------------------------------------------------------------------+
  94. | verify | boolean | ``True`` |
  95. +----------------------+------------+------------------------------------------------------------------------+
  96. | headers.User-Agent | string | a random User-Agent |
  97. +----------------------+------------+------------------------------------------------------------------------+
  98. | category | string | current category, like ``'general'`` |
  99. +----------------------+------------+------------------------------------------------------------------------+
  100. | started | datetime | current date-time |
  101. +----------------------+------------+------------------------------------------------------------------------+
  102. | pageno | int | current pagenumber |
  103. +----------------------+------------+------------------------------------------------------------------------+
  104. | language | string | specific language code like ``'en_US'``, or ``'all'`` if unspecified |
  105. +----------------------+------------+------------------------------------------------------------------------+
  106. parsed arguments
  107. ~~~~~~~~~~~~~~~~
  108. The function ``def request(query, params):`` always returns the
  109. ``params`` variable. Inside searx, the following paramters can be
  110. used to specify a search request:
  111. +------------+-----------+---------------------------------------------------------+
  112. | argument | type | information |
  113. +============+===========+=========================================================+
  114. | url | string | requested url |
  115. +------------+-----------+---------------------------------------------------------+
  116. | method | string | HTTP request method |
  117. +------------+-----------+---------------------------------------------------------+
  118. | headers | set | HTTP header information |
  119. +------------+-----------+---------------------------------------------------------+
  120. | data | set | HTTP data information (parsed if ``method != 'GET'``) |
  121. +------------+-----------+---------------------------------------------------------+
  122. | cookies | set | HTTP cookies |
  123. +------------+-----------+---------------------------------------------------------+
  124. | verify | boolean | Performing SSL-Validity check |
  125. +------------+-----------+---------------------------------------------------------+
  126. example code
  127. ~~~~~~~~~~~~
  128. .. code:: python
  129. # search-url
  130. base_url = 'https://example.com/'
  131. search_string = 'search?{query}&page={page}'
  132. # do search-request
  133. def request(query, params):
  134. search_path = search_string.format(
  135. query=urlencode({'q': query}),
  136. page=params['pageno'])
  137. params['url'] = base_url + search_path
  138. return params
  139. returned results
  140. ----------------
  141. Searx is able to return results of different media-types.
  142. Currently the following media-types are supported:
  143. - default
  144. - images
  145. - videos
  146. - torrent
  147. - map
  148. To set another media-type as default, the parameter
  149. ``template`` must be set to the desired type.
  150. default
  151. ~~~~~~~
  152. +--------------------+---------------------------------------------------------------------------------------------------------------+
  153. | result-parameter | information |
  154. +====================+===============================================================================================================+
  155. | url | string, url of the result |
  156. +--------------------+---------------------------------------------------------------------------------------------------------------+
  157. | title | string, title of the result |
  158. +--------------------+---------------------------------------------------------------------------------------------------------------+
  159. | content | string, general result-text |
  160. +--------------------+---------------------------------------------------------------------------------------------------------------+
  161. | publishedDate | :py:class:`datetime.datetime`, time of publish |
  162. +--------------------+---------------------------------------------------------------------------------------------------------------+
  163. images
  164. ~~~~~~
  165. to use this template, the parameter
  166. +--------------------+---------------------------------------------------------------------------------------------------------------------------------------+
  167. | result-parameter | information |
  168. +====================+=======================================================================================================================================+
  169. | template | is set to ``images.html`` |
  170. +--------------------+---------------------------------------------------------------------------------------------------------------------------------------+
  171. | url | string, url to the result site |
  172. +--------------------+---------------------------------------------------------------------------------------------------------------------------------------+
  173. | title | string, title of the result *(partly implemented)* |
  174. +--------------------+---------------------------------------------------------------------------------------------------------------------------------------+
  175. | content | *(partly implemented)* |
  176. +--------------------+---------------------------------------------------------------------------------------------------------------------------------------+
  177. | publishedDate | :py:class:`datetime.datetime`, time of publish *(partly implemented)* |
  178. +--------------------+---------------------------------------------------------------------------------------------------------------------------------------+
  179. | img\_src | string, url to the result image |
  180. +--------------------+---------------------------------------------------------------------------------------------------------------------------------------+
  181. | thumbnail\_src | string, url to a small-preview image |
  182. +--------------------+---------------------------------------------------------------------------------------------------------------------------------------+
  183. videos
  184. ~~~~~~
  185. +--------------------+--------------------------------------------------------------------------------------------------------------+
  186. | result-parameter | information |
  187. +====================+==============================================================================================================+
  188. | template | is set to ``videos.html`` |
  189. +--------------------+--------------------------------------------------------------------------------------------------------------+
  190. | url | string, url of the result |
  191. +--------------------+--------------------------------------------------------------------------------------------------------------+
  192. | title | string, title of the result |
  193. +--------------------+--------------------------------------------------------------------------------------------------------------+
  194. | content | *(not implemented yet)* |
  195. +--------------------+--------------------------------------------------------------------------------------------------------------+
  196. | publishedDate | :py:class:`datetime.datetime`, time of publish |
  197. +--------------------+--------------------------------------------------------------------------------------------------------------+
  198. | thumbnail | string, url to a small-preview image |
  199. +--------------------+--------------------------------------------------------------------------------------------------------------+
  200. torrent
  201. ~~~~~~~
  202. +------------------+---------------------------------------------------------------------------------------------------------------------------------------+
  203. | result-parameter | information |
  204. +==================+=======================================================================================================================================+
  205. | template | is set to ``torrent.html`` |
  206. +------------------+---------------------------------------------------------------------------------------------------------------------------------------+
  207. | url | string, url of the result |
  208. +------------------+---------------------------------------------------------------------------------------------------------------------------------------+
  209. | title | string, title of the result |
  210. +------------------+---------------------------------------------------------------------------------------------------------------------------------------+
  211. | content | string, general result-text |
  212. +------------------+---------------------------------------------------------------------------------------------------------------------------------------+
  213. | publishedDate | :py:class:`datetime.datetime`, time of publish *(not implemented yet)* |
  214. +------------------+---------------------------------------------------------------------------------------------------------------------------------------+
  215. | seed | int, number of seeder |
  216. +------------------+---------------------------------------------------------------------------------------------------------------------------------------+
  217. | leech | int, number of leecher |
  218. +------------------+---------------------------------------------------------------------------------------------------------------------------------------+
  219. | filesize | int, size of file in bytes |
  220. +------------------+---------------------------------------------------------------------------------------------------------------------------------------+
  221. | files | int, number of files |
  222. +------------------+---------------------------------------------------------------------------------------------------------------------------------------+
  223. | magnetlink | string, `magnetlink <https://en.wikipedia.org/wiki/Magnet_URI_scheme>`__ of the result |
  224. +------------------+---------------------------------------------------------------------------------------------------------------------------------------+
  225. | torrentfile | string, torrentfile of the result |
  226. +------------------+---------------------------------------------------------------------------------------------------------------------------------------+
  227. map
  228. ~~~
  229. +-------------------------+--------------------------------------------------------------------------------------------------------------+
  230. | result-parameter | information |
  231. +=========================+==============================================================================================================+
  232. | url | string, url of the result |
  233. +-------------------------+--------------------------------------------------------------------------------------------------------------+
  234. | title | string, title of the result |
  235. +-------------------------+--------------------------------------------------------------------------------------------------------------+
  236. | content | string, general result-text |
  237. +-------------------------+--------------------------------------------------------------------------------------------------------------+
  238. | publishedDate | :py:class:`datetime.datetime`, time of publish |
  239. +-------------------------+--------------------------------------------------------------------------------------------------------------+
  240. | latitude | latitude of result (in decimal format) |
  241. +-------------------------+--------------------------------------------------------------------------------------------------------------+
  242. | longitude | longitude of result (in decimal format) |
  243. +-------------------------+--------------------------------------------------------------------------------------------------------------+
  244. | boundingbox | boundingbox of result (array of 4. values ``[lat-min, lat-max, lon-min, lon-max]``) |
  245. +-------------------------+--------------------------------------------------------------------------------------------------------------+
  246. | geojson | geojson of result (http://geojson.org) |
  247. +-------------------------+--------------------------------------------------------------------------------------------------------------+
  248. | osm.type | type of osm-object (if OSM-Result) |
  249. +-------------------------+--------------------------------------------------------------------------------------------------------------+
  250. | osm.id | id of osm-object (if OSM-Result) |
  251. +-------------------------+--------------------------------------------------------------------------------------------------------------+
  252. | address.name | name of object |
  253. +-------------------------+--------------------------------------------------------------------------------------------------------------+
  254. | address.road | street name of object |
  255. +-------------------------+--------------------------------------------------------------------------------------------------------------+
  256. | address.house\_number | house number of object |
  257. +-------------------------+--------------------------------------------------------------------------------------------------------------+
  258. | address.locality | city, place of object |
  259. +-------------------------+--------------------------------------------------------------------------------------------------------------+
  260. | address.postcode | postcode of object |
  261. +-------------------------+--------------------------------------------------------------------------------------------------------------+
  262. | address.country | country of object |
  263. +-------------------------+--------------------------------------------------------------------------------------------------------------+