Fixed #29997 -- Allowed combining SearchQuerys with different configs.

Seems to be a needless restriction in
978a00e39f.
This commit is contained in:
Jaap Roes 2018-11-30 15:42:50 +01:00 committed by Tim Graham
parent 793a71b7be
commit 8a1a919468
2 changed files with 16 additions and 6 deletions

View File

@ -99,8 +99,6 @@ class SearchQueryCombinable:
'SearchQuery can only be combined with other SearchQuerys, ' 'SearchQuery can only be combined with other SearchQuerys, '
'got {}.'.format(type(other)) 'got {}.'.format(type(other))
) )
if not self.config == other.config:
raise TypeError("SearchQuery configs don't match.")
if reversed: if reversed:
return CombinedSearchQuery(other, connector, self, self.config) return CombinedSearchQuery(other, connector, self, self.config)
return CombinedSearchQuery(self, connector, other, self.config) return CombinedSearchQuery(self, connector, other, self.config)

View File

@ -276,12 +276,24 @@ class TestCombinations(GrailTestData, PostgreSQLTestCase):
searched = Line.objects.filter(character=self.minstrel, dialogue__search=~SearchQuery('kneecaps')) searched = Line.objects.filter(character=self.minstrel, dialogue__search=~SearchQuery('kneecaps'))
self.assertCountEqual(searched, [self.verse0, self.verse2]) self.assertCountEqual(searched, [self.verse0, self.verse2])
def test_query_config_mismatch(self): def test_combine_different_configs(self):
with self.assertRaisesMessage(TypeError, "SearchQuery configs don't match."): searched = Line.objects.filter(
Line.objects.filter( dialogue__search=(
dialogue__search=SearchQuery('kneecaps', config='german') | SearchQuery('cadeau', config='french') |
SearchQuery('nostrils', config='english') SearchQuery('nostrils', config='english')
) )
)
self.assertCountEqual(searched, [self.french, self.verse2])
@skipUnlessDBFeature('has_phraseto_tsquery')
def test_combine_raw_phrase(self):
searched = Line.objects.filter(
dialogue__search=(
SearchQuery('burn:*', search_type='raw', config='simple') |
SearchQuery('rode forth from Camelot', search_type='phrase')
)
)
self.assertCountEqual(searched, [self.verse0, self.verse1, self.verse2])
def test_query_combined_mismatch(self): def test_query_combined_mismatch(self):
msg = "SearchQuery can only be combined with other SearchQuerys, got" msg = "SearchQuery can only be combined with other SearchQuerys, got"