engine_overview.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. .. _engines-dev:
  2. ===============
  3. Engine Overview
  4. ===============
  5. .. contents::
  6. :depth: 3
  7. :local:
  8. :backlinks: entry
  9. .. _metasearch-engine: https://en.wikipedia.org/wiki/Metasearch_engine
  10. .. sidebar:: Further reading ..
  11. - :ref:`configured engines`
  12. - :ref:`settings engines`
  13. SearXNG is a metasearch-engine_, so it uses different search engines to provide
  14. better results.
  15. Because there is no general search API which could be used for every search
  16. engine, an adapter has to be built between SearXNG and the external search
  17. engines. Adapters are stored under the folder :origin:`searx/engines`.
  18. .. _general engine configuration:
  19. General Engine Configuration
  20. ============================
  21. It is required to tell SearXNG the type of results the engine provides. The
  22. arguments can be set in the engine file or in the settings file (normally
  23. ``settings.yml``). The arguments in the settings file override the ones in the
  24. engine file.
  25. It does not matter if an option is stored in the engine file or in the settings.
  26. However, the standard way is the following:
  27. .. _engine file:
  28. Engine File
  29. -----------
  30. .. table:: Common options in the engine module
  31. :width: 100%
  32. ======================= =========== ========================================================
  33. argument type information
  34. ======================= =========== ========================================================
  35. categories list categories, in which the engine is working
  36. paging boolean support multiple pages
  37. time_range_support boolean support search time range
  38. engine_type str - ``online`` :ref:`[ref] <online engines>` by
  39. default, other possibles values are:
  40. - ``offline`` :ref:`[ref] <offline engines>`
  41. - ``online_dictionary`` :ref:`[ref] <online dictionary>`
  42. - ``online_currency`` :ref:`[ref] <online currency>`
  43. - ``online_url_search`` :ref:`[ref] <online url search>`
  44. ======================= =========== ========================================================
  45. .. _engine settings:
  46. Engine ``settings.yml``
  47. -----------------------
  48. For a more detailed description, see :ref:`settings engines` in the :ref:`settings.yml`.
  49. .. table:: Common options in the engine setup (``settings.yml``)
  50. :width: 100%
  51. ======================= =========== ==================================================
  52. argument type information
  53. ======================= =========== ==================================================
  54. name string name of search-engine
  55. engine string name of searxng-engine (file name without ``.py``)
  56. enable_http bool enable HTTP (by default only HTTPS is enabled).
  57. shortcut string shortcut of search-engine
  58. timeout string specific timeout for search-engine
  59. display_error_messages boolean display error messages on the web UI
  60. proxies dict set proxies for a specific engine
  61. (e.g. ``proxies : {http: socks5://proxy:port,
  62. https: socks5://proxy:port}``)
  63. ======================= =========== ==================================================
  64. .. _engine overrides:
  65. Overrides
  66. ---------
  67. A few of the options have default values in the namespace of the engine's python
  68. module, but are often overwritten by the settings. If ``None`` is assigned to an
  69. option in the engine file, it has to be redefined in the settings, otherwise
  70. SearXNG will not start with that engine (global names with a leading underline can
  71. be ``None``).
  72. Here is an very simple example of the global names in the namespace of engine's
  73. module:
  74. .. code:: python
  75. # engine dependent config
  76. categories = ['general']
  77. paging = True
  78. _non_overwritten_global = 'foo'
  79. .. table:: The naming of overrides is arbitrary / recommended overrides are:
  80. :width: 100%
  81. ======================= =========== ===========================================
  82. argument type information
  83. ======================= =========== ===========================================
  84. base_url string base-url, can be overwritten to use same
  85. engine on other URL
  86. number_of_results int maximum number of results per request
  87. language string ISO code of language and country like en_US
  88. api_key string api-key if required by engine
  89. ======================= =========== ===========================================
  90. .. _engine request:
  91. Making a Request
  92. ================
  93. To perform a search an URL have to be specified. In addition to specifying an
  94. URL, arguments can be passed to the query.
  95. .. _engine request arguments:
  96. Passed Arguments (request)
  97. --------------------------
  98. These arguments can be used to construct the search query. Furthermore,
  99. parameters with default value can be redefined for special purposes.
  100. .. _engine request online:
  101. .. table:: If the ``engine_type`` is :py:obj:`online
  102. <searx.search.processors.online.OnlineProcessor.get_params>`
  103. :width: 100%
  104. ====================== ============== ========================================================================
  105. argument type default-value, information
  106. ====================== ============== ========================================================================
  107. url str ``''``
  108. method str ``'GET'``
  109. headers set ``{}``
  110. data set ``{}``
  111. cookies set ``{}``
  112. verify bool ``True``
  113. headers.User-Agent str a random User-Agent
  114. category str current category, like ``'general'``
  115. safesearch int ``0``, between ``0`` and ``2`` (normal, moderate, strict)
  116. time_range Optional[str] ``None``, can be ``day``, ``week``, ``month``, ``year``
  117. pageno int current pagenumber
  118. searxng_locale str SearXNG's locale selected by user. Specific language code like
  119. ``'en'``, ``'en-US'``, or ``'all'`` if unspecified.
  120. ====================== ============== ========================================================================
  121. .. _engine request online_dictionary:
  122. .. table:: If the ``engine_type`` is :py:obj:`online_dictionary
  123. <searx.search.processors.online_dictionary.OnlineDictionaryProcessor.get_params>`,
  124. in addition to the :ref:`online <engine request online>` arguments:
  125. :width: 100%
  126. ====================== ============== ========================================================================
  127. argument type default-value, information
  128. ====================== ============== ========================================================================
  129. from_lang str specific language code like ``'en_US'``
  130. to_lang str specific language code like ``'en_US'``
  131. query str the text query without the languages
  132. ====================== ============== ========================================================================
  133. .. _engine request online_currency:
  134. .. table:: If the ``engine_type`` is :py:obj:`online_currency
  135. <searx.search.processors.online_currency.OnlineCurrencyProcessor.get_params>`,
  136. in addition to the :ref:`online <engine request online>` arguments:
  137. :width: 100%
  138. ====================== ============== ========================================================================
  139. argument type default-value, information
  140. ====================== ============== ========================================================================
  141. amount float the amount to convert
  142. from str ISO 4217 code
  143. to str ISO 4217 code
  144. from_name str currency name
  145. to_name str currency name
  146. ====================== ============== ========================================================================
  147. .. _engine request online_url_search:
  148. .. table:: If the ``engine_type`` is :py:obj:`online_url_search
  149. <searx.search.processors.online_url_search.OnlineUrlSearchProcessor.get_params>`,
  150. in addition to the :ref:`online <engine request online>` arguments:
  151. :width: 100%
  152. ====================== ============== ========================================================================
  153. argument type default-value, information
  154. ====================== ============== ========================================================================
  155. search_url dict URLs from the search query:
  156. .. code:: python
  157. {
  158. 'http': str,
  159. 'ftp': str,
  160. 'data:image': str
  161. }
  162. ====================== ============== ========================================================================
  163. Specify Request
  164. ---------------
  165. The function :py:func:`def request(query, params):
  166. <searx.engines.demo_online.request>` always returns the ``params`` variable, the
  167. following parameters can be used to specify a search request:
  168. .. table::
  169. :width: 100%
  170. =================== =========== ==========================================================================
  171. argument type information
  172. =================== =========== ==========================================================================
  173. url str requested url
  174. method str HTTP request method
  175. headers set HTTP header information
  176. data set HTTP data information
  177. cookies set HTTP cookies
  178. verify bool Performing SSL-Validity check
  179. allow_redirects bool Follow redirects
  180. max_redirects int maximum redirects, hard limit
  181. soft_max_redirects int maximum redirects, soft limit. Record an error but don't stop the engine
  182. raise_for_httperror bool True by default: raise an exception if the HTTP code of response is >= 300
  183. =================== =========== ==========================================================================
  184. Making a Response
  185. =================
  186. In the ``response`` function of the engine, the HTTP response (``resp``) is
  187. parsed and a list of results is returned.
  188. A engine can append result-items of different media-types and different
  189. result-types to the result list. The list of the result items is render to HTML
  190. by templates. For more details read section:
  191. - :ref:`simple theme templates`
  192. - :ref:`result types`