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

Functions

 init (_)
 
 connect ()
 
 search (query, params)
 

Variables

str engine_type = 'offline'
 
str host = '127.0.0.1'
 
int port = 27017
 
str username = ''
 
str password = ''
 
 database = None
 
 collection = None
 
 key = None
 
bool paging = True
 
int results_per_page = 20
 
bool exact_match_only = False
 
str result_template = 'key-value.html'
 
 _client = None
 

Detailed Description

MongoDB_ is a document based database program that handles JSON like data.
Before configuring the ``mongodb`` engine, you must install the dependency
pymongo_.

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

In order to query MongoDB_, you have to select a ``database`` and a
``collection``.  Furthermore, you have to select a ``key`` that is going to be
searched.  MongoDB_ also supports the option ``exact_match_only``, so configure
it as you wish.

Example
=======

Below is an example configuration for using a MongoDB collection:

.. code:: yaml

  # MongoDB engine
  # Required dependency: pymongo

  - name: mymongo
    engine: mongodb
    shortcut: md
    exact_match_only: false
    host: '127.0.0.1'
    port: 27017
    enable_http: true
    results_per_page: 20
    database: 'business'
    collection: 'reviews'  # name of the db collection
    key: 'name'            # key in the collection to search for

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

Function Documentation

◆ connect()

searx.engines.mongodb.connect ( )

Definition at line 75 of file mongodb.py.

75def connect():
76 global _client # pylint: disable=global-statement
77 kwargs = {'port': port}
78 if username:
79 kwargs['username'] = username
80 if password:
81 kwargs['password'] = password
82 _client = MongoClient(host, **kwargs)[database][collection]
83
84

Referenced by searx.engines.mongodb.init().

+ Here is the caller graph for this function:

◆ init()

searx.engines.mongodb.init ( _)

Definition at line 71 of file mongodb.py.

71def init(_):
72 connect()
73
74

References searx.engines.mongodb.connect().

+ Here is the call graph for this function:

◆ search()

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

Definition at line 85 of file mongodb.py.

85def search(query, params):
86 results = []
87 if exact_match_only:
88 q = {'$eq': query}
89 else:
90 _re = re.compile('.*{0}.*'.format(re.escape(query)), re.I | re.M)
91 q = {'$regex': _re}
92
93 query = _client.find({key: q}).skip((params['pageno'] - 1) * results_per_page).limit(results_per_page)
94
95 results.append({'number_of_results': query.count()})
96 for r in query:
97 del r['_id']
98 r = {str(k): str(v) for k, v in r.items()}
99 r['template'] = result_template
100 results.append(r)
101
102 return results

References searx.format.

Variable Documentation

◆ _client

searx.engines.mongodb._client = None
protected

Definition at line 68 of file mongodb.py.

◆ collection

searx.engines.mongodb.collection = None

Definition at line 59 of file mongodb.py.

◆ database

searx.engines.mongodb.database = None

Definition at line 58 of file mongodb.py.

◆ engine_type

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

Definition at line 51 of file mongodb.py.

◆ exact_match_only

bool searx.engines.mongodb.exact_match_only = False

Definition at line 65 of file mongodb.py.

◆ host

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

Definition at line 54 of file mongodb.py.

◆ key

searx.engines.mongodb.key = None

Definition at line 60 of file mongodb.py.

◆ paging

bool searx.engines.mongodb.paging = True

Definition at line 63 of file mongodb.py.

◆ password

str searx.engines.mongodb.password = ''

Definition at line 57 of file mongodb.py.

◆ port

int searx.engines.mongodb.port = 27017

Definition at line 55 of file mongodb.py.

◆ result_template

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

Definition at line 66 of file mongodb.py.

◆ results_per_page

int searx.engines.mongodb.results_per_page = 20

Definition at line 64 of file mongodb.py.

◆ username

str searx.engines.mongodb.username = ''

Definition at line 56 of file mongodb.py.