.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
10
MeiliSearch_ is aimed at individuals and small companies. It is designed for
11
small-scale (less than 10 million documents) data collections. E.g. it is great
12
for storing web pages you have visited and searching in the contents later.
13
14
The engine supports faceted search, so you can search in a subset of documents
15
of the collection. Furthermore, you can search in MeiliSearch_ instances that
16
require authentication by setting ``auth_token``.
17
18
Example
19
=======
20
21
Here is a simple example to query a Meilisearch instance:
22
23
.. code:: yaml
24
25
- name: meilisearch
26
engine: meilisearch
27
shortcut: mes
28
base_url: http://localhost:7700
29
index: my-index
30
enable_http: true
31
32
"""
33
34
# pylint: disable=global-statement
35
36
from
json
import
loads, dumps
37
38
39
base_url =
'http://localhost:7700'
40
index =
''
41
auth_key =
''
42
facet_filters = []
43
_search_url =
''
44
result_template =
'key-value.html'
45
categories = [
'general'
]
46
paging =
True
47
48
49
def
init
(_):
50
if
index ==
''
:
51
raise
ValueError(
'index cannot be empty'
)
52
53
global
_search_url
54
_search_url = base_url +
'/indexes/'
+ index +
'/search'
55
56
57
def
request
(query, params):
58
if
auth_key !=
''
:
59
params[
'headers'
][
'X-Meili-API-Key'
] = auth_key
60
61
params[
'headers'
][
'Content-Type'
] =
'application/json'
62
params[
'url'
] = _search_url
63
params[
'method'
] =
'POST'
64
65
data = {
66
'q'
: query,
67
'offset'
: 10 * (params[
'pageno'
] - 1),
68
'limit'
: 10,
69
}
70
if
len(facet_filters) > 0:
71
data[
'facetFilters'
] = facet_filters
72
73
params[
'data'
] = dumps(data)
74
75
return
params
76
77
78
def
response
(resp):
79
results = []
80
81
resp_json = loads(resp.text)
82
for
result
in
resp_json[
'hits'
]:
83
r = {key: str(value)
for
key, value
in
result.items()}
84
r[
'template'
] = result_template
85
results.append(r)
86
87
return
results
searx.engines.meilisearch.request
request(query, params)
Definition
meilisearch.py:57
searx.engines.meilisearch.init
init(_)
Definition
meilisearch.py:49
searx.engines.meilisearch.response
response(resp)
Definition
meilisearch.py:78
searxng
searx
engines
meilisearch.py
Generated on Sat Nov 16 2024 00:10:57 for .oO SearXNG Developer Documentation Oo. by
1.12.0