Fix #11600 Eleasticsearch7 empty admin search gives 500 (#11626)

pull/11651/head
Maikel Martens 2024-02-09 15:43:10 +01:00 zatwierdzone przez Matt Westcott
rodzic d93588fb5b
commit ef06e48c7f
5 zmienionych plików z 37 dodań i 2 usunięć

Wyświetl plik

@ -33,6 +33,7 @@ Changelog
* Fix: Ensure `BooleanRadioSelect` uses the same styles as `RadioSelect` (Thibaud Colas)
* Fix: Prevent failure on `collectstatic` when `ManifestStaticFilesStorage` is in use (Matt Westcott)
* Fix: Prevent error on submitting an empty search in the admin under Elasticsearch (Maikel Martens)
6.0 (07.02.2024)

Wyświetl plik

@ -799,6 +799,7 @@
* Andre Delorme
* arshyia3000
* Adrien Hamraoui
* Maikel Martens
## Translators

Wyświetl plik

@ -15,3 +15,4 @@ depth: 1
* Ensure `BooleanRadioSelect` uses the same styles as `RadioSelect` (Thibaud Colas)
* Prevent failure on `collectstatic` when `ManifestStaticFilesStorage` is in use (Matt Westcott)
* Prevent error on submitting an empty search in the admin under Elasticsearch (Maikel Martens)

Wyświetl plik

@ -1026,8 +1026,15 @@ class ElasticsearchAutocompleteQueryCompilerImpl:
if len(fields) == 0:
# No fields. Return a query that'll match nothing
return {"bool": {"mustNot": {"match_all": {}}}}
return self._compile_plaintext_query(self.query, fields)
elif isinstance(self.query, PlainText):
return self._compile_plaintext_query(self.query, fields)
elif isinstance(self.query, MatchAll):
return {"match_all": {}}
else:
raise NotImplementedError(
"`%s` is not supported for autocomplete queries."
% self.query.__class__.__name__
)
class Elasticsearch7AutocompleteQueryCompiler(

Wyświetl plik

@ -96,6 +96,31 @@ class TestElasticsearch7SearchQuery(TestCase):
}
self.assertDictEqual(query.get_query(), expected_result)
def test_match_all_autocomplete(self):
# Create a query
query = self.autocomplete_query_compiler_class(
models.Book.objects.all(), MATCH_ALL
)
# Check it
expected_result = {
"bool": {
"filter": {"match": {"content_type": "searchtests.Book"}},
"must": {"match_all": {}},
}
}
self.assertDictEqual(query.get_query(), expected_result)
def test_non_supported_queries_autocomplete(self):
# Create a query
query = self.autocomplete_query_compiler_class(
models.Book.objects.all(), Fuzzy("Hello")
)
# Check it
with self.assertRaises(NotImplementedError):
query.get_query()
def test_none_query_string(self):
# Create a query
query = self.query_compiler_class(models.Book.objects.all(), MATCH_ALL)