engine_overview.rst 24 KB

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