Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qwpCW-00EUfF-Tc for pgsql-bugs@arkaria.postgresql.org; Sat, 28 Oct 2023 19:42:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qwpCV-005QGq-2H for pgsql-bugs@arkaria.postgresql.org; Sat, 28 Oct 2023 19:42:27 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qwpCU-005QGi-H7 for pgsql-bugs@lists.postgresql.org; Sat, 28 Oct 2023 19:42:26 +0000 Received: from momjian.us ([72.94.173.45]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qwpCN-002m4q-6h for pgsql-bugs@lists.postgresql.org; Sat, 28 Oct 2023 19:42:25 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=momjian.us; s=2023062407; h=In-Reply-To:Content-Transfer-Encoding:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-ID:Content-Description; bh=O9q9coC2CDw0D8LrRpbH+eMM07NdomNzusSGGaw+IZU=; b=GP7CkhtzmGcXLLOsNQwqiw5IHD urevSuZ4UbSMnVBC98DWf2qKgNi8iXQPH3rDWk8HomuLkipHJlZPOGnpJaG1oMvU43VdsB0aMknsx M/wRT0dZBH/4IQWtQIzIpB2NGftPQgYs9yxghi50y0zhJEPelOveFtlr/JKUgrXBvE0WbZ4TbCgFa 96sqfewrhf9zMcQtS+xCMdyZ0StOk9yZnzjFQa3+gh0Z5e7Hx+iYQo4TXz8TE7x8xOFwojTPMYhhF AMS1cRQQGzYyfc32lPPGUg5sKjmEXk2NDZFOBV18vgr0NF8YXmz4CK/xFPnn+So+UtK76qGyY7wSL 6Y5VHEZA==; Received: from bruce by momjian.us with local (Exim 4.96) (envelope-from ) id 1qwpCK-0094kc-2m; Sat, 28 Oct 2023 15:42:16 -0400 Date: Sat, 28 Oct 2023 15:42:16 -0400 From: Bruce Momjian To: Alex Malek Cc: pgsql-bugs@lists.postgresql.org, ngigi@at.co.ke Subject: Re: BUG #15172: Postgresql ts_headline with <-> operator does not highlight text properly Message-ID: References: <152461454026.19805.6310947081647212894@wrigleys.postgresql.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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 > 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 Commercial Bank does not have any Equity in Europe but > European Commercial Bank 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 European > Commercial Bank 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 Bank does not have any Equity in Europebut European Commercial Bank 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 Bank does not have any Equity in Europe but European Commercial Bank does Is this documented somewhere? -- Bruce Momjian https://momjian.us EDB https://enterprisedb.com Only you can decide what is important to you.