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

Functions

 init (engine_settings)
 
 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
 
str result_template = 'key-value.html'
 
 _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 70 of file mariadb_server.py.

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

◆ search()

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

Definition at line 82 of file mariadb_server.py.

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

Variable Documentation

◆ _connection

searx.engines.mariadb_server._connection = None
protected

Definition at line 67 of file mariadb_server.py.

◆ database

str searx.engines.mariadb_server.database = ""

Definition at line 52 of file mariadb_server.py.

◆ engine_type

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

Definition at line 44 of file mariadb_server.py.

◆ host

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

Definition at line 46 of file mariadb_server.py.

◆ limit

int searx.engines.mariadb_server.limit = 10

Definition at line 64 of file mariadb_server.py.

◆ logger

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

Definition at line 41 of file mariadb_server.py.

◆ paging

bool searx.engines.mariadb_server.paging = True

Definition at line 65 of file mariadb_server.py.

◆ password

str searx.engines.mariadb_server.password = ""

Definition at line 58 of file mariadb_server.py.

◆ port

int searx.engines.mariadb_server.port = 3306

Definition at line 49 of file mariadb_server.py.

◆ query_str

str searx.engines.mariadb_server.query_str = ""

Definition at line 61 of file mariadb_server.py.

◆ result_template

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

Definition at line 66 of file mariadb_server.py.

◆ username

str searx.engines.mariadb_server.username = ""

Definition at line 55 of file mariadb_server.py.