Fixed #28528 -- Allowed combining SearchVectors with different configs.

This commit is contained in:
adamb70 2020-02-05 01:51:13 +00:00 committed by Mariusz Felisiak
parent 72b97a5b1e
commit 4c6ab1f2aa
2 changed files with 12 additions and 1 deletions

View File

@ -56,7 +56,7 @@ class SearchVectorCombinable:
ADD = '||'
def _combine(self, other, connector, reversed):
if not isinstance(other, SearchVectorCombinable) or not self.config == other.config:
if not isinstance(other, SearchVectorCombinable):
raise TypeError(
'SearchVector can only be combined with other SearchVector '
'instances, got %s.' % type(other).__name__

View File

@ -297,6 +297,17 @@ class TestCombinations(GrailTestData, PostgreSQLTestCase):
with self.assertRaisesMessage(TypeError, msg):
Line.objects.filter(dialogue__search=None + SearchVector('character__name'))
def test_combine_different_vector_configs(self):
searched = Line.objects.annotate(
search=(
SearchVector('dialogue', config='english') +
SearchVector('dialogue', config='french')
),
).filter(
search=SearchQuery('cadeaux', config='french') | SearchQuery('nostrils')
)
self.assertCountEqual(searched, [self.french, self.verse2])
def test_query_and(self):
searched = Line.objects.annotate(
search=SearchVector('scene__setting', 'dialogue'),