engine_overview.rst 26KB

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