pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Igal @ Lucee.org <igal@lucee.org>
To: pgsql-general <pgsql-general@postgresql.org>
Subject: Consider Spaces in pg_trgm for Better Similarity
Date: Sun, 28 Jan 2018 21:56:26 -0800
Message-ID: <fb93cee1-6020-1b8c-4dad-e7f9741db497@lucee.org> (raw)

Is there a way to consider white space in tri-grams?  That would allow 
for better matches of phrases.

For example, currently "one two three" and "three two one" would 
generate the same tri-grams ({  o,  t, on, th, tw,ee ,hre,ne 
,one,ree,thr,two,wo }), and the distance of "one two four" will be the 
same for both of them.  The query:

SELECT   phrase
         ,input
         ,similarity(t1.phrase, t2.input)
         ,word_similarity(t1.phrase, t2.input)
FROM      (values('one two three'),('three two one')) t1(phrase)
         ,(values('one two four')) t2(input);

Returns:

phrase        |input        |similarity  |word_similarity |
--------------|-------------|------------|----------------|
one two three |one two four |0.444444448 |0.615384638 |
three two one |one two four |0.444444448 |0.615384638 |

But surely "one two four" is more similar to "one two three" than to 
"three two one".

Any thoughts?

Igal Sapir
Lucee Core Developer
Lucee.org <http://lucee.org/;

Message-ID: <fb93cee1-6020-1b8c-4dad-e7f9741db497@lucee.org>
Permalink:  ../fb93cee1-6020-1b8c-4dad-e7f9741db497@lucee.org/
Also on:    postgresql.org/message-id/fb93cee1-6020-1b8c-4dad-e7f9741db497@lucee.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: igal@lucee.org
  Subject: Re: Consider Spaces in pg_trgm for Better Similarity
  In-Reply-To: <fb93cee1-6020-1b8c-4dad-e7f9741db497@lucee.org>
  References: <fb93cee1-6020-1b8c-4dad-e7f9741db497@lucee.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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