mirror of https://github.com/django/django.git
Simplified handling of weights in SearchRank.
This commit is contained in:
parent
1138ca4c57
commit
5637933268
|
@ -222,23 +222,12 @@ class SearchRank(Func):
|
||||||
vector = SearchVector(vector)
|
vector = SearchVector(vector)
|
||||||
if not hasattr(query, 'resolve_expression'):
|
if not hasattr(query, 'resolve_expression'):
|
||||||
query = SearchQuery(query)
|
query = SearchQuery(query)
|
||||||
if weights is not None and not hasattr(weights, 'resolve_expression'):
|
expressions = (vector, query)
|
||||||
weights = Value(weights)
|
if weights is not None:
|
||||||
self.weights = weights
|
if not hasattr(weights, 'resolve_expression'):
|
||||||
super().__init__(vector, query)
|
weights = Value(weights)
|
||||||
|
expressions = (weights,) + expressions
|
||||||
def as_sql(self, compiler, connection, function=None, template=None):
|
super().__init__(*expressions)
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
SearchVectorField.register_lookup(SearchVectorExact)
|
SearchVectorField.register_lookup(SearchVectorExact)
|
||||||
|
|
Loading…
Reference in New Issue