Skip to content

Commit 9cd8b4b

Browse files
committed
Implement POST route in search method
1 parent 52b1711 commit 9cd8b4b

File tree

2 files changed

+13
-19
lines changed

2 files changed

+13
-19
lines changed

meilisearch/index.py

+6-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import json
21
import urllib
32
from datetime import datetime
43
from time import sleep
@@ -239,24 +238,19 @@ def search(self, query, opt_params=None):
239238
results: `dict`
240239
Dictionnary with hits, offset, limit, processingTime and initial query
241240
"""
242-
# Query parameters parsing
241+
# Bidy data parsing
243242
if opt_params is None:
244243
opt_params = {}
245-
for key in opt_params:
246-
if key in ('facetsDistribution', 'facetFilters'):
247-
opt_params[key] = json.dumps(opt_params[key])
248-
elif isinstance(opt_params[key], list):
249-
opt_params[key] = ','.join(opt_params[key])
250-
params = {
244+
body = {
251245
'q': query,
252246
**opt_params
253247
}
254-
return self.http.get(
255-
'{}/{}/{}?{}'.format(
248+
return self.http.post(
249+
'{}/{}/{}'.format(
256250
self.config.paths.index,
257251
self.uid,
258-
self.config.paths.search,
259-
urllib.parse.urlencode(params))
252+
self.config.paths.search),
253+
body=body
260254
)
261255

262256
def get_document(self, document_id):

meilisearch/tests/index/test_index_search_meilisearch.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def test_custom_search(self):
4646
response = self.index.search(
4747
'Dragon',
4848
{
49-
'attributesToHighlight': 'title'
49+
'attributesToHighlight': ['title']
5050
}
5151
)
5252
assert isinstance(response, object)
@@ -60,9 +60,9 @@ def test_custom_search_params_with_wildcard(self):
6060
'a',
6161
{
6262
'limit': 5,
63-
'attributesToHighlight': '*',
64-
'attributesToRetrieve': '*',
65-
'attributesToCrop': '*',
63+
'attributesToHighlight': ['*'],
64+
'attributesToRetrieve': ['*'],
65+
'attributesToCrop': ['*'],
6666
}
6767
)
6868
assert isinstance(response, object)
@@ -76,9 +76,9 @@ def test_custom_search_params_with_simple_string(self):
7676
'a',
7777
{
7878
'limit': 5,
79-
'attributesToHighlight': 'title',
80-
'attributesToRetrieve': 'title',
81-
'attributesToCrop': 'title',
79+
'attributesToHighlight': ['title'],
80+
'attributesToRetrieve': ['title'],
81+
'attributesToCrop': ['title'],
8282
}
8383
)
8484
assert isinstance(response, object)

0 commit comments

Comments
 (0)