Skip to content

Add search tests: empty string and empty query (placeholder search) #135

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 1 commit into from
Jul 21, 2020
Merged
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
36 changes: 36 additions & 0 deletions meilisearch/tests/index/test_index_search_meilisearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ def test_basic_search_with_empty_params(self):
assert response['hits'][0]['id'] == '166428'
assert '_formatted' not in response['hits'][0]

def test_basic_search_with_empty_query(self):
"""Tests search with empty query and empty params"""
response = self.index.search('')
assert isinstance(response, object)
assert len(response['hits']) == 0
assert response['query'] == ''

def test_basic_search_with_placeholder(self):
"""Tests search with no query [None] and empty params"""
response = self.index.search(None, {})
assert isinstance(response, object)
assert len(response['hits']) == 20

def test_custom_search(self):
"""Tests search with an simple query and custom parameter (attributesToHighlight)"""
response = self.index.search(
Expand All @@ -54,6 +67,29 @@ def test_custom_search(self):
assert '_formatted' in response['hits'][0]
assert 'dragon' in response['hits'][0]['_formatted']['title'].lower()

def test_custom_search_with_empty_query(self):
"""Tests search with empty query and custom parameter (attributesToHighlight)"""
response = self.index.search(
'',
{
'attributesToHighlight': ['title']
}
)
assert isinstance(response, object)
assert len(response['hits']) == 0
assert response['query'] == ''

def test_custom_search_with_placeholder(self):
"""Tests search with no query [None] and custom parameter (limit)"""
response = self.index.search(
None,
{
'limit': 5
}
)
assert isinstance(response, object)
assert len(response['hits']) == 5

def test_custom_search_params_with_wildcard(self):
"""Tests search with '*' in query params"""
response = self.index.search(
Expand Down