mirror of
https://github.com/django/django.git
synced 2025-08-30 07:17:49 +00:00
Fixed #27143 -- Allowed combining SearchQuery with more than one & or | operators.
This commit is contained in:
parent
40d5011471
commit
978a00e39f
3 changed files with 74 additions and 19 deletions
|
@ -205,14 +205,46 @@ class TestCombinations(GrailTestData, PostgreSQLTestCase):
|
|||
).filter(search=SearchQuery('bedemir') & SearchQuery('scales'))
|
||||
self.assertSequenceEqual(searched, [self.bedemir0])
|
||||
|
||||
def test_query_multiple_and(self):
|
||||
searched = Line.objects.annotate(
|
||||
search=SearchVector('scene__setting', 'dialogue'),
|
||||
).filter(search=SearchQuery('bedemir') & SearchQuery('scales') & SearchQuery('nostrils'))
|
||||
self.assertSequenceEqual(searched, [])
|
||||
|
||||
searched = Line.objects.annotate(
|
||||
search=SearchVector('scene__setting', 'dialogue'),
|
||||
).filter(search=SearchQuery('shall') & SearchQuery('use') & SearchQuery('larger'))
|
||||
self.assertSequenceEqual(searched, [self.bedemir0])
|
||||
|
||||
def test_query_or(self):
|
||||
searched = Line.objects.filter(dialogue__search=SearchQuery('kneecaps') | SearchQuery('nostrils'))
|
||||
self.assertSequenceEqual(set(searched), {self.verse1, self.verse2})
|
||||
|
||||
def test_query_multiple_or(self):
|
||||
searched = Line.objects.filter(
|
||||
dialogue__search=SearchQuery('kneecaps') | SearchQuery('nostrils') | SearchQuery('Sir Robin')
|
||||
)
|
||||
self.assertSequenceEqual(set(searched), {self.verse1, self.verse2, self.verse0})
|
||||
|
||||
def test_query_invert(self):
|
||||
searched = Line.objects.filter(character=self.minstrel, dialogue__search=~SearchQuery('kneecaps'))
|
||||
self.assertEqual(set(searched), {self.verse0, self.verse2})
|
||||
|
||||
def test_query_config_mismatch(self):
|
||||
with self.assertRaisesMessage(TypeError, "SearchQuery configs don't match."):
|
||||
Line.objects.filter(
|
||||
dialogue__search=SearchQuery('kneecaps', config='german') |
|
||||
SearchQuery('nostrils', config='english')
|
||||
)
|
||||
|
||||
def test_query_combined_mismatch(self):
|
||||
msg = "SearchQuery can only be combined with other SearchQuerys, got"
|
||||
with self.assertRaisesMessage(TypeError, msg):
|
||||
Line.objects.filter(dialogue__search=None | SearchQuery('kneecaps'))
|
||||
|
||||
with self.assertRaisesMessage(TypeError, msg):
|
||||
Line.objects.filter(dialogue__search=None & SearchQuery('kneecaps'))
|
||||
|
||||
|
||||
@modify_settings(INSTALLED_APPS={'append': 'django.contrib.postgres'})
|
||||
class TestRankingAndWeights(GrailTestData, PostgreSQLTestCase):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue