engine_overview.txt 24KB

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