def test_phrase(self): results = self.backend.search(Phrase("rust programming"), models.Book.objects.all()) self.assertSetEqual({r.title for r in results}, {"The Rust Programming Language"}) results = self.backend.search(Phrase("programming rust"), models.Book.objects.all()) self.assertSetEqual({r.title for r in results}, {"Programming Rust"})
def test_phrase(self): results = self.backend.search(Phrase('rust programming'), models.Book.objects.all()) self.assertSetEqual({r.title for r in results}, {'The Rust Programming Language'}) results = self.backend.search(Phrase('programming rust'), models.Book.objects.all()) self.assertSetEqual({r.title for r in results}, {'Programming Rust'})
def test_phrase_query_single_field(self): # Create a query query_compiler = self.query_compiler_class(models.Book.objects.all(), Phrase("Hello world"), fields=['title']) # Check it expected_result = {'match_phrase': {'title': "Hello world"}} self.assertDictEqual(query_compiler.get_inner_query(), expected_result)
def test_phrase_query(self): # Create a query query_compiler = self.query_compiler_class(models.Book.objects.all(), Phrase("Hello world")) # Check it expected_result = {'multi_match': {'fields': ['_all_text', '_edgengrams'], 'query': "Hello world", 'type': 'phrase'}} self.assertDictEqual(query_compiler.get_inner_query(), expected_result)
def test_with_simple_and_phrase(self): filters, query = parse_query_string('this is simple "hello world"') self.assertDictEqual(filters, {}) self.assertEqual( repr(query), repr(And([PlainText("this is simple"), Phrase("hello world")])))
def test_operator(self): filters, query = parse_query_string('this is simple "hello world"', operator='or') self.assertDictEqual(filters, {}) self.assertEqual( repr(query), repr( Or([ PlainText("this is simple", operator='or'), Phrase("hello world") ])))
def test_phrase_query(self): # Create a query query_compiler = self.query_compiler_class(models.Book.objects.all(), Phrase("Hello world")) # Check it expected_result = { "multi_match": { "fields": ["_all", "_partials"], "query": "Hello world", "type": "phrase", } } self.assertDictEqual(query_compiler.get_inner_query(), expected_result)
def test_multiple_phrases(self): filters, query = parse_query_string('"hello world" "hi earth"') self.assertEqual( repr(query), repr(And([Phrase("hello world"), Phrase("hi earth")])))
def test_phrase_with_filter(self): filters, query = parse_query_string( '"hello world" author:"foo bar" bar:beer') self.assertDictEqual(filters, {'author': 'foo bar', 'bar': 'beer'}) self.assertEqual(repr(query), repr(Phrase("hello world")))
def test_with_phrase_unclosed(self): filters, query = parse_query_string('"hello world') self.assertDictEqual(filters, {}) self.assertEqual(repr(query), repr(Phrase("hello world")))