bug: fuzzystrmatch levenshtein is wrong

From: marcin mank <marcin(dot)mank(at)gmail(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: bug: fuzzystrmatch levenshtein is wrong
Date: 2009-12-07 13:33:36
Message-ID: b1b9fac60912070533g17ed035dh316da047767661b4@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

The current behavior of levenshtein(text,text,int,int,int) is wrong. Consider:

leki_dev=# select levenshtein('','a',2,4,5);
levenshtein
-------------
1
(1 row)

leki_dev=# select levenshtein('a','',2,4,5);
levenshtein
-------------
1
(1 row)

leki_dev=# select levenshtein('aa','a',2,4,5);
levenshtein
-------------
1
(1 row)

leki_dev=# select levenshtein('a','aa',2,4,5);
levenshtein
-------------
1
(1 row)

versus (after patch)

postgres=# select levenshtein('','a',2,4,5);
levenshtein
-------------
2
(1 row)

postgres=# select levenshtein('a','',2,4,5);
levenshtein
-------------
4
(1 row)

postgres=# select levenshtein('aa','a',2,4,5);
levenshtein
-------------
4
(1 row)

postgres=# select levenshtein('a','aa',2,4,5);
levenshtein
-------------
2
(1 row)

patch attached.

Greetings
Marcin Mańk

Attachment Content-Type Size
levenshtein.diff application/octet-stream 2.3 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Xin Wang 2009-12-07 13:50:09 How to cache a non-unique index?
Previous Message Magnus Hagander 2009-12-07 13:32:30 Re: [PATCH] Windows x64 [repost]