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 1secAX-009aiZ-PD for pgsql-bugs@arkaria.postgresql.org; Thu, 15 Aug 2024 15:13:42 +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 1secAU-00HW4r-J7 for pgsql-bugs@arkaria.postgresql.org; Thu, 15 Aug 2024 15:13:38 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1secAT-00HW4j-89 for pgsql-bugs@lists.postgresql.org; Thu, 15 Aug 2024 15:13:38 +0000 Received: from fout4-smtp.messagingengine.com ([103.168.172.147]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1secAL-0050LB-TF for pgsql-bugs@lists.postgresql.org; Thu, 15 Aug 2024 15:13:36 +0000 Received: from phl-compute-04.internal (phl-compute-04.nyi.internal [10.202.2.44]) by mailfout.nyi.internal (Postfix) with ESMTP id C1DA4138FC6D; Thu, 15 Aug 2024 11:13:27 -0400 (EDT) Received: from phl-imap-09 ([10.202.2.99]) by phl-compute-04.internal (MEProxy); Thu, 15 Aug 2024 11:13:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eulerto.com; h= cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1723734807; x=1723821207; bh=JoBsJzNFAz QAhNtUpwygQiNjJeL9twVPIccI8VYKm+I=; b=ba7Wpc62lOau1lZiaAS92f+k4x Yd3eriRKk3Mx74HrL5hfSB1UdlmNSIcFEZ1jwNR9tZPPgGkf99zyTY3Ik/c1hffV UOeeP1Fjz3nZzqRozVioGoiLg54f76ZfCnuzpfIGO8OG0ZN7HyJrl8O+RJlHBPwJ iQgxjkOmxy+LCoPZHWdj+PTlaep0DBYKQ18s5Q5nzC3htUehk61xDHJMk1/+5RAa iim7nLMPRCrFppUioOzH//pusKVUBuDF2u24GNmv4wTV2SVmnLlsR0MHSb3wxBZm Fd1yHMk6T5w27RLwsj92y8kw/lrVqB0mJ1kv0Il3hb0GN6oSMm14wVN8RcqQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1723734807; x=1723821207; bh=JoBsJzNFAzQAhNtUpwygQiNjJeL9 twVPIccI8VYKm+I=; b=J/7EdRTq4S6ENr5XqvxCPwkFHeT1ueyfHbEhhVSWa5LR B6G4SC6YhQrZIKZ8/7etSFablp7Byw54Q1r7kexnCRBtZoRLOGffM5audTBw5An4 KDytsOqqdlgjrSY+B8qgBvN52aEkELu404k2OE8lsUAlaUZqogkFbyJk3lvTxmo0 SijFpkSRjvK5iiE7xSUAokl1OGEH7ZnKiQA1IU341k0D3hG0Xg0dtmZ4YBtNaE7b tQsj8a+sxr/ItPQ6pFychgb4iA4yhqk0N1z5g+EEu1CiEQFxHyTFp3yBkidBd8Tc NjuBUJphj4JxFS7dqd3CWDzVEZUImNCPIrr/5opYMQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtiedgkeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefoggffhf fvkfgjfhfutgesrgdtreerredttdenucfhrhhomhepfdfguhhlvghrucfvrghvvghirhgr fdcuoegvuhhlvghrsegvuhhlvghrthhordgtohhmqeenucggtffrrghtthgvrhhnpeekje dvhefgjeekueehgfegueekjefggfdtueetffeluefgheeitdegfffhgeeuheenucffohhm rghinhepphhoshhtghhrvghsqhhlrdhorhhgpdgvnhhtvghrphhrihhsvggusgdrtghomh enucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegvuhhl vghrsegvuhhlvghrthhordgtohhmpdhnsggprhgtphhtthhopedvpdhmohguvgepshhmth hpohhuthdprhgtphhtthhopegsohhsrghmihgrrdhkrghrrghnsehgmhgrihhlrdgtohhm pdhrtghpthhtohepphhgshhqlhdqsghughhssehlihhsthhsrdhpohhsthhgrhgvshhqlh drohhrgh X-ME-Proxy: Feedback-ID: i0c21471d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 2332815A005E; Thu, 15 Aug 2024 11:13:27 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface MIME-Version: 1.0 Date: Thu, 15 Aug 2024 12:13:06 -0300 From: "Euler Taveira" To: bosamia.karan@gmail.com, pgsql-bugs@lists.postgresql.org Message-Id: In-Reply-To: <18580-11fe381a9adde140@postgresql.org> References: <18580-11fe381a9adde140@postgresql.org> Subject: Re: BUG #18580: The pg_similarity appears to be wrong Content-Type: multipart/alternative; boundary=1f6e19882c7446dea02b348f73fd9a7d List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --1f6e19882c7446dea02b348f73fd9a7d Content-Type: text/plain Content-Transfer-Encoding: 7bit On Mon, Aug 12, 2024, at 6:58 AM, PG Bug reporting form wrote: > SELECT * > FROM ( > SELECT > *, > similarity(provision_clean_description, 'Policies The General Partner > shall promptly notify the Investor of any proposed changes in the Funds > leverage policies including adjustments to leverage ratios') AS sim_tim > FROM provision_database > ) pd > WHERE sim_tim <= 1 and sim_tim > 0.7 and firm_id=18; > > This both sentences giving similarity score as 1 despite the fact that the > sentence 1. has Policies as the starting word(do not include the starting > hyphen in the sentences): > - Policies The General Partner shall promptly notify the Investor of any > proposed changes in the Funds leverage policies including adjustments to > leverage ratios > - The General Partner shall promptly notify the Investor of any proposed > changes in the Funds leverage policies including adjustments to leverage > ratios > This is not a bug. That's how trigram works. The documentation [1] explains that the words don't need to be in the same order because it counts the number of common trigrams. Trigrams are extracted ignoring non-alphanumeric characters. Trigrams are case-insensitive. You can check the trigrams extracted using the show_trgm() function. -- -- return the non-common trigrams -- WITH a AS ( SELECT x FROM unnest(show_trgm('Policies The General Partner shall promptly notify the Investor of any proposed changes in the Funds leverage policies including adjustments to leverage ratios')) x), b AS ( SELECT x FROM unnest(show_trgm('The General Partner shall promptly notify the Investor of any proposed changes in the Funds leverage policies including adjustments to leverage ratios')) x) SELECT * FROM a FULL JOIN b ON (a.x = b.x) WHERE a.x IS NULL OR b.x IS NULL; [1] https://www.postgresql.org/docs/current/pgtrgm.html#PGTRGM-CONCEPTS -- Euler Taveira EDB https://www.enterprisedb.com/ --1f6e19882c7446dea02b348f73fd9a7d Content-Type: text/html Content-Transfer-Encoding: quoted-printable
On Mon, Aug 12,= 2024, at 6:58 AM, PG Bug reporting form wrote:
SELECT *
FROM (
  SELECT 
    *, 
    similarity(provision_clean_description, = 'Policies The General Partner
shall promptly notify the In= vestor of any proposed changes in the Funds
leverage polic= ies including adjustments to leverage ratios') AS sim_tim
=   FROM provision_database
) pd
  W= HERE sim_tim <=3D 1 and sim_tim > 0.7 and firm_id=3D18;
<= div>
This both sentences giving similarity score as 1 desp= ite the fact that the
sentence 1. has Policies as the star= ting word(do not include the starting
hyphen in the senten= ces):
- Policies The General Partner shall promptly notify= the Investor of any
proposed changes in the Funds leverag= e policies including adjustments to
leverage ratios
- The General Partner shall promptly notify the Investor of any = proposed
changes in the Funds leverage policies including = adjustments to leverage
ratios


This is not a bug.

That's how trigram works. The documentation [1] explains that the word= s don't
need to be in the same order because it counts the= number of common trigrams.
Trigrams are extracted ignorin= g non-alphanumeric characters. Trigrams are
case-insensiti= ve. You can check the trigrams extracted using the show_trgm()
=
function.

--
-- return t= he non-common trigrams
--
WITH a AS (
SELECT x FROM unnest(show_trgm('Policies The General Partner sha= ll promptly
notify the Investor of any proposed changes in= the Funds leverage policies
including adjustments to leve= rage ratios')) x),
b AS (
SELECT x FROM unne= st(show_trgm('The General Partner shall promptly notify the
Investor of any proposed changes in the Funds leverage policies includ= ing
adjustments to leverage ratios')) x)
SEL= ECT * FROM a FULL JOIN b ON (a.x =3D b.x) WHERE a.x IS NULL OR b.x IS NU= LL;



--
Euler Taveira

--1f6e19882c7446dea02b348f73fd9a7d--