.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
meilisearch.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2""".. sidebar:: info
3
4 - :origin:`meilisearch.py <searx/engines/meilisearch.py>`
5 - `MeiliSearch <https://www.meilisearch.com>`_
6 - `MeiliSearch Documentation <https://docs.meilisearch.com/>`_
7 - `Install MeiliSearch
8 <https://docs.meilisearch.com/learn/getting_started/installation.html>`_
9
10MeiliSearch_ is aimed at individuals and small companies. It is designed for
11small-scale (less than 10 million documents) data collections. E.g. it is great
12for storing web pages you have visited and searching in the contents later.
13
14The engine supports faceted search, so you can search in a subset of documents
15of the collection. Furthermore, you can search in MeiliSearch_ instances that
16require authentication by setting `auth_key`_.
17
18.. _auth_key: https://www.meilisearch.com/docs/reference/api/overview#authorization
19
20Example
21=======
22
23Here is a simple example to query a Meilisearch instance:
24
25.. code:: yaml
26
27 - name: meilisearch
28 engine: meilisearch
29 shortcut: mes
30 base_url: http://localhost:7700
31 index: my-index
32 enable_http: true
33 # auth_key: Bearer XXXXX
34
35"""
36
37# pylint: disable=global-statement
38
39from json import dumps
40from searx.result_types import EngineResults
41from searx.extended_types import SXNG_Response
42
43base_url = 'http://localhost:7700'
44index = ''
45auth_key = ''
46facet_filters = []
47_search_url = ''
48categories = ['general']
49paging = True
50
51
52def init(_):
53 if index == '':
54 raise ValueError('index cannot be empty')
55
56 global _search_url
57 _search_url = base_url + '/indexes/' + index + '/search'
58
59
60def request(query, params):
61 if auth_key != '':
62 params['headers']['Authorization'] = auth_key
63
64 params['headers']['Content-Type'] = 'application/json'
65 params['url'] = _search_url
66 params['method'] = 'POST'
67
68 data = {
69 'q': query,
70 'offset': 10 * (params['pageno'] - 1),
71 'limit': 10,
72 }
73 if len(facet_filters) > 0:
74 data['facetFilters'] = facet_filters
75
76 params['data'] = dumps(data)
77
78 return params
79
80
81def response(resp: SXNG_Response) -> EngineResults:
82 res = EngineResults()
83
84 resp_json = resp.json()
85 for row in resp_json['hits']:
86 kvmap = {key: str(value) for key, value in row.items()}
87 res.add(res.types.KeyValue(kvmap=kvmap))
88
89 return res
EngineResults response(SXNG_Response resp)