@@ -0,0 +1,59 @@
1+# SPDX-License-Identifier: AGPL-3.0-or-later
2+"""
3+ Meilisearch
4+"""
5+
6+# pylint: disable=global-statement, missing-function-docstring
7+
8+from json import loads, dumps
9+
10+
11+base_url = 'http://localhost:7700'
12+index = ''
13+auth_key = ''
14+facet_filters = list()
15+_search_url = ''
16+result_template = 'key-value.html'
17+categories = ['general']
18+paging = True
19+
20+
21+def init(_):
22+ if index == '':
23+ raise ValueError('index cannot be empty')
24+
25+ global _search_url
26+ _search_url = base_url + '/indexes/' + index + '/search'
27+
28+
29+def request(query, params):
30+ if auth_key != '':
31+ params['headers']['X-Meili-API-Key'] = auth_key
32+
33+ params['headers']['Content-Type'] = 'application/json'
34+ params['url'] = _search_url
35+ params['method'] = 'POST'
36+
37+ data = {
38+ 'q': query,
39+ 'offset': 10 * (params['pageno'] - 1),
40+ 'limit': 10,
41+ }
42+ if len(facet_filters) > 0:
43+ data['facetFilters'] = facet_filters
44+
45+ params['data'] = dumps(data)
46+
47+ return params
48+
49+
50+def response(resp):
51+ results = []
52+
53+ resp_json = loads(resp.text)
54+ for result in resp_json['hits']:
55+ r = {key: str(value) for key, value in result.items()}
56+ r['template'] = result_template
57+ results.append(r)
58+
59+ return results