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 1qwsqS-00Er1Z-E0 for pgsql-bugs@arkaria.postgresql.org; Sat, 28 Oct 2023 23:35:56 +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 1qwspR-005lll-AG for pgsql-bugs@arkaria.postgresql.org; Sat, 28 Oct 2023 23:34:53 +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 1qwspR-005lk6-0m for pgsql-bugs@lists.postgresql.org; Sat, 28 Oct 2023 23:34:53 +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 1qwspJ-002nVa-Ph for pgsql-bugs@lists.postgresql.org; Sat, 28 Oct 2023 23:34:51 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=momjian.us; s=2023062407; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description; bh=QkbVt8TnEYyFc94Dc6+Un/rofIAkU+29BZYu5bn2LkM=; b=ETQ3v 6mFHoFdlBk/3TVL/joWOTcpN1ASAjeXpFVuNqFPSkfDm+iuI45iEPMX91HFIX/IaIjtGfcxHmCLJW ZKfOgt6cyRweZLNap1RLwzSn2Xr9igwPCRDNmVyPNyzH9EiHjVh9hT2/xx2hyoZOiTCB8iErG9Vtu hAavnun0WatEydycyNsafhgGyDc6bzXb6+W+Zwr1SQKQu403Sf+dRIioeevo28KFsfgS9vZO1YDF2 r2wh0aOlLp/PW1IksBiFe7I/0Y6DBVnRCuYjUkiBDr7q/kTmuqxGs6PgsbNLZqCrdew0mOervA9lE u9PltcuAgFzTQg8QqwbZ0ekmVjJAA==; Received: from bruce by momjian.us with local (Exim 4.96) (envelope-from ) id 1qwspG-009Wwk-30; Sat, 28 Oct 2023 19:34:42 -0400 Date: Sat, 28 Oct 2023 19:34:42 -0400 From: Bruce Momjian To: Tom Lane Cc: Alex Malek , 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> <1995601.1698526000@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="pCUE7kMedD/JdMrT" Content-Disposition: inline In-Reply-To: <1995601.1698526000@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --pCUE7kMedD/JdMrT Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Sat, Oct 28, 2023 at 04:46:40PM -0400, Tom Lane wrote: > Bruce Momjian 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 European Commercial Bank 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 https://momjian.us EDB https://enterprisedb.com Only you can decide what is important to you. --pCUE7kMedD/JdMrT Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="headline.diff" diff --git a/doc/src/sgml/textsearch.sgml b/doc/src/sgml/textsearch.sgml index 1550be5695..c607874dbc 100644 --- a/doc/src/sgml/textsearch.sgml +++ b/doc/src/sgml/textsearch.sgml @@ -1287,7 +1287,10 @@ ts_headline( config ts_headline 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 config; if config is omitted, the --pCUE7kMedD/JdMrT--