Skip to content

Implement POST route in search method #131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions meilisearch/index.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
import urllib
from datetime import datetime
from time import sleep
Expand Down Expand Up @@ -239,24 +238,18 @@ def search(self, query, opt_params=None):
results: `dict`
Dictionnary with hits, offset, limit, processingTime and initial query
"""
# Query parameters parsing
if opt_params is None:
opt_params = {}
for key in opt_params:
if key in ('facetsDistribution', 'facetFilters'):
opt_params[key] = json.dumps(opt_params[key])
elif isinstance(opt_params[key], list):
opt_params[key] = ','.join(opt_params[key])
params = {
body = {
'q': query,
**opt_params
}
return self.http.get(
'{}/{}/{}?{}'.format(
return self.http.post(
'{}/{}/{}'.format(
self.config.paths.index,
self.uid,
self.config.paths.search,
urllib.parse.urlencode(params))
self.config.paths.search),
body=body
)

def get_document(self, document_id):
Expand Down
14 changes: 7 additions & 7 deletions meilisearch/tests/index/test_index_search_meilisearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_custom_search(self):
response = self.index.search(
'Dragon',
{
'attributesToHighlight': 'title'
'attributesToHighlight': ['title']
}
)
assert isinstance(response, object)
Expand All @@ -60,9 +60,9 @@ def test_custom_search_params_with_wildcard(self):
'a',
{
'limit': 5,
'attributesToHighlight': '*',
'attributesToRetrieve': '*',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The simple string "*" is not a valid entry ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't for the post route. Do you think that's a core problem? A simple srting will creat a bad_request response

'attributesToCrop': '*',
'attributesToHighlight': ['*'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum! These kinds of changes are breakable, right?

'attributesToRetrieve': ['*'],
'attributesToCrop': ['*'],
}
)
assert isinstance(response, object)
Expand All @@ -76,9 +76,9 @@ def test_custom_search_params_with_simple_string(self):
'a',
{
'limit': 5,
'attributesToHighlight': 'title',
'attributesToRetrieve': 'title',
'attributesToCrop': 'title',
'attributesToHighlight': ['title'],
'attributesToRetrieve': ['title'],
'attributesToCrop': ['title'],
}
)
assert isinstance(response, object)
Expand Down