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

Functions

 init (_engine_settings)
 
 search (query, _params)
 
 search_keys (query)
 

Variables

str engine_type = 'offline'
 
str host = '127.0.0.1'
 
int port = 6379
 
str password = ''
 
int db = 0
 
bool paging = False
 
str result_template = 'key-value.html'
 
bool exact_match_only = True
 
 _redis_client = None
 

Detailed Description

Redis is an open source (BSD licensed), in-memory data structure (key value
based) store.  Before configuring the ``redis_server`` engine, you must install
the dependency redis_.

Configuration
=============

Select a database to search in and set its index in the option ``db``.  You can
either look for exact matches or use partial keywords to find what you are
looking for by configuring ``exact_match_only``.

Example
=======

Below is an example configuration:

.. code:: yaml

  # Required dependency: redis

  - name: myredis
    shortcut : rds
    engine: redis_server
    exact_match_only: false
    host: '127.0.0.1'
    port: 6379
    enable_http: true
    password: ''
    db: 0

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

Function Documentation

◆ init()

searx.engines.redis_server.init ( _engine_settings)

Definition at line 55 of file redis_server.py.

55def init(_engine_settings):
56 global _redis_client # pylint: disable=global-statement
57 _redis_client = redis.StrictRedis(
58 host=host,
59 port=port,
60 db=db,
61 password=password or None,
62 decode_responses=True,
63 )
64
65

◆ search()

searx.engines.redis_server.search ( query,
_params )

Definition at line 66 of file redis_server.py.

66def search(query, _params):
67 if not exact_match_only:
68 return search_keys(query)
69
70 ret = _redis_client.hgetall(query)
71 if ret:
72 ret['template'] = result_template
73 return [ret]
74
75 if ' ' in query:
76 qset, rest = query.split(' ', 1)
77 ret = []
78 for res in _redis_client.hscan_iter(qset, match='*{}*'.format(rest)):
79 ret.append(
80 {
81 res[0]: res[1],
82 'template': result_template,
83 }
84 )
85 return ret
86 return []
87
88

References searx.format, and searx.engines.redis_server.search_keys().

+ Here is the call graph for this function:

◆ search_keys()

searx.engines.redis_server.search_keys ( query)

Definition at line 89 of file redis_server.py.

89def search_keys(query):
90 ret = []
91 for key in _redis_client.scan_iter(match='*{}*'.format(query)):
92 key_type = _redis_client.type(key)
93 res = None
94
95 if key_type == 'hash':
96 res = _redis_client.hgetall(key)
97 elif key_type == 'list':
98 res = dict(enumerate(_redis_client.lrange(key, 0, -1)))
99
100 if res:
101 res['template'] = result_template
102 res['redis_key'] = key
103 ret.append(res)
104 return ret

References searx.format.

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

+ Here is the caller graph for this function:

Variable Documentation

◆ _redis_client

searx.engines.redis_server._redis_client = None
protected

Definition at line 52 of file redis_server.py.

◆ db

int searx.engines.redis_server.db = 0

Definition at line 45 of file redis_server.py.

◆ engine_type

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

Definition at line 39 of file redis_server.py.

◆ exact_match_only

bool searx.engines.redis_server.exact_match_only = True

Definition at line 50 of file redis_server.py.

◆ host

str searx.engines.redis_server.host = '127.0.0.1'

Definition at line 42 of file redis_server.py.

◆ paging

bool searx.engines.redis_server.paging = False

Definition at line 48 of file redis_server.py.

◆ password

str searx.engines.redis_server.password = ''

Definition at line 44 of file redis_server.py.

◆ port

int searx.engines.redis_server.port = 6379

Definition at line 43 of file redis_server.py.

◆ result_template

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

Definition at line 49 of file redis_server.py.