kopia lustrzana https://github.com/wagtail/wagtail
Don't break on blank search queries
rodzic
e4748e45de
commit
88cbfb2875
|
@ -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()
|
||||
|
||||
|
|
|
@ -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."
|
||||
)
|
||||
|
|
Ładowanie…
Reference in New Issue