Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e8MOv-00055g-Rj for pgsql-bugs@arkaria.postgresql.org; Sat, 28 Oct 2017 08:23:30 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1e8MOv-0006NZ-9b for pgsql-bugs@arkaria.postgresql.org; Sat, 28 Oct 2017 08:23:29 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1e8MOC-000584-4Z for pgsql-bugs@postgresql.org; Sat, 28 Oct 2017 08:22:44 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by magus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e8MO3-0006WM-Re for pgsql-bugs@postgresql.org; Sat, 28 Oct 2017 08:22:43 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 67C9221C2057; Sat, 28 Oct 2017 11:22:34 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru Received: from arthur.localdomain (geo9.internetdsl.tpnet.pl [83.12.118.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id 7D1F121C0624; Sat, 28 Oct 2017 11:22:33 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1509178954; bh=jsXPvjRUIpdrJuflKZ9ZKNW4t5XX3PMigwBbHOHlUoM=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=Gd/CN9GNADU1YOAJ83LuUmVW8W9I2ergg3PQbZYhLdn92B/+Re3UVaIyVQrBRuk1t nvuj1vZZ6cQsxIw5UhNmibt8H0qBsvpq1xBbBc3RwyHYPV7BIQPSGjlnuv8PeKrNaV 3icATxCtBchqsMsyLrM89e6KKFTAaHRANu0Ks2BM= Date: Sat, 28 Oct 2017 10:22:29 +0200 From: Arthur Zakirov To: Cristiano Coelho Cc: "pgsql-bugs@postgresql.org" Subject: Re: pg_trgm word_similarity inconsistencies or bug Message-ID: <20171028082225.GA2157@arthur.localdomain> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.9.1 (2017-09-22) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org On Fri, Oct 27, 2017 at 06:48:08PM +0000, Cristiano Coelho wrote: > Hello all, this is related to postgres 9.6 (9.6.4) and a good description can be found here https://stackoverflow.com/questions/46966360/postgres-word-similarity-not-comparing-words > > But in summary, word_similarity doesn’t seem to do exactly what the docs say, since it will match trigrams from multiple words rather tan doing a word by word comparison. > > Below is a table with output and expected output, thanks to kiln from stackoverflow to provide it. > Interesting. An klin's answer from stackoverflow.com is right. The initial example can be reduced to the next: =# select word_similarity('sage', 'age sag'); word_similarity ----------------- 1 It computes maximum similarity using closest trigrams not considering order of 'sage' trigrams. It determines that all trigrams from 'sage' match trigrams from 'age sag'. Initial order of 'age sag' trigrams: ' a', ' ag', 'age', 'ge ', ' s', ' sa', 'sag', 'ag ' ^ ^ |from |to Sorted 'sage' trigrams (all of them occured within 'age sag' trigrams continuously): ' s', ' sa', 'age', 'ge ', 'sag' Maybe the problem should be solved by considering 'sage' trigrams initial order. -- Arthur Zakirov Postgres Professional: http://www.postgrespro.com Russian Postgres Company -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs