pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: dominik.giger@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #16235: ts_rank ignores match and only considers lower weighted vector
Date: Mon, 27 Jan 2020 17:34:58 -0500
Message-ID: <23961.1580164498@sss.pgh.pa.us> (raw)
In-Reply-To: <16235-2dad73572326cfab@postgresql.org>
References: <16235-2dad73572326cfab@postgresql.org>

PG Bug reporting form <noreply@postgresql.org> writes:
> The following query shows the problem:

> select ts_rank(doc1, query) as rank_wrong, ts_rank(doc2, query) as
> rank_correct
> from (select setweight(to_tsvector('simple', 'foo something'), 'A') ||
>              setweight(to_tsvector('simple', 'foobar'), 'C')    as doc1,
>              setweight(to_tsvector('simple', 'foo something'), 'A') as
> doc2,
>              to_tsquery('simple', 'foo:* & something')               as
> query) as subquery;

> ts_rank on doc1 is only half of the rank of doc2. ts_rank seems to only
> consider the 'foobar' term with lower weight when calculating the rank. The
> foo:1A is only considered in doc2.

No, that's not correct.  What it actually is doing is taking some sort of
average of the weights of the occurrences, as you can see if you play
around with a few more examples besides these two.  That could be better
documented, perhaps, but I don't think it's obviously broken.

I can see that there might be a use for taking the max or even the sum
of the weights rather than an average --- in many situations it wouldn't
be desirable to rank doc1 of your example lower than doc2.  But really
that'd be a different ranking algorithm, not a bug fix for this one.

The manual claims you can write your own ranking algorithm ... but
AFAICS you'd have to code it in C, because we aren't exposing anything
at SQL level that would let you get at the raw match data :-(.
So there's room for improvement there.

Also, you might try using ts_rank_cd() instead, as that uses a different
algorithm for combining the weights.  At least on this example, doc1
gets a higher score than doc2.

			regards, tom lane





view thread (3+ messages)  latest in thread

Message-ID: <23961.1580164498@sss.pgh.pa.us>
Permalink:  ../23961.1580164498@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/23961.1580164498@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, dominik.giger@gmail.com
  Subject: Re: BUG #16235: ts_rank ignores match and only considers lower weighted vector
  In-Reply-To: <23961.1580164498@sss.pgh.pa.us>
  References: <16235-2dad73572326cfab@postgresql.org> <23961.1580164498@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox