Also add `normalization` parameter option that specifies whether and how a
document's length should impact its rank.
>0 (the default) ignores the document length
>1 divides the rank by 1 + the logarithm of the document length
>2 divides the rank by the document length
>4 divides the rank by the mean harmonic distance between extents (this is
implemented only by ts_rank_cd)
>8 divides the rank by the number of unique words in document
>16 divides the rank by 1 + the logarithm of the number of unique words in
document
>32 divides the rank by itself + 1
Now you can do something like this:
{{{
class SearchRankCD(SearchRank):
function = 'ts_rank_cd'
def __init__(self, vector, query, normalization=0, **extra):
super(SearchRank, self).__init__(
vector, query, normalization, **extra)
query = SearchQuery('messenger')
Application.objects.annotate(
rank=SearchRankCD(
F('search_vector_title'), query,
normalization=2) # 2 divides the rank by the document length
).filter(search_vector_title=query).order_by('-rank')
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28194>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* type: Uncategorized => New feature
* component: Uncategorized => contrib.postgres
--
Ticket URL: <https://code.djangoproject.com/ticket/28194#comment:1>
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/28194#comment:2>
* status: new => assigned
* owner: nobody => Andrii Soldatenko
--
Ticket URL: <https://code.djangoproject.com/ticket/28194#comment:3>
* owner: Andrii Soldatenko => Hannes Ljungberg
* needs_better_patch: 0 => 1
* has_patch: 0 => 1
Comment:
https://github.com/django/django/pull/12597
--
Ticket URL: <https://code.djangoproject.com/ticket/28194#comment:4>
* needs_better_patch: 1 => 0
* version: 1.11 => master
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/28194#comment:5>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"0b51a4f8946178daf469bec4cbedbc02a23cf814" 0b51a4f]:
{{{
#!CommitTicketReference repository=""
revision="0b51a4f8946178daf469bec4cbedbc02a23cf814"
Fixed #28194 -- Added support for normalization and cover density to
SearchRank.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28194#comment:6>