2020 BookSimpleQueryStringSearchFilterBackendDocumentViewSet
2121)
2222from ..filter_backends import SimpleQueryStringSearchFilterBackend
23+ from ..versions import ELASTICSEARCH_GTE_6_0
2324
2425from .base import (
2526 BaseRestFrameworkTestCase ,
@@ -194,15 +195,8 @@ def _search_boost(self, search_term, ordering, url=None):
194195 result_item = filtered_response .data ['results' ][counter ]
195196 self .assertEqual (result_item ['id' ], item_id )
196197
197- def test_search (self , url = None ):
198- """Search by field."""
199- # Search for: Pig and Pepper
200- self ._search (
201- search_term = 'Pig and Pepper' ,
202- num_results = 2 ,
203- url = url
204- )
205-
198+ def test_search_with_quotes (self , url = None ):
199+ """Search with quotes."""
206200 # Search for: "Pig and Pepper"
207201 self ._search (
208202 search_term = '"Pig and Pepper"' ,
@@ -248,21 +242,25 @@ def test_search(self, url=None):
248242 url = url
249243 )
250244
251- def test_search_boost (self , url = None ):
252- """Search boost.
245+ @unittest .skipIf (condition = ELASTICSEARCH_GTE_6_0 , reason = "" )
246+ def test_search_without_quotes (self , url ):
247+ """Test search without quotes. This does not work on Elasticsearch 6.x.
253248
249+ :param url:
254250 :return:
255251 """
256252 # Search for: Pig and Pepper
257- self ._search_boost (
253+ self ._search (
258254 search_term = 'Pig and Pepper' ,
259- ordering = [
260- self .non_lorem [3 ].pk ,
261- self .non_lorem [4 ].pk ,
262- ],
255+ num_results = 2 ,
263256 url = url
264257 )
265258
259+ def test_search_with_quotes_boost (self , url = None ):
260+ """Search boost.
261+
262+ :return:
263+ """
266264 # Search for: "Pig and Pepper"
267265 self ._search_boost (
268266 search_term = '"Pig and Pepper"' ,
@@ -322,7 +320,23 @@ def test_search_boost(self, url=None):
322320 url = url
323321 )
324322
325- def test_search_alternative (self , url = None ):
323+ @unittest .skipIf (condition = ELASTICSEARCH_GTE_6_0 , reason = "" )
324+ def test_search_without_quotes_boost (self , url = None ):
325+ """Search boost without quotes. Does not work on Elasticsearch 6.x.
326+
327+ :return:
328+ """
329+ # Search for: Pig and Pepper
330+ self ._search_boost (
331+ search_term = 'Pig and Pepper' ,
332+ ordering = [
333+ self .non_lorem [3 ].pk ,
334+ self .non_lorem [4 ].pk ,
335+ ],
336+ url = url
337+ )
338+
339+ def test_search_with_quotes_alternative (self , url = None ):
326340 """Test search by field.
327341
328342 :param url:
@@ -332,9 +346,9 @@ def test_search_alternative(self, url=None):
332346 'bookdocument_simple_query_string_boost_search_backend-list' ,
333347 kwargs = {}
334348 )
335- return self .test_search (url )
349+ return self .test_search_with_quotes (url )
336350
337- def test_search_boost_alternative (self , url = None ):
351+ def test_search_with_quotes_boost_alternative (self , url = None ):
338352 """Search boost.
339353
340354 :return:
@@ -343,7 +357,7 @@ def test_search_boost_alternative(self, url=None):
343357 'bookdocument_simple_query_string_boost_search_backend-list' ,
344358 kwargs = {}
345359 )
346- return self .test_search_boost (url )
360+ return self .test_search_with_quotes_boost (url )
347361
348362 def test_search_selected_fields (self , url = None ):
349363 """Search boost.
0 commit comments