pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bruce Momjian <bruce@momjian.us>
To: Alex Malek <magicagent@gmail.com>
Cc: pgsql-bugs@lists.postgresql.org
Cc: ngigi@at.co.ke
Subject: Re: BUG #15172: Postgresql ts_headline with <-> operator does not highlight text properly
Date: Sat, 28 Oct 2023 15:42:16 -0400
Message-ID: <ZT1kGIbiALGclTUA@momjian.us> (raw)
In-Reply-To: <CAGH8cccS-9yb1VkgUTAaghz4P3aL8DneH_24bN7Y0LCLO8by1Q@mail.gmail.com>
References: <152461454026.19805.6310947081647212894@wrigleys.postgresql.org>
	<CAGH8cccS-9yb1VkgUTAaghz4P3aL8DneH_24bN7Y0LCLO8by1Q@mail.gmail.com>

On Wed, Aug  3, 2022 at 02:02:51PM -0400, Alex Malek wrote:
> On Wed, Aug 3, 2022 at 1:58 PM PG Bug reporting form <noreply@postgresql.org>
> wrote:
>     I have a noticed a likely bug when using ts_headline with the <-> operator
> 
>     Assuming the following query:
> 
>     SELECT ts_headline('English','This Commercial Bank does not have any Equity
>     in Europe but European Commercial Bank does',
>                         phraseto_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
> 
>     Which only highlights *European Commercial Bank* due to the <-> operator in
>     phraseto_tsquery.
> 
>     SELECT phraseto_tsquery('English','European Commercial Bank');
>     returns 'european' <-> 'commerci' <-> 'bank' as expected indicating the
>     problem is with ts_headline function.

I tested this against Postgres 11 and master (and you tested on PG 10
and 14) and I found the same behavior, plus I found someting even
worse:

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

Notice that "Bank" and "Equity" are not next to each other, but they
still highlight.  In fact, the words appear to be independently checked:

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

Is this documented somewhere?

-- 
  Bruce Momjian  <bruce@momjian.us>        https://momjian.us
  EDB                                      https://enterprisedb.com

  Only you can decide what is important to you.





view thread (13+ messages)  latest in thread

Message-ID: <ZT1kGIbiALGclTUA@momjian.us>
Permalink:  ../ZT1kGIbiALGclTUA@momjian.us/
Also on:    postgresql.org/message-id/ZT1kGIbiALGclTUA@momjian.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 using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: bruce@momjian.us, magicagent@gmail.com, pgsql-bugs@lists.postgresql.org, ngigi@at.co.ke
  Subject: Re: BUG #15172: Postgresql ts_headline with <-> operator does not highlight text properly
  In-Reply-To: <ZT1kGIbiALGclTUA@momjian.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