summaryrefslogtreecommitdiff
path: root/searx/engines/mongodb.py
diff options
context:
space:
mode:
authorMarkus Heiser <markus.heiser@darmarit.de>2021-12-27 09:26:22 +0100
committerMarkus Heiser <markus.heiser@darmarit.de>2021-12-27 09:26:22 +0100
commit3d96a9839a12649874b6d4cf9466bd3616b0a03c (patch)
treee7d54d1e345b1e792d538ddc250f4827bb2fd9b9 /searx/engines/mongodb.py
parentfcdc2c2cd26e24c2aa3f064d93cee3e29dc2a30c (diff)
downloadsearxng-3d96a9839a12649874b6d4cf9466bd3616b0a03c.tar.gz
searxng-3d96a9839a12649874b6d4cf9466bd3616b0a03c.zip
[format.python] initial formatting of the python code
This patch was generated by black [1]:: make format.python [1] https://github.com/psf/black Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'searx/engines/mongodb.py')
-rw-r--r--searx/engines/mongodb.py23
1 files changed, 10 insertions, 13 deletions
diff --git a/searx/engines/mongodb.py b/searx/engines/mongodb.py
index 2ebb90539..c833ca9e0 100644
--- a/searx/engines/mongodb.py
+++ b/searx/engines/mongodb.py
@@ -26,38 +26,35 @@ result_template = 'key-value.html'
_client = None
+
def init(_):
connect()
+
def connect():
global _client # pylint: disable=global-statement
- kwargs = { 'port': port }
+ kwargs = {'port': port}
if username:
kwargs['username'] = username
if password:
kwargs['password'] = password
_client = MongoClient(host, **kwargs)[database][collection]
+
def search(query, params):
results = []
if exact_match_only:
- q = { '$eq': query }
+ q = {'$eq': query}
else:
- _re = re.compile('.*{0}.*'.format(re.escape(query)), re.I | re.M )
- q = { '$regex': _re }
+ _re = re.compile('.*{0}.*'.format(re.escape(query)), re.I | re.M)
+ q = {'$regex': _re}
- query = _client.find(
- {key: q}
- ).skip(
- ( params['pageno'] -1 ) * results_per_page
- ).limit(
- results_per_page
- )
+ query = _client.find({key: q}).skip((params['pageno'] - 1) * results_per_page).limit(results_per_page)
- results.append({ 'number_of_results': query.count() })
+ results.append({'number_of_results': query.count()})
for r in query:
del r['_id']
- r = { str(k):str(v) for k,v in r.items() }
+ r = {str(k): str(v) for k, v in r.items()}
r['template'] = result_template
results.append(r)