summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2020-02-25 00:12:04 -0500
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-02-26 08:16:22 +0100
commit5637933268af9a7fbf69d162d686a9929903ff47 (patch)
treeb297e60d3db6f213e7d8686265f9c85e4cc2f316
parent1138ca4c5708882621e87129dc28fa91eeabaaec (diff)
Simplified handling of weights in SearchRank.
-rw-r--r--django/contrib/postgres/search.py23
1 files changed, 6 insertions, 17 deletions
diff --git a/django/contrib/postgres/search.py b/django/contrib/postgres/search.py
index 56b4a28f62..484d4315b9 100644
--- a/django/contrib/postgres/search.py
+++ b/django/contrib/postgres/search.py
@@ -222,23 +222,12 @@ class SearchRank(Func):
vector = SearchVector(vector)
if not hasattr(query, 'resolve_expression'):
query = SearchQuery(query)
- if weights is not None and not hasattr(weights, 'resolve_expression'):
- weights = Value(weights)
- self.weights = weights
- super().__init__(vector, query)
-
- def as_sql(self, compiler, connection, function=None, template=None):
- extra_params = []
- extra_context = {}
- if template is None and self.weights:
- template = '%(function)s(%(weights)s, %(expressions)s)'
- weight_sql, extra_params = compiler.compile(self.weights)
- extra_context['weights'] = weight_sql
- sql, params = super().as_sql(
- compiler, connection,
- function=function, template=template, **extra_context
- )
- return sql, extra_params + params
+ expressions = (vector, query)
+ if weights is not None:
+ if not hasattr(weights, 'resolve_expression'):
+ weights = Value(weights)
+ expressions = (weights,) + expressions
+ super().__init__(*expressions)
SearchVectorField.register_lookup(SearchVectorExact)