summaryrefslogtreecommitdiff
path: root/searx
diff options
context:
space:
mode:
authorNoémi Ványi <sitbackandwait@gmail.com>2021-04-02 16:16:57 +0200
committerNoémi Ványi <sitbackandwait@gmail.com>2021-04-06 21:57:05 +0200
commit07f5edce3d47164eb6b7858a1d025a707d716689 (patch)
tree13e007c5f799aa2ceb1668a71196da45bf39d4a1 /searx
parentdd2b106f947597203db19449054d4fd422a55365 (diff)
downloadsearxng-07f5edce3d47164eb6b7858a1d025a707d716689.tar.gz
searxng-07f5edce3d47164eb6b7858a1d025a707d716689.zip
Add Meilisearch engine
Website: https://www.meilisearch.com/
Diffstat (limited to 'searx')
-rw-r--r--searx/engines/meilisearch.py59
-rw-r--r--searx/settings.yml7
2 files changed, 66 insertions, 0 deletions
diff --git a/searx/engines/meilisearch.py b/searx/engines/meilisearch.py
new file mode 100644
index 000000000..4e0ff15f3
--- /dev/null
+++ b/searx/engines/meilisearch.py
@@ -0,0 +1,59 @@
+# SPDX-License-Identifier: AGPL-3.0-or-later
+"""
+ Meilisearch
+"""
+
+# pylint: disable=global-statement, missing-function-docstring
+
+from json import loads, dumps
+
+
+base_url = 'http://localhost:7700'
+index = ''
+auth_key = ''
+facet_filters = list()
+_search_url = ''
+result_template = 'key-value.html'
+categories = ['general']
+paging = True
+
+
+def init(_):
+ if index == '':
+ raise ValueError('index cannot be empty')
+
+ global _search_url
+ _search_url = base_url + '/indexes/' + index + '/search'
+
+
+def request(query, params):
+ if auth_key != '':
+ params['headers']['X-Meili-API-Key'] = auth_key
+
+ params['headers']['Content-Type'] = 'application/json'
+ params['url'] = _search_url
+ params['method'] = 'POST'
+
+ data = {
+ 'q': query,
+ 'offset': 10 * (params['pageno'] - 1),
+ 'limit': 10,
+ }
+ if len(facet_filters) > 0:
+ data['facetFilters'] = facet_filters
+
+ params['data'] = dumps(data)
+
+ return params
+
+
+def response(resp):
+ results = []
+
+ resp_json = loads(resp.text)
+ for result in resp_json['hits']:
+ r = {key: str(value) for key, value in result.items()}
+ r['template'] = result_template
+ results.append(r)
+
+ return results
diff --git a/searx/settings.yml b/searx/settings.yml
index 50bccb1ef..3428b2ec5 100644
--- a/searx/settings.yml
+++ b/searx/settings.yml
@@ -700,6 +700,13 @@ engines:
require_api_key: false
results: HTML
+# - name : meilisearch
+# engine : meilisearch
+# shortcut: mes
+# enable_http: True
+# base_url : http://localhost:7700
+# index : my-index
+
- name : microsoft academic
engine : microsoft_academic
categories : science