pg_trgm word_similarity inconsistencies or bug

Cristiano Coelho <cristianocca@hotmail.com>

From: Cristiano Coelho <cristianocca@hotmail.com>
To: "pgsql-bugs@postgresql.org" <pgsql-bugs@postgresql.org>
Date: 2017-10-27T18:48:08Z
Lists: pgsql-bugs, pgsql-hackers
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.



with data(t) as (

values

('message'),

('message s'),

('message sag'),

('message sag sag'),

('message sag sage')

)



select t, word_similarity('sage', t), my_word_similarity('sage', t)

from data;



        t         | word_similarity | my_word_similarity

------------------+-----------------+--------------------

 message          |             0.6 |                0.3

 message s        |             0.8 |                0.3

 message sag      |               1 |                0.5

 message sag sag  |               1 |                0.5

 message sag sage |               1 |                  1

Commits

  1. Update trigram example in docs to correct state

  2. Add strict_word_similarity to pg_trgm module

  3. Rework word_similarity documentation, make it close to actual algorithm.