Don't break on blank search queries

pull/12838/head
Matt Westcott 2025-01-28 17:42:52 +00:00
rodzic e4748e45de
commit 88cbfb2875
2 zmienionych plików z 20 dodań i 1 usunięć

Wyświetl plik

@ -346,7 +346,7 @@ class MySQLSearchQueryCompiler(BaseSearchQueryCompiler):
if isinstance(query, PlainText):
terms = query.query_string.split()
if not terms:
return None
return SearchQuery("")
last_term = terms.pop()

Wyświetl plik

@ -68,6 +68,25 @@ class TestMySQLSearchBackend(BackendTests, TransactionTestCase):
all_other_titles | {"JavaScript: The Definitive Guide"},
)
def test_empty_search(self):
results = self.backend.search("", models.Book.objects.all())
self.assertSetEqual(
{r.title for r in results},
set(),
)
results = self.backend.search(" ", models.Book.objects.all())
self.assertSetEqual(
{r.title for r in results},
set(),
)
results = self.backend.search("*", models.Book.objects.all())
self.assertSetEqual(
{r.title for r in results},
set(),
)
@skip(
"The MySQL backend doesn't support choosing individual fields for the search, only (body, title) or (autocomplete) fields may be searched."
)