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

Functions

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

Variables

str engine_type = 'offline'
 
str host = "127.0.0.1"
 
str port = "5432"
 
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

PostgreSQL is a powerful and robust open source database.  Before configuring
the PostgreSQL engine, you must install the dependency ``psychopg2``.

Example
=======

Below is an example configuration:

.. code:: yaml

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

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

Function Documentation

◆ _fetch_results()

searx.engines.postgresql._fetch_results ( cur)
protected

Definition at line 72 of file postgresql.py.

72def _fetch_results(cur):
73 results = []
74 titles = []
75
76 try:
77 titles = [column_desc.name for column_desc in cur.description]
78
79 for res in cur:
80 result = dict(zip(titles, map(str, res)))
81 result['template'] = result_template
82 results.append(result)
83
84 # no results to fetch
85 except psycopg2.ProgrammingError:
86 pass
87
88 return results

Referenced by searx.engines.postgresql.search().

+ Here is the caller graph for this function:

◆ init()

searx.engines.postgresql.init ( engine_settings)

Definition at line 44 of file postgresql.py.

44def init(engine_settings):
45 global _connection # pylint: disable=global-statement
46
47 if 'query_str' not in engine_settings:
48 raise ValueError('query_str cannot be empty')
49
50 if not engine_settings['query_str'].lower().startswith('select '):
51 raise ValueError('only SELECT query is supported')
52
53 _connection = psycopg2.connect(
54 database=database,
55 user=username,
56 password=password,
57 host=host,
58 port=port,
59 )
60
61

◆ search()

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

Definition at line 62 of file postgresql.py.

62def search(query, params):
63 query_params = {'query': query}
64 query_to_run = query_str + ' LIMIT {0} OFFSET {1}'.format(limit, (params['pageno'] - 1) * limit)
65
66 with _connection:
67 with _connection.cursor() as cur:
68 cur.execute(query_to_run, query_params)
69 return _fetch_results(cur)
70
71

References searx.engines.postgresql._fetch_results(), and searx.format.

+ Here is the call graph for this function:

Variable Documentation

◆ _connection

searx.engines.postgresql._connection = None
protected

Definition at line 41 of file postgresql.py.

◆ database

str searx.engines.postgresql.database = ""

Definition at line 34 of file postgresql.py.

◆ engine_type

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

Definition at line 31 of file postgresql.py.

◆ host

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

Definition at line 32 of file postgresql.py.

◆ limit

int searx.engines.postgresql.limit = 10

Definition at line 38 of file postgresql.py.

◆ paging

bool searx.engines.postgresql.paging = True

Definition at line 39 of file postgresql.py.

◆ password

str searx.engines.postgresql.password = ""

Definition at line 36 of file postgresql.py.

◆ port

str searx.engines.postgresql.port = "5432"

Definition at line 33 of file postgresql.py.

◆ query_str

str searx.engines.postgresql.query_str = ""

Definition at line 37 of file postgresql.py.

◆ result_template

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

Definition at line 40 of file postgresql.py.

◆ username

str searx.engines.postgresql.username = ""

Definition at line 35 of file postgresql.py.