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 1khctM-0002mb-MH for pgsql-bugs@arkaria.postgresql.org; Tue, 24 Nov 2020 18:18:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1khctL-0006mm-Fg for pgsql-bugs@arkaria.postgresql.org; Tue, 24 Nov 2020 18:18:15 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1khctL-0006me-9G for pgsql-bugs@lists.postgresql.org; Tue, 24 Nov 2020 18:18:15 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1khctJ-0005mg-82 for pgsql-bugs@lists.postgresql.org; Tue, 24 Nov 2020 18:18:14 +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 0AOIIAk3292537; Tue, 24 Nov 2020 13:18:10 -0500 From: Tom Lane To: stas@hellofyllo.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #16744: ts_headline behaves incorrectly with <-> and proximity operators In-reply-to: <16744-861496b4f8f941f2@postgresql.org> References: <16744-861496b4f8f941f2@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Tue, 24 Nov 2020 17:02:40 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <292535.1606241890.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Tue, 24 Nov 2020 13:18:10 -0500 Message-ID: <292536.1606241890@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk PG Bug reporting form writes: > When running the following code > select ts_headline('Alpha Beta Gama', phraseto_tsquery ('alpha gama'= )) > or = > select ts_headline('Alpha Beta Gama', to_tsquery ('alpha <-> gama')) > I would expect the result be not to be highlighted, That's operating as designed, I think. Per the code comment: * If we found nothing acceptable, select min_words words starting= at * the beginning. The expectation really is that it's on you to not select documents that don't match your search query. Once you've selected a document to display, ts_headline() is just going to do the best it can to produce something useful. "Not highlight anything" wasn't deemed particularly useful, and I agree with that judgment. Also, once it's selected a document fragment to display, it will highlight all words within that fragment that appear in the search query, whether or not the particular occurrence is part of the match-if-any. Thus regression=3D# select ts_headline('Alpha Beta Gama foo bar alpha gama', ph= raseto_tsquery ('alpha gama')); ts_headline = ---------------------------------------------------------------- Alpha Beta Gama foo bar alpha gama (1 row) Again, this is a value judgment about what's useful. regards, tom lane