sql-engines.rst 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. .. _sql engines:
  2. ===========
  3. SQL Engines
  4. ===========
  5. .. sidebar:: further read
  6. - `SQLite <https://www.sqlite.org/index.html>`_
  7. - `PostgreSQL <https://www.postgresql.org>`_
  8. - `MySQL <https://www.mysql.com>`_
  9. .. contents::
  10. :depth: 2
  11. :local:
  12. :backlinks: entry
  13. .. sidebar:: info
  14. Initial sponsored by `Search and Discovery Fund
  15. <https://nlnet.nl/discovery>`_ of `NLnet Foundation <https://nlnet.nl/>`_.
  16. With the *SQL engines* you can bind SQL databases into SearXNG. The following
  17. Relational Database Management System (RDBMS) are supported:
  18. - :ref:`engine sqlite`
  19. - :ref:`engine postgresql`
  20. - :ref:`engine mysql_server` & :ref:`engine mariadb_server`
  21. All of the engines above are just commented out in the :origin:`settings.yml
  22. <searx/settings.yml>`, as you have to set the required attributes for the
  23. engines, e.g. ``database:`` ...
  24. .. code:: yaml
  25. - name: ...
  26. engine: {sqlite|postgresql|mysql_server}
  27. database: ...
  28. result_template: {template_name}
  29. query_str: ...
  30. By default, the engines use the ``key-value`` template for displaying results /
  31. see :origin:`simple <searx/templates/simple/result_templates/key-value.html>`
  32. theme. If you are not satisfied with the original result layout, you can use
  33. your own template, set ``result_template`` attribute to ``{template_name}`` and
  34. place the templates at::
  35. searx/templates/{theme_name}/result_templates/{template_name}
  36. If you do not wish to expose these engines on a public instance, you can still
  37. add them and limit the access by setting ``tokens`` as described in section
  38. :ref:`private engines`.
  39. Extra Dependencies
  40. ==================
  41. For using :ref:`engine postgresql` or :ref:`engine mysql_server` you need to
  42. install additional packages in Python's Virtual Environment of your SearXNG
  43. instance. To switch into the environment (:ref:`searxng-src`) you can use
  44. :ref:`searxng.sh`::
  45. $ sudo utils/searxng.sh instance cmd bash
  46. (searxng-pyenv)$ pip install ...
  47. Configure the engines
  48. =====================
  49. The configuration of the new database engines are similar. You must put a valid
  50. SQL-SELECT query in ``query_str``. At the moment you can only bind at most one
  51. parameter in your query. By setting the attribute ``limit`` you can define how
  52. many results you want from the SQL server. Basically, it is the same as the
  53. ``LIMIT`` keyword in SQL.
  54. Please, do not include ``LIMIT`` or ``OFFSET`` in your SQL query as the engines
  55. rely on these keywords during paging. If you want to configure the number of
  56. returned results use the option ``limit``.
  57. .. _engine sqlite:
  58. SQLite
  59. ------
  60. .. sidebar:: info
  61. - :origin:`sqlite.py <searx/engines/sqlite.py>`
  62. .. automodule:: searx.engines.sqlite
  63. :members:
  64. .. _engine postgresql:
  65. PostgreSQL
  66. ----------
  67. .. _psycopg2: https://www.psycopg.org/install
  68. .. sidebar:: info
  69. - :origin:`postgresql.py <searx/engines/postgresql.py>`
  70. - ``pip install`` `psycopg2-binary <psycopg2>`_
  71. .. automodule:: searx.engines.postgresql
  72. :members:
  73. .. _engine mysql_server:
  74. MySQL
  75. -----
  76. .. sidebar:: info
  77. - :origin:`mysql_server.py <searx/engines/mysql_server.py>`
  78. - ``pip install`` :pypi:`mysql-connector-python <mysql-connector-python>`
  79. .. automodule:: searx.engines.mysql_server
  80. :members:
  81. .. _engine mariadb_server:
  82. MariaDB
  83. --------
  84. .. sidebar:: info
  85. - :origin:`mariadb_server.py <searx/engines/mariadb_server.py>`
  86. - ``pip install`` :pypi:`mariadb <mariadb>`
  87. .. automodule:: searx.engines.mariadb_server
  88. :members: