Opened 8 years ago

Closed 5 years ago

#28194 closed New feature (fixed)

Add search rank cd function and normalization for Postgres full text search

Reported by: Andrii Soldatenko Owned by: Hannes Ljungberg
Component: contrib.postgres Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

It would be great to have cover density ranking for the given document vector and query function ts_rank_cd. It helps to order search results with different normalization strategies.

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')

Change History (6)

comment:1 by Andrii Soldatenko, 8 years ago

Component: Uncategorizedcontrib.postgres
Type: UncategorizedNew feature

comment:2 by Tim Graham, 8 years ago

Triage Stage: UnreviewedAccepted

comment:3 by Andrii Soldatenko, 8 years ago

Owner: changed from nobody to Andrii Soldatenko
Status: newassigned

comment:4 by Simon Charette, 5 years ago

Has patch: set
Owner: changed from Andrii Soldatenko to Hannes Ljungberg
Patch needs improvement: set

comment:5 by Mariusz Felisiak, 5 years ago

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin
Version: 1.11master

comment:6 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

Resolution: fixed
Status: assignedclosed

In 0b51a4f:

Fixed #28194 -- Added support for normalization and cover density to SearchRank.

Note: See TracTickets for help on using tickets.
Back to Top