pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #18580: The pg_similarity appears to be wrong
2+ messages / 2 participants
[nested] [flat]
* BUG #18580: The pg_similarity appears to be wrong
@ 2024-08-12 09:58 PG Bug reporting form <noreply@postgresql.org>
0 siblings, 1 reply; 2+ messages in thread
From: PG Bug reporting form @ 2024-08-12 09:58 UTC (permalink / raw)
To: pgsql-bugs@lists.postgresql.org; +Cc: bosamia.karan@gmail.com
The following bug has been logged on the website:
Bug reference: 18580
Logged by: Karan Bosamia
Email address: bosamia.karan@gmail.com
PostgreSQL version: 14.10
Operating system: Ubuntu
Description:
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
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: BUG #18580: The pg_similarity appears to be wrong
@ 2024-08-15 15:13 Euler Taveira <euler@eulerto.com>
parent: PG Bug reporting form <noreply@postgresql.org>
0 siblings, 0 replies; 2+ messages in thread
From: Euler Taveira @ 2024-08-15 15:13 UTC (permalink / raw)
To: bosamia.karan@gmail.com; pgsql-bugs@lists.postgresql.org
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/
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2024-08-15 15:13 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-08-12 09:58 BUG #18580: The pg_similarity appears to be wrong PG Bug reporting form <noreply@postgresql.org>
2024-08-15 15:13 ` Euler Taveira <euler@eulerto.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox