Skip to content

Commit a285f4d

Browse files
committed
Add search tests: empty string and empty query (placeholder search)
1 parent c2585f3 commit a285f4d

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

meilisearch/tests/index/test_index_search_meilisearch.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@ def test_basic_search_with_empty_params(self):
4141
assert response['hits'][0]['id'] == '166428'
4242
assert '_formatted' not in response['hits'][0]
4343

44+
def test_basic_search_with_empty_query(self):
45+
"""Tests search with empty query and empty params"""
46+
response = self.index.search('', {})
47+
assert isinstance(response, object)
48+
assert len(response['hits']) == 0
49+
assert response['query'] == ''
50+
51+
def test_basic_search_with_placeholder(self):
52+
"""Tests search with no query [None] and empty params"""
53+
response = self.index.search(None, {})
54+
assert isinstance(response, object)
55+
assert len(response['hits']) == 20
56+
4457
def test_custom_search(self):
4558
"""Tests search with an simple query and custom parameter (attributesToHighlight)"""
4659
response = self.index.search(
@@ -54,6 +67,29 @@ def test_custom_search(self):
5467
assert '_formatted' in response['hits'][0]
5568
assert 'dragon' in response['hits'][0]['_formatted']['title'].lower()
5669

70+
def test_custom_search_with_empty_query(self):
71+
"""Tests search with empty query and custom parameter (attributesToHighlight)"""
72+
response = self.index.search(
73+
'',
74+
{
75+
'attributesToHighlight': ['title']
76+
}
77+
)
78+
assert isinstance(response, object)
79+
assert len(response['hits']) == 0
80+
assert response['query'] == ''
81+
82+
def test_custom_search_with_placeholder(self):
83+
"""Tests search with no query [None] and custom parameter (limit)"""
84+
response = self.index.search(
85+
None,
86+
{
87+
'limit': 5
88+
}
89+
)
90+
assert isinstance(response, object)
91+
assert len(response['hits']) == 5
92+
5793
def test_custom_search_params_with_wildcard(self):
5894
"""Tests search with '*' in query params"""
5995
response = self.index.search(

0 commit comments

Comments
 (0)