From: Bruce Momjian <bruce@momjian.us>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: 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 19:34:42 -0400
Message-ID: <ZT2akojpqo9rLiV_@momjian.us> (raw)
In-Reply-To: <1995601.1698526000@sss.pgh.pa.us>
References: <152461454026.19805.6310947081647212894@wrigleys.postgresql.org>
<CAGH8cccS-9yb1VkgUTAaghz4P3aL8DneH_24bN7Y0LCLO8by1Q@mail.gmail.com>
<ZT1kGIbiALGclTUA@momjian.us>
<1995601.1698526000@sss.pgh.pa.us>
On Sat, Oct 28, 2023 at 04:46:40PM -0400, Tom Lane wrote:
> Bruce Momjian <bruce@momjian.us> writes:
> > Is this documented somewhere?
>
> The docs [1] only say that ts_headline "returns an excerpt from the
> document in which terms from the query are highlighted". This
> behavior does not violate that admittedly-weak contract.
>
> IIRC, ts_headline does attempt to find a text fragment or fragments
> that fully satisfy the query (e.g., include an exact phrase match)
> but it will then highlight all the matching words in the fragment,
> not only the location of the phrase match. I do not agree with the
I see what you mean in this query output:
SELECT ts_headline('English','kj asdlkjf alds jflkasjd flkaj dsflkja sdlfk jaslfd kjasdlfkj salfdkj This Commercial Bank does not have any Equity in Europe but European Commercial Bank does lkj sadlkjf asldkjf alskjd flsakj fdlkaj dfaslkfd jlakds jaslkfdj',
('''european'' <-> ''commerci'' <-> ''bank''')::tsquery);
ts_headline
---------------------------------------------------------------------------------------------------------------------------------
Europe but <b>European</b> <b>Commercial</b> <b>Bank</b> does lkj sadlkjf asldkjf alskjd flsakj fdlkaj dfaslkfd jlakds jaslkfdj
The query controls the fragment chosen.
> OP's opinion that that's wrong. The highlight-em-all approach has its
> own value, and in any case it may not be possible to find a full match
> that satisfies the function's other constraints such as MaxWords.
> Refusing to highlight anything in that event would be unhelpful.
Attached is a proposed doc patch.
I hope people don't mind me addressing these old emails but I think
they address important issues, and while I wasn't able to deal with them
when they are posted, I have time for the next month to do so.
--
Bruce Momjian <bruce@momjian.us> https://momjian.us
EDB https://enterprisedb.com
Only you can decide what is important to you.
Attachments:headline.diff (text/x-diff, 922B) downloaddiff --git a/doc/src/sgml/textsearch.sgml b/doc/src/sgml/textsearch.sgmlindex 1550be5695..c607874dbc 100644--- a/doc/src/sgml/textsearch.sgml+++ b/doc/src/sgml/textsearch.sgml@@ -1287,7 +1287,10 @@ ts_headline(<optional> <replaceable class="parameter">config</replaceable> <type
<para>
<function>ts_headline</function> accepts a document along
with a query, and returns an excerpt from
- the document in which terms from the query are highlighted. The+ the document in which terms from the query are highlighted.+ Specifically, the function will return text fragments that satisfy+ the query, and highlight all words that appear in the query, even if+ those words do not match the query operator restrictions. The
configuration to be used to parse the document can be specified by
<replaceable>config</replaceable>; if <replaceable>config</replaceable>
is omitted, the
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, tgl@sss.pgh.pa.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: <ZT2akojpqo9rLiV_@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