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

Functions

 init (engine_settings)
 
 search (query, params)
 
 _fetch_results (cur)
 

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
 
str result_template = 'key-value.html'
 
 _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

◆ _fetch_results()

searx.engines.mysql_server._fetch_results ( cur)
protected

Definition at line 91 of file mysql_server.py.

91def _fetch_results(cur):
92 results = []
93 for res in cur:
94 result = dict(zip(cur.column_names, map(str, res)))
95 result['template'] = result_template
96 results.append(result)
97
98 return results

◆ init()

searx.engines.mysql_server.init ( engine_settings)

Definition at line 62 of file mysql_server.py.

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

◆ search()

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

Definition at line 81 of file mysql_server.py.

81def search(query, params):
82 query_params = {'query': query}
83 query_to_run = query_str + ' LIMIT {0} OFFSET {1}'.format(limit, (params['pageno'] - 1) * limit)
84
85 with _connection.cursor() as cur:
86 cur.execute(query_to_run, query_params)
87
88 return _fetch_results(cur)
89
90

Variable Documentation

◆ _connection

searx.engines.mysql_server._connection = None
protected

Definition at line 59 of file mysql_server.py.

◆ auth_plugin

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

Definition at line 36 of file mysql_server.py.

◆ database

str searx.engines.mysql_server.database = ""

Definition at line 44 of file mysql_server.py.

◆ engine_type

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

Definition at line 35 of file mysql_server.py.

◆ host

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

Definition at line 38 of file mysql_server.py.

◆ limit

int searx.engines.mysql_server.limit = 10

Definition at line 56 of file mysql_server.py.

◆ paging

bool searx.engines.mysql_server.paging = True

Definition at line 57 of file mysql_server.py.

◆ password

str searx.engines.mysql_server.password = ""

Definition at line 50 of file mysql_server.py.

◆ port

int searx.engines.mysql_server.port = 3306

Definition at line 41 of file mysql_server.py.

◆ query_str

str searx.engines.mysql_server.query_str = ""

Definition at line 53 of file mysql_server.py.

◆ result_template

str searx.engines.mysql_server.result_template = 'key-value.html'

Definition at line 58 of file mysql_server.py.

◆ username

str searx.engines.mysql_server.username = ""

Definition at line 47 of file mysql_server.py.