summaryrefslogtreecommitdiff
path: root/django/contrib/postgres/search.py
diff options
context:
space:
mode:
authorHannes Ljungberg <hannes@5monkeys.se>2020-03-20 22:01:26 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-03-23 11:00:55 +0100
commit0b51a4f8946178daf469bec4cbedbc02a23cf814 (patch)
tree11aefd7c5b20687255010004e466a5a5af1bcaae /django/contrib/postgres/search.py
parent4ed534758cb6a11df9f49baddecca5a6cdda9311 (diff)
downloaddjango-0b51a4f8946178daf469bec4cbedbc02a23cf814.tar.gz
Fixed #28194 -- Added support for normalization and cover density to SearchRank.
Diffstat (limited to 'django/contrib/postgres/search.py')
-rw-r--r--django/contrib/postgres/search.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/django/contrib/postgres/search.py b/django/contrib/postgres/search.py
index 2b2ae0c321..f1640d85ba 100644
--- a/django/contrib/postgres/search.py
+++ b/django/contrib/postgres/search.py
@@ -208,7 +208,10 @@ class SearchRank(Func):
function = 'ts_rank'
output_field = FloatField()
- def __init__(self, vector, query, weights=None):
+ def __init__(
+ self, vector, query, weights=None, normalization=None,
+ cover_density=False,
+ ):
if not hasattr(vector, 'resolve_expression'):
vector = SearchVector(vector)
if not hasattr(query, 'resolve_expression'):
@@ -218,6 +221,12 @@ class SearchRank(Func):
if not hasattr(weights, 'resolve_expression'):
weights = Value(weights)
expressions = (weights,) + expressions
+ if normalization is not None:
+ if not hasattr(normalization, 'resolve_expression'):
+ normalization = Value(normalization)
+ expressions += (normalization,)
+ if cover_density:
+ self.function = 'ts_rank_cd'
super().__init__(*expressions)