|
@@ -27,6 +27,9 @@ class TestElasticsearch5SearchQuery(TestCase):
|
|
|
)
|
|
|
|
|
|
query_compiler_class = Elasticsearch5SearchBackend.query_compiler_class
|
|
|
+ autocomplete_query_compiler_class = (
|
|
|
+ Elasticsearch5SearchBackend.autocomplete_query_compiler_class
|
|
|
+ )
|
|
|
|
|
|
def test_simple(self):
|
|
|
# Create a query
|
|
@@ -36,9 +39,22 @@ class TestElasticsearch5SearchQuery(TestCase):
|
|
|
expected_result = {
|
|
|
"bool": {
|
|
|
"filter": {"match": {"content_type": "searchtests.Book"}},
|
|
|
- "must": {
|
|
|
- "multi_match": {"query": "Hello", "fields": ["_all", "_partials"]}
|
|
|
- },
|
|
|
+ "must": {"match": {"_all": {"query": "Hello"}}},
|
|
|
+ }
|
|
|
+ }
|
|
|
+ self.assertDictEqual(query_compiler.get_query(), expected_result)
|
|
|
+
|
|
|
+ def test_simple_autocomplete(self):
|
|
|
+ # Create a query
|
|
|
+ query_compiler = self.autocomplete_query_compiler_class(
|
|
|
+ models.Book.objects.all(), "Hello"
|
|
|
+ )
|
|
|
+
|
|
|
+ # Check it
|
|
|
+ expected_result = {
|
|
|
+ "bool": {
|
|
|
+ "filter": {"match": {"content_type": "searchtests.Book"}},
|
|
|
+ "must": {"match": {"_partials": {"query": "Hello"}}},
|
|
|
}
|
|
|
}
|
|
|
self.assertDictEqual(query_compiler.get_query(), expected_result)
|
|
@@ -67,10 +83,11 @@ class TestElasticsearch5SearchQuery(TestCase):
|
|
|
"bool": {
|
|
|
"filter": {"match": {"content_type": "searchtests.Book"}},
|
|
|
"must": {
|
|
|
- "multi_match": {
|
|
|
- "query": "Hello",
|
|
|
- "fields": ["_all", "_partials"],
|
|
|
- "operator": "and",
|
|
|
+ "match": {
|
|
|
+ "_all": {
|
|
|
+ "query": "Hello",
|
|
|
+ "operator": "and",
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
}
|
|
@@ -90,9 +107,7 @@ class TestElasticsearch5SearchQuery(TestCase):
|
|
|
{"match": {"content_type": "searchtests.Book"}},
|
|
|
{"term": {"title_filter": "Test"}},
|
|
|
],
|
|
|
- "must": {
|
|
|
- "multi_match": {"query": "Hello", "fields": ["_all", "_partials"]}
|
|
|
- },
|
|
|
+ "must": {"match": {"_all": {"query": "Hello"}}},
|
|
|
}
|
|
|
}
|
|
|
self.assertDictEqual(query_compiler.get_query(), expected_result)
|
|
@@ -120,9 +135,7 @@ class TestElasticsearch5SearchQuery(TestCase):
|
|
|
}
|
|
|
},
|
|
|
],
|
|
|
- "must": {
|
|
|
- "multi_match": {"query": "Hello", "fields": ["_all", "_partials"]}
|
|
|
- },
|
|
|
+ "must": {"match": {"_all": {"query": "Hello"}}},
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -165,9 +178,7 @@ class TestElasticsearch5SearchQuery(TestCase):
|
|
|
}
|
|
|
},
|
|
|
],
|
|
|
- "must": {
|
|
|
- "multi_match": {"query": "Hello", "fields": ["_all", "_partials"]}
|
|
|
- },
|
|
|
+ "must": {"match": {"_all": {"query": "Hello"}}},
|
|
|
}
|
|
|
}
|
|
|
self.assertDictEqual(query, expected_result)
|
|
@@ -192,9 +203,7 @@ class TestElasticsearch5SearchQuery(TestCase):
|
|
|
}
|
|
|
},
|
|
|
],
|
|
|
- "must": {
|
|
|
- "multi_match": {"query": "Hello", "fields": ["_all", "_partials"]}
|
|
|
- },
|
|
|
+ "must": {"match": {"_all": {"query": "Hello"}}},
|
|
|
}
|
|
|
}
|
|
|
self.assertDictEqual(query_compiler.get_query(), expected_result)
|
|
@@ -283,9 +292,7 @@ class TestElasticsearch5SearchQuery(TestCase):
|
|
|
{"match": {"content_type": "searchtests.Book"}},
|
|
|
{"term": {"title_filter": "Test"}},
|
|
|
],
|
|
|
- "must": {
|
|
|
- "multi_match": {"query": "Hello", "fields": ["_all", "_partials"]}
|
|
|
- },
|
|
|
+ "must": {"match": {"_all": {"query": "Hello"}}},
|
|
|
}
|
|
|
}
|
|
|
self.assertDictEqual(query_compiler.get_query(), expected_result)
|
|
@@ -303,9 +310,7 @@ class TestElasticsearch5SearchQuery(TestCase):
|
|
|
{"match": {"content_type": "searchtests.Book"}},
|
|
|
{"bool": {"mustNot": {"exists": {"field": "title_filter"}}}},
|
|
|
],
|
|
|
- "must": {
|
|
|
- "multi_match": {"query": "Hello", "fields": ["_all", "_partials"]}
|
|
|
- },
|
|
|
+ "must": {"match": {"_all": {"query": "Hello"}}},
|
|
|
}
|
|
|
}
|
|
|
self.assertDictEqual(query_compiler.get_query(), expected_result)
|
|
@@ -323,9 +328,7 @@ class TestElasticsearch5SearchQuery(TestCase):
|
|
|
{"match": {"content_type": "searchtests.Book"}},
|
|
|
{"bool": {"mustNot": {"exists": {"field": "title_filter"}}}},
|
|
|
],
|
|
|
- "must": {
|
|
|
- "multi_match": {"query": "Hello", "fields": ["_all", "_partials"]}
|
|
|
- },
|
|
|
+ "must": {"match": {"_all": {"query": "Hello"}}},
|
|
|
}
|
|
|
}
|
|
|
self.assertDictEqual(query_compiler.get_query(), expected_result)
|
|
@@ -343,9 +346,7 @@ class TestElasticsearch5SearchQuery(TestCase):
|
|
|
{"match": {"content_type": "searchtests.Book"}},
|
|
|
{"exists": {"field": "title_filter"}},
|
|
|
],
|
|
|
- "must": {
|
|
|
- "multi_match": {"query": "Hello", "fields": ["_all", "_partials"]}
|
|
|
- },
|
|
|
+ "must": {"match": {"_all": {"query": "Hello"}}},
|
|
|
}
|
|
|
}
|
|
|
self.assertDictEqual(query_compiler.get_query(), expected_result)
|
|
@@ -363,9 +364,7 @@ class TestElasticsearch5SearchQuery(TestCase):
|
|
|
{"match": {"content_type": "searchtests.Book"}},
|
|
|
{"prefix": {"title_filter": "Test"}},
|
|
|
],
|
|
|
- "must": {
|
|
|
- "multi_match": {"query": "Hello", "fields": ["_all", "_partials"]}
|
|
|
- },
|
|
|
+ "must": {"match": {"_all": {"query": "Hello"}}},
|
|
|
}
|
|
|
}
|
|
|
self.assertDictEqual(query_compiler.get_query(), expected_result)
|
|
@@ -388,9 +387,7 @@ class TestElasticsearch5SearchQuery(TestCase):
|
|
|
{"match": {"content_type": "searchtests.Book"}},
|
|
|
{"range": {"publication_date_filter": {"gt": "2014-04-29"}}},
|
|
|
],
|
|
|
- "must": {
|
|
|
- "multi_match": {"query": "Hello", "fields": ["_all", "_partials"]}
|
|
|
- },
|
|
|
+ "must": {"match": {"_all": {"query": "Hello"}}},
|
|
|
}
|
|
|
}
|
|
|
self.assertDictEqual(query_compiler.get_query(), expected_result)
|
|
@@ -411,9 +408,7 @@ class TestElasticsearch5SearchQuery(TestCase):
|
|
|
{"match": {"content_type": "searchtests.Book"}},
|
|
|
{"range": {"publication_date_filter": {"lt": "2014-04-29"}}},
|
|
|
],
|
|
|
- "must": {
|
|
|
- "multi_match": {"query": "Hello", "fields": ["_all", "_partials"]}
|
|
|
- },
|
|
|
+ "must": {"match": {"_all": {"query": "Hello"}}},
|
|
|
}
|
|
|
}
|
|
|
self.assertDictEqual(query_compiler.get_query(), expected_result)
|
|
@@ -434,9 +429,7 @@ class TestElasticsearch5SearchQuery(TestCase):
|
|
|
{"match": {"content_type": "searchtests.Book"}},
|
|
|
{"range": {"publication_date_filter": {"gte": "2014-04-29"}}},
|
|
|
],
|
|
|
- "must": {
|
|
|
- "multi_match": {"query": "Hello", "fields": ["_all", "_partials"]}
|
|
|
- },
|
|
|
+ "must": {"match": {"_all": {"query": "Hello"}}},
|
|
|
}
|
|
|
}
|
|
|
self.assertDictEqual(query_compiler.get_query(), expected_result)
|
|
@@ -457,9 +450,7 @@ class TestElasticsearch5SearchQuery(TestCase):
|
|
|
{"match": {"content_type": "searchtests.Book"}},
|
|
|
{"range": {"publication_date_filter": {"lte": "2014-04-29"}}},
|
|
|
],
|
|
|
- "must": {
|
|
|
- "multi_match": {"query": "Hello", "fields": ["_all", "_partials"]}
|
|
|
- },
|
|
|
+ "must": {"match": {"_all": {"query": "Hello"}}},
|
|
|
}
|
|
|
}
|
|
|
self.assertDictEqual(query_compiler.get_query(), expected_result)
|
|
@@ -488,9 +479,7 @@ class TestElasticsearch5SearchQuery(TestCase):
|
|
|
}
|
|
|
},
|
|
|
],
|
|
|
- "must": {
|
|
|
- "multi_match": {"query": "Hello", "fields": ["_all", "_partials"]}
|
|
|
- },
|
|
|
+ "must": {"match": {"_all": {"query": "Hello"}}},
|
|
|
}
|
|
|
}
|
|
|
self.assertDictEqual(query_compiler.get_query(), expected_result)
|
|
@@ -540,10 +529,26 @@ class TestElasticsearch5SearchQuery(TestCase):
|
|
|
models.Book.objects.all(), Phrase("Hello world")
|
|
|
)
|
|
|
|
|
|
+ # Check it
|
|
|
+ expected_result = {
|
|
|
+ "match_phrase": {
|
|
|
+ "_all": "Hello world",
|
|
|
+ }
|
|
|
+ }
|
|
|
+ self.assertDictEqual(query_compiler.get_inner_query(), expected_result)
|
|
|
+
|
|
|
+ def test_phrase_query_multiple_fields(self):
|
|
|
+ # Create a query
|
|
|
+ query_compiler = self.query_compiler_class(
|
|
|
+ models.Book.objects.all(),
|
|
|
+ Phrase("Hello world"),
|
|
|
+ fields=["title", "content"],
|
|
|
+ )
|
|
|
+
|
|
|
# Check it
|
|
|
expected_result = {
|
|
|
"multi_match": {
|
|
|
- "fields": ["_all", "_partials"],
|
|
|
+ "fields": ["title", "content"],
|
|
|
"query": "Hello world",
|
|
|
"type": "phrase",
|
|
|
}
|
|
@@ -602,19 +607,6 @@ class TestElasticsearch5SearchQuery(TestCase):
|
|
|
with self.assertRaises(NotImplementedError):
|
|
|
query_compiler.get_inner_query()
|
|
|
|
|
|
- def test_fuzzy_query_partial_match_disallowed(self):
|
|
|
- # Create a query
|
|
|
- query_compiler = self.query_compiler_class(
|
|
|
- models.Book.objects.all(),
|
|
|
- Fuzzy("Hello world"),
|
|
|
- fields=["_all"],
|
|
|
- partial_match=True,
|
|
|
- )
|
|
|
-
|
|
|
- # Check it
|
|
|
- with self.assertRaises(NotImplementedError):
|
|
|
- query_compiler.get_inner_query()
|
|
|
-
|
|
|
def test_year_filter(self):
|
|
|
# Create a query
|
|
|
query_compiler = self.query_compiler_class(
|
|
@@ -628,9 +620,7 @@ class TestElasticsearch5SearchQuery(TestCase):
|
|
|
{"match": {"content_type": "searchtests.Book"}},
|
|
|
{"range": {"publication_date_filter": {"gt": 1900}}},
|
|
|
],
|
|
|
- "must": {
|
|
|
- "multi_match": {"query": "Hello", "fields": ["_all", "_partials"]}
|
|
|
- },
|
|
|
+ "must": {"match": {"_all": {"query": "Hello"}}},
|
|
|
}
|
|
|
}
|
|
|
self.assertDictEqual(query_compiler.get_query(), expected_result)
|