Skip to content

Fix bug: Search optional params are not applied when they are a list of strings #87

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 2 commits into from
Jun 2, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions meilisearch/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ def search(self, query, opt_params=None):
if opt_params is None:
opt_params = {}
search_param = {'q': query}
for key in opt_params:
if isinstance(opt_params[key], list):
opt_params[key] = ",".join(opt_params[key])
params = {**search_param, **opt_params}
return self.http.get(
'{}/{}/{}?{}'.format(
Expand Down
19 changes: 17 additions & 2 deletions meilisearch/tests/index/test_index_search_meilisearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,20 @@ def test_basic_search_params_with_simple_string(self):
assert "title" in response['hits'][0]['_formatted']
assert not "release_date" in response['hits'][0]['_formatted']

# Add def test_basic_search_params_with_string_list(self):
# when bug (issue #85) is fixed
def test_basic_search_params_with_string_list(self):
"""Tests search with string list in query params"""
response = self.index.search(
'a',
{
'limit': 5,
'attributesToRetrieve': ['title', 'overview'],
"attributesToHighlight": ["title"],
}
)
assert isinstance(response, object)
assert len(response['hits']) == 5
assert "title" in response['hits'][0]
assert "overview" in response['hits'][0]
assert not "release_date" in response['hits'][0]
assert "title" in response['hits'][0]['_formatted']
assert not "overview" in response['hits'][0]['_formatted']