Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ki0ey-0000Qv-LP for pgsql-bugs@arkaria.postgresql.org; Wed, 25 Nov 2020 19:41:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ki0ew-00024i-Uh for pgsql-bugs@arkaria.postgresql.org; Wed, 25 Nov 2020 19:40:58 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ki0ew-00024b-Ok for pgsql-bugs@lists.postgresql.org; Wed, 25 Nov 2020 19:40:58 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ki0eq-0007eC-L4 for pgsql-bugs@lists.postgresql.org; Wed, 25 Nov 2020 19:40:57 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 0APJeo4C501700; Wed, 25 Nov 2020 14:40:50 -0500 From: Tom Lane To: Stas Obydionnov cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #16744: ts_headline behaves incorrectly with <-> and proximity operators In-reply-to: References: <16744-861496b4f8f941f2@postgresql.org> <292536.1606241890@sss.pgh.pa.us> Comments: In-reply-to Stas Obydionnov message dated "Wed, 25 Nov 2020 21:23:02 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <501698.1606333250.1@sss.pgh.pa.us> Date: Wed, 25 Nov 2020 14:40:50 -0500 Message-ID: <501699.1606333250@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Stas Obydionnov 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 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 [ 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 "European Commercial Bank" 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