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 1pHOcM-0000Ks-UN for pgsql-hackers@arkaria.postgresql.org; Mon, 16 Jan 2023 12:29:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pHOcK-0003ht-SB for pgsql-hackers@arkaria.postgresql.org; Mon, 16 Jan 2023 12:29:36 +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 1pHOcJ-0003hj-NX for pgsql-hackers@lists.postgresql.org; Mon, 16 Jan 2023 12:29:36 +0000 Received: from wout3-smtp.messagingengine.com ([64.147.123.19]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pHOcC-0007M6-J7 for pgsql-hackers@lists.postgresql.org; Mon, 16 Jan 2023 12:29:34 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 4C997320089C; Mon, 16 Jan 2023 07:29:26 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Mon, 16 Jan 2023 07:29:26 -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=1673872165; x=1673958565; bh=Q I06SsUOWzT7sxeFN2pwdmfwgmg+KiXwhV/vUlCDn+c=; b=Z1PZgYr4yyjsdVc1/ Mu3AT235OmyR3FPrzDKSFyGTVY5BDYuaBypCzP75PuNwiPzA6YzorVoVTQQu5QlN YoCEKA1nHtwEKSYrJfczMj6X8KOxRvvwv+YBBPUiewqBflRCwWx0w6txk8qnHD/v c697hV/YO8OGCieuQTT+59EHym4Om6wUVNB/n9j34EYeHzjYuiktTYf9U73yGNy2 +NOcVjkVrixRnqHGRu4ni0+pseuZT41icZzkrvTSLL7EABIe2I0XNirlj5D3SP7j klaiUehLcjzb/EsaQebt+NuVSWig88xQZ9grsT9BktS2k55S9IJhdtJQzvoSH7W8 3zobA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedruddtgedggedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvvefukfggtggugfgjsehtke ertddttdejnecuhfhrohhmpeetlhhvrghrohcujfgvrhhrvghrrgcuoegrlhhvhhgvrhhr vgesrghlvhhhrdhnohdqihhprdhorhhgqeenucggtffrrghtthgvrhhnpedvkedtffduff dtffffheffhfejjefhgfeiueeukeejkeffgfdufffhudffffeuveenucffohhmrghinhep vghnthgvrhhprhhishgvuggsrdgtohhmnecuvehluhhsthgvrhfuihiivgeptdenucfrrg hrrghmpehmrghilhhfrhhomheprghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhr gh X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 16 Jan 2023 07:29:25 -0500 (EST) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 483D797; Mon, 16 Jan 2023 13:23:03 +0100 (CET) Date: Mon, 16 Jan 2023 13:23:03 +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: <20230116122303.ddumvskoxnositjy@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <840.1669405935@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2022-Nov-25, Tom Lane wrote: > After further contemplation of bug #17691 [1], I've concluded that > what I did in commit c9b0c678d was largely misguided. For one > thing, the new hlCover() algorithm no longer finds shortest-possible > cover strings: if your query is "x & y" and the text is like > "... x ... x ... y ...", then the selected cover string will run > from the first occurrence of x to the y, whereas the old algorithm > would have correctly selected "x ... y". For another thing, the > maximum-cover-length hack that I added in 78e73e875 to band-aid > over the performance issues of the original c9b0c678d patch means > that various scenarios no longer work as well as they used to, > which is the proximate cause of the complaints in bug #17691. I came across #17556 which contains a different test for this, and I'm not sure that this patch changes things completely for the better. In that bug report, Alex Malek presents this example select ts_headline('baz baz baz ipsum ' || repeat(' foo ',4998) || 'labor', $$'ipsum' & 'labor'$$::tsquery, 'StartSel={, StopSel=}, MaxFragments=100, MaxWords=7, MinWords=3'), ts_headline('baz baz baz ipsum ' || repeat(' foo ',4999) || 'labor', $$'ipsum' & 'labor'$$::tsquery, 'StartSel={, StopSel=}, MaxFragments=100, MaxWords=7, MinWords=3'); which returns, in the current HEAD, the following ts_headline │ ts_headline ─────────────────────┼───────────── {ipsum} ... {labor} │ baz baz baz (1 fila) That is, once past the 5000 words of distance, it fails to find a good cover, but before that it returns an acceptable headline. However, after your proposed patch, we get this: ts_headline │ ts_headline ─────────────┼───────────── {ipsum} │ {ipsum} (1 fila) which is an improvement in the second case, though perhaps not as much as we would like, and definitely not an improvement in the first case. -- Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/ "If you have nothing to say, maybe you need just the right tool to help you not say it." (New York Times, about Microsoft PowerPoint)