.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.engines.mysql_server Namespace Reference

Functions

 init (engine_settings)
 
EngineResults search (query, params)
 

Variables

str engine_type = 'offline'
 
str auth_plugin = 'caching_sha2_password'
 
str host = "127.0.0.1"
 
int port = 3306
 
str database = ""
 
str username = ""
 
str password = ""
 
str query_str = ""
 
int limit = 10
 
bool paging = True
 
 _connection = None
 

Detailed Description

MySQL is said to be the most popular open source database.  Before enabling
MySQL engine, you must install the package ``mysql-connector-python``.

The authentication plugin is configurable by setting ``auth_plugin`` in the
attributes.  By default it is set to ``caching_sha2_password``.

Example
=======

This is an example configuration for querying a MySQL server:

.. code:: yaml

   - name: my_database
     engine: mysql_server
     database: my_database
     username: searxng
     password: password
     limit: 5
     query_str: 'SELECT * from my_table WHERE my_column=%(query)s'

Implementations
===============

Function Documentation

◆ init()

searx.engines.mysql_server.init ( engine_settings)

Definition at line 63 of file mysql_server.py.

63def init(engine_settings):
64 global _connection # pylint: disable=global-statement
65
66 if 'query_str' not in engine_settings:
67 raise ValueError('query_str cannot be empty')
68
69 if not engine_settings['query_str'].lower().startswith('select '):
70 raise ValueError('only SELECT query is supported')
71
72 _connection = mysql.connector.connect(
73 database=database,
74 user=username,
75 password=password,
76 host=host,
77 port=port,
78 auth_plugin=auth_plugin,
79 )
80
81

◆ search()

EngineResults searx.engines.mysql_server.search ( query,
params )

Definition at line 82 of file mysql_server.py.

82def search(query, params) -> EngineResults:
83 res = EngineResults()
84 query_params = {'query': query}
85 query_to_run = query_str + ' LIMIT {0} OFFSET {1}'.format(limit, (params['pageno'] - 1) * limit)
86
87 with _connection.cursor() as cur:
88 cur.execute(query_to_run, query_params)
89 for row in cur:
90 kvmap = dict(zip(cur.column_names, map(str, row)))
91 res.add(res.types.KeyValue(kvmap=kvmap))
92
93 return res

Variable Documentation

◆ _connection

searx.engines.mysql_server._connection = None
protected

Definition at line 60 of file mysql_server.py.

◆ auth_plugin

str searx.engines.mysql_server.auth_plugin = 'caching_sha2_password'

Definition at line 38 of file mysql_server.py.

◆ database

str searx.engines.mysql_server.database = ""

Definition at line 46 of file mysql_server.py.

◆ engine_type

str searx.engines.mysql_server.engine_type = 'offline'

Definition at line 37 of file mysql_server.py.

◆ host

str searx.engines.mysql_server.host = "127.0.0.1"

Definition at line 40 of file mysql_server.py.

◆ limit

int searx.engines.mysql_server.limit = 10

Definition at line 58 of file mysql_server.py.

◆ paging

bool searx.engines.mysql_server.paging = True

Definition at line 59 of file mysql_server.py.

◆ password

str searx.engines.mysql_server.password = ""

Definition at line 52 of file mysql_server.py.

◆ port

int searx.engines.mysql_server.port = 3306

Definition at line 43 of file mysql_server.py.

◆ query_str

str searx.engines.mysql_server.query_str = ""

Definition at line 55 of file mysql_server.py.

◆ username

str searx.engines.mysql_server.username = ""

Definition at line 49 of file mysql_server.py.