Skip to content

Commit f0695d6

Browse files
eskombrocurquiza
authored andcommitted
Implement POST route in search method (#131)
Implement POST route in search method
1 parent 02fc049 commit f0695d6

File tree

2 files changed

+12
-19
lines changed

2 files changed

+12
-19
lines changed

meilisearch/index.py

+5-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,18 @@ 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
243241
if opt_params is None:
244242
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 = {
243+
body = {
251244
'q': query,
252245
**opt_params
253246
}
254-
return self.http.get(
255-
'{}/{}/{}?{}'.format(
247+
return self.http.post(
248+
'{}/{}/{}'.format(
256249
self.config.paths.index,
257250
self.uid,
258-
self.config.paths.search,
259-
urllib.parse.urlencode(params))
251+
self.config.paths.search),
252+
body=body
260253
)
261254

262255
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)