From 7c8b043a036dd0eab91131800ed104bc17956b22 Mon Sep 17 00:00:00 2001 From: Simon Charette Date: Mon, 24 Feb 2020 23:51:27 -0500 Subject: [PATCH] Refs #31304 -- Made __search lookup default to its rhs' config. This make the SearchLookup lookup more coherent with its SearchVectorExact base which configures its rhs SearchQuery with its lhs' config. --- django/contrib/postgres/lookups.py | 3 ++- tests/postgres_tests/test_search.py | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/django/contrib/postgres/lookups.py b/django/contrib/postgres/lookups.py index cc5bc022c6..37630bc068 100644 --- a/django/contrib/postgres/lookups.py +++ b/django/contrib/postgres/lookups.py @@ -57,7 +57,8 @@ class SearchLookup(SearchVectorExact): def process_lhs(self, qn, connection): if not isinstance(self.lhs.output_field, SearchVectorField): - self.lhs = SearchVector(self.lhs) + config = getattr(self.rhs, 'config', None) + self.lhs = SearchVector(self.lhs, config=config) lhs, lhs_params = super().process_lhs(qn, connection) return lhs, lhs_params diff --git a/tests/postgres_tests/test_search.py b/tests/postgres_tests/test_search.py index 298932ba2e..04adef4f17 100644 --- a/tests/postgres_tests/test_search.py +++ b/tests/postgres_tests/test_search.py @@ -104,6 +104,12 @@ class SimpleSearchTest(GrailTestData, PostgreSQLTestCase): searched = Line.objects.filter(dialogue__search='Robin killed') self.assertSequenceEqual(searched, [self.verse0]) + def test_search_query_config(self): + searched = Line.objects.filter( + dialogue__search=SearchQuery('nostrils', config='simple'), + ) + self.assertSequenceEqual(searched, [self.verse2]) + @modify_settings(INSTALLED_APPS={'append': 'django.contrib.postgres'}) class SearchVectorFieldTest(GrailTestData, PostgreSQLTestCase):