@@ -132,3 +132,98 @@ def test_custom_search_params_with_facets_distribution(index_with_documents):
132132 assert response ['facetsDistribution' ]['genre' ]['cartoon' ] == 1
133133 assert response ['facetsDistribution' ]['genre' ]['action' ] == 3
134134 assert response ['facetsDistribution' ]['genre' ]['fantasy' ] == 1
135+
136+ def test_custom_search_params_with_filter_string (index_with_documents ):
137+ index = index_with_documents ()
138+ update = index .update_filterable_attributes (['genre' ])
139+ index .wait_for_pending_update (update ['updateId' ])
140+ response = index .search (
141+ 'world' ,
142+ {
143+ 'filter' : 'genre = action'
144+ }
145+ )
146+ assert isinstance (response , dict )
147+ assert len (response ['hits' ]) == 3
148+ assert 'facetsDistribution' not in response
149+ assert 'exhaustiveFacetsCount' not in response
150+
151+ def test_custom_search_params_with_mutilple_filter_string (index_with_documents ):
152+ index = index_with_documents ()
153+ update = index .update_filterable_attributes (['genre' , 'release_date' ])
154+ index .wait_for_pending_update (update ['updateId' ])
155+ response = index .search (
156+ 'world' ,
157+ {
158+ 'filter' : 'genre = action AND release_date < 1550000000'
159+ }
160+ )
161+ assert isinstance (response , dict )
162+ assert len (response ['hits' ]) == 2
163+ assert 'facetsDistribution' not in response
164+ assert 'exhaustiveFacetsCount' not in response
165+ assert response ['hits' ][0 ]['title' ] == 'Avengers: Infinity War'
166+
167+ def test_custom_search_params_with_filter (index_with_documents ):
168+ index = index_with_documents ()
169+ update = index .update_filterable_attributes (['genre' ])
170+ index .wait_for_pending_update (update ['updateId' ])
171+ response = index .search (
172+ 'world' ,
173+ {
174+ 'filter' : [['genre = action' ]]
175+ }
176+ )
177+ assert isinstance (response , dict )
178+ assert len (response ['hits' ]) == 3
179+ assert 'facetsDistribution' not in response
180+ assert 'exhaustiveFacetsCount' not in response
181+
182+ def test_custom_search_params_with_multiple_filter (index_with_documents ):
183+ index = index_with_documents ()
184+ update = index .update_filterable_attributes (['genre' ])
185+ index .wait_for_pending_update (update ['updateId' ])
186+ response = index .search (
187+ 'world' ,
188+ {
189+ 'filter' : ['genre = action' , ['genre = action' , 'genre = action' ]]
190+ }
191+ )
192+ assert isinstance (response , dict )
193+ assert len (response ['hits' ]) == 3
194+ assert 'facetsDistribution' not in response
195+ assert 'exhaustiveFacetsCount' not in response
196+
197+ def test_custom_search_params_with_many_params (index_with_documents ):
198+ index = index_with_documents ()
199+ update = index .update_filterable_attributes (['genre' ])
200+ index .wait_for_pending_update (update ['updateId' ])
201+ response = index .search (
202+ 'world' ,
203+ {
204+ 'filter' : [['genre = action' ]],
205+ 'attributesToRetrieve' : ['title' , 'poster' ]
206+ }
207+ )
208+ assert isinstance (response , dict )
209+ assert len (response ['hits' ]) == 3
210+ assert 'facetsDistribution' not in response
211+ assert 'exhaustiveFacetsCount' not in response
212+ assert 'title' in response ['hits' ][0 ]
213+ assert 'poster' in response ['hits' ][0 ]
214+ assert 'overview' not in response ['hits' ][0 ]
215+ assert 'release_date' not in response ['hits' ][0 ]
216+ assert response ['hits' ][0 ]['title' ] == 'Avengers: Infinity War'
217+
218+ def test_phrase_search (index_with_documents ):
219+ response = index_with_documents ().search ('coco "dumbo"' )
220+ assert isinstance (response , dict )
221+ assert len (response ['hits' ]) == 1
222+ assert 'facetsDistribution' not in response
223+ assert 'exhaustiveFacetsCount' not in response
224+ assert 'title' in response ['hits' ][0 ]
225+ assert 'poster' in response ['hits' ][0 ]
226+ assert 'overview' in response ['hits' ][0 ]
227+ assert 'release_date' in response ['hits' ][0 ]
228+ assert response ['hits' ][0 ]['title' ] == 'Dumbo'
229+ assert '_formatted' not in response ['hits' ][0 ]
0 commit comments