Re: BUG #16744: ts_headline behaves incorrectly with <-> and proximity operators

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Stas Obydionnov <stas(at)hellofyllo(dot)com>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #16744: ts_headline behaves incorrectly with <-> and proximity operators
Date: 2020-11-25 19:40:50
Message-ID: 501699.1606333250@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Stas Obydionnov <stas(at)hellofyllo(dot)com> writes:
> Probably I provided a bad example.
> Here is another one from a similar bug that was opened a couple of years
> ago and was not answered.

> Assuming the following query:

> SELECT ts_headline('English',
> 'This Commercial Bank does not have any Equity in Europe but European
> Commercial Bank does',
> to_tsquery('English','European <-> Commercial <-> Bank')::tsquery);

> The returned result is:
> This <b>Commercial</b> <b>Bank</b> does not have any Equity in Europe but
> <b>European</b> <b>Commercial</b> <b>Bank</b> does

> This highlights the words Commercial & Bank separately in addition
> to European Commercial Bank.

> However, the correct output expected should be:
> This Commercial Bank does not have any Equity in Europe but <b>European</b>
> <b>Commercial</b> <b>Bank</b> does

[ shrug... ] Whether that's more correct than the current behavior
is a matter of opinion. As I said, the ts_headline code highlights
all matching words within whatever fragment it selects. It does
make an effort to locate a fragment that satisfies the query as
written, but that doesn't mean there won't be additional word
matches within the fragment. (In fact, if I'm reading the code
correctly, it actually gives preference to fragments having more
matching words, which is why you don't just get "<b>European</b>
<b>Commercial</b> <b>Bank</b>" here.) I think it's reasonable to
consider that highlighting the additional matches is a useful thing
to do, so I'm disinclined to change this longstanding behavior.

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Zhiyu ZY13 Xu 2020-11-25 20:41:32 pgadmin--pgagent---the process hang by unknow reasons
Previous Message Stas Obydionnov 2020-11-25 19:23:02 Re: BUG #16744: ts_headline behaves incorrectly with <-> and proximity operators