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

Functions

 init (engine_settings)
 
EngineResults search (query, params)
 

Variables

 logger = logging.getLogger()
 
str engine_type = 'offline'
 
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

MariaDB is a community driven fork of MySQL. Before enabling MariaDB engine,
you must the install the pip package ``mariadb`` along with the necessary
prerequities.

`See the following documentation for more details
<https://mariadb.com/docs/server/connect/programming-languages/c/install/>`_

Example
=======

This is an example configuration for querying a MariaDB server:

.. code:: yaml

   - name: my_database
     engine: mariadb_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.mariadb_server.init ( engine_settings)

Definition at line 71 of file mariadb_server.py.

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

◆ search()

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

Definition at line 83 of file mariadb_server.py.

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

Variable Documentation

◆ _connection

searx.engines.mariadb_server._connection = None
protected

Definition at line 68 of file mariadb_server.py.

◆ database

str searx.engines.mariadb_server.database = ""

Definition at line 54 of file mariadb_server.py.

◆ engine_type

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

Definition at line 46 of file mariadb_server.py.

◆ host

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

Definition at line 48 of file mariadb_server.py.

◆ limit

int searx.engines.mariadb_server.limit = 10

Definition at line 66 of file mariadb_server.py.

◆ logger

searx.engines.mariadb_server.logger = logging.getLogger()

Definition at line 43 of file mariadb_server.py.

◆ paging

bool searx.engines.mariadb_server.paging = True

Definition at line 67 of file mariadb_server.py.

◆ password

str searx.engines.mariadb_server.password = ""

Definition at line 60 of file mariadb_server.py.

◆ port

int searx.engines.mariadb_server.port = 3306

Definition at line 51 of file mariadb_server.py.

◆ query_str

str searx.engines.mariadb_server.query_str = ""

Definition at line 63 of file mariadb_server.py.

◆ username

str searx.engines.mariadb_server.username = ""

Definition at line 57 of file mariadb_server.py.