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 1pIS5n-0004Vl-Sh for pgsql-hackers@arkaria.postgresql.org; Thu, 19 Jan 2023 10:24:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pIS5m-0008St-Ou for pgsql-hackers@arkaria.postgresql.org; Thu, 19 Jan 2023 10:24:22 +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 1pIS5l-0008QY-NW for pgsql-hackers@lists.postgresql.org; Thu, 19 Jan 2023 10:24:22 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pIS5i-0007zk-C3 for pgsql-hackers@lists.postgresql.org; Thu, 19 Jan 2023 10:24:21 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 128E85C00EC; Thu, 19 Jan 2023 05:24:13 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Thu, 19 Jan 2023 05:24:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:reply-to:sender :subject:subject:to:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1674123853; x=1674210253; bh=n aGjmYLrQtlr33cXMFQIwpAMvevHfQAMdGhrnnLddf4=; b=apW6PjXXXNZ64l/fR sqdI26h+Z/cqE+Zs327DeKJCoHs8Wci1sINGPu3lnRPrDL6tv9dKRxX/aVCIFzwb Un08mghPVM/rndkJIkLZimR5zq1BLIitfygDWQtnZiCMcwK4Z5ypN7vIFFo1NczK tcbFh14BGZf9IrKndMtjPWc2XQhrvRKWIn5f4a6V3t01oICxvaYRRxOjjFAhOxAr Cvzt5ravoDwNpQoW01+GOlTeaxInXagphpExBEteYG68fR0CrzuWUsT7NgUE0zI0 AEAUeiJOj8XCXCSiZ6Gtzij48+2kzl7IhuMdRilC2TFKCT1otT3eOygpTmemCh7i sNPcg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedruddutddgudehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvvefukfggtggugfgjsehtke ertddttdejnecuhfhrohhmpeetlhhvrghrohcujfgvrhhrvghrrgcuoegrlhhvhhgvrhhr vgesrghlvhhhrdhnohdqihhprdhorhhgqeenucggtffrrghtthgvrhhnpedvkedtffduff dtffffheffhfejjefhgfeiueeukeejkeffgfdufffhudffffeuveenucffohhmrghinhep vghnthgvrhhprhhishgvuggsrdgtohhmnecuvehluhhsthgvrhfuihiivgeptdenucfrrg hrrghmpehmrghilhhfrhhomheprghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhr gh X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 19 Jan 2023 05:24:12 -0500 (EST) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 0A71A98; Thu, 19 Jan 2023 11:16:30 +0100 (CET) Date: Thu, 19 Jan 2023 11:16:29 +0100 From: Alvaro Herrera To: Tom Lane Cc: pgsql-hackers@lists.postgresql.org, sebastian.patino-lang@posteo.net Subject: Re: Rethinking the implementation of ts_headline() Message-ID: <20230119101629.vjdjktbol273zjpm@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <3951261.1674082546@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2023-Jan-18, Tom Lane wrote: > Alvaro Herrera writes: > > and was surprised that the match for the 'day & drink' arm of the OR > > disappears from the reported headline. > > I'd argue that that's exactly what should happen. It's supposed to > find as-short-as-possible cover strings that satisfy the query. OK, that makes sense. > I don't find anything particularly principled about the old behavior: > > > Day after day, day after day,↵ > > We stuck ... motion, ↵ > > As idle as a painted Ship ↵ > > Upon > > It's including hits for "day" into the cover despite the lack of any > nearby match to "drink". I suppose it would be possible to put 'day' and 'drink' in two different fragments: since the query has a & operator for them, the words don't necessarily have to be nearby. But OK, your argument for this being the shortest result is sensible. I do wonder, though, if it's effectively usable for somebody building a search interface on top. If I'm ranking the results from several documents, and this document comes on top of others that only match one arm of the OR query, then I would like to be able to show the matches for both arms of the OR. > > Another thing I think might be a regression is the way fragments are > > selected. Consider what happens if I change the "idle & painted" in the > > earlier query to "idle <-> painted", and MaxWords is kept low: > > Of course, "idle <-> painted" is satisfied nowhere in this text > (the words are there, but not adjacent). Oh, I see the problem, and it is my misunderstanding: the <-> operator is counting the words in between, even if they are stop words. I understood from the docs that those words were ignored, but that is not so. I misread the phraseto_tsquery doc as though they were explaining the <-> operator. Another experiment shows that the headline becomes "complete" only if I specify the exact distance in the operator: SELECT dist, ts_headline('simple', 'As idle as a painted Ship', to_tsquery('simple', format('(idle <%s> painted)', dist)), 'MaxFragments=5, MaxWords=8, MinWords=4') from generate_series(1, 4) dist; dist │ ts_headline ──────┼────────────────────────────────────── 1 │ As idle as a 2 │ As idle as a 3 │ idle as a painted Ship 4 │ As idle as a (4 filas) I again have to question how valuable in practice is a operator that's so strict that I have to know exactly how many stop words I want there to be in between the phrase search. For some reason, in my mind I had it as "at most N words, ignoring stop words", but that's not what it is. Anyway, I don't think this needs to stop your current patch. > So the cover has to run from the last 'day' to the 'drink'. I think > v15 is deciding that it runs from the first 'day' to the 'drink', > which while not exactly wrong is not the shortest cover. Sounds fair. > The rest of this is just minor variations in what mark_hl_fragments() > decides to do based on the precise cover string it's given. I don't > dispute that mark_hl_fragments() could be improved, but this patch > doesn't touch its algorithm and I think that doing so should be > material for a different patch. Understood and agreed. > > (Both 15 and master highlight 'painted' in the "Upon a painted Ocean" > > verse, which perhaps they shouldn't do, since it's not preceded by > > 'idle'.) > > Yeah, and 'idle' too. Once it's chosen a string to show, it'll > highlight all the query words within that string, whether they > constitute part of the match or not. I can see arguments on both > sides of doing it that way; it was probably more sensible before > we had phrase match than it is now. But again, changing that phase > of the processing is outside the scope of this patch. I'm just > trying to undo the damage I did to the cover-string-selection phase. All clear then. -- Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/ "The eagle never lost so much time, as when he submitted to learn of the crow." (William Blake)