.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_key`_.
17
18
.. _auth_key: https://www.meilisearch.com/docs/reference/api/overview#authorization
19
20
Example
21
=======
22
23
Here 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
39
from
json
import
dumps
40
from
searx.result_types
import
EngineResults
41
from
searx.extended_types
import
SXNG_Response
42
43
base_url =
'http://localhost:7700'
44
index =
''
45
auth_key =
''
46
facet_filters = []
47
_search_url =
''
48
categories = [
'general'
]
49
paging =
True
50
51
52
def
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
60
def
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
81
def
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
searx.result_types.EngineResults
Definition
__init__.py:51
searx.engines.meilisearch.request
request(query, params)
Definition
meilisearch.py:60
searx.engines.meilisearch.init
init(_)
Definition
meilisearch.py:52
searx.engines.meilisearch.response
EngineResults response(SXNG_Response resp)
Definition
meilisearch.py:81
searx.extended_types
Definition
extended_types.py:1
searx.result_types
Definition
__init__.py:1
searxng
searx
engines
meilisearch.py
Generated on Thu Apr 24 2025 22:38:20 for .oO SearXNG Developer Documentation Oo. by
1.13.2