diff options
author | Simon Charette <charette.s@gmail.com> | 2020-02-25 00:08:55 -0500 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-02-26 08:12:45 +0100 |
commit | 1138ca4c5708882621e87129dc28fa91eeabaaec (patch) | |
tree | 2d1790443b3e97a2636faf4e41a1ab0a2e9bb22a /django/contrib/postgres/search.py | |
parent | d0f1c03331718f1b146cf0fd6ffefa19538eebe4 (diff) | |
download | django-1138ca4c5708882621e87129dc28fa91eeabaaec.tar.gz |
Formalized SearchVector and SearchRank signatures.
Diffstat (limited to 'django/contrib/postgres/search.py')
-rw-r--r-- | django/contrib/postgres/search.py | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/django/contrib/postgres/search.py b/django/contrib/postgres/search.py index 19a0ca777c..56b4a28f62 100644 --- a/django/contrib/postgres/search.py +++ b/django/contrib/postgres/search.py @@ -76,13 +76,10 @@ class SearchVector(SearchVectorCombinable, Func): function = 'to_tsvector' arg_joiner = " || ' ' || " output_field = SearchVectorField() - config = None - def __init__(self, *expressions, **extra): - super().__init__(*expressions, **extra) - config = self.extra.get('config', self.config) + def __init__(self, *expressions, config=None, weight=None): + super().__init__(*expressions) self.config = SearchConfig.from_parameter(config) - weight = self.extra.get('weight') if weight is not None and not hasattr(weight, 'resolve_expression'): weight = Value(weight) self.weight = weight @@ -220,25 +217,23 @@ class SearchRank(Func): function = 'ts_rank' output_field = FloatField() - def __init__(self, vector, query, **extra): + def __init__(self, vector, query, weights=None): if not hasattr(vector, 'resolve_expression'): vector = SearchVector(vector) if not hasattr(query, 'resolve_expression'): query = SearchQuery(query) - weights = extra.get('weights') if weights is not None and not hasattr(weights, 'resolve_expression'): weights = Value(weights) self.weights = weights - super().__init__(vector, query, **extra) + super().__init__(vector, query) def as_sql(self, compiler, connection, function=None, template=None): extra_params = [] extra_context = {} - if template is None and self.extra.get('weights'): - if self.weights: - template = '%(function)s(%(weights)s, %(expressions)s)' - weight_sql, extra_params = compiler.compile(self.weights) - extra_context['weights'] = weight_sql + 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 |