Re: [GENERAL] Bug in metaphone (contrib/fuzzystrmatch)

From: Joe Conway <mail(at)joeconway(dot)com>
To: jim(at)nasby(dot)net
Cc: "Patches (PostgreSQL)" <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [GENERAL] Bug in metaphone (contrib/fuzzystrmatch)
Date: 2003-06-07 15:40:08
Message-ID: 3EE20758.6040005@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-patches

(I never saw this make it to the list yesterday, so I'm resending to
patches)

Jim C. Nasby wrote:
> Second argument to metaphone is suposed to set the limit on the
> number of characters to return, but it breaks on some phrases:
>
> usps=# select metaphone(a,3),metaphone(a,4),metaphone(a,20) from
> (select 'Hello world'::varchar AS a) a;
> HLW | HLWR | HLWRLT
>
> usps=# select metaphone(a,3),metaphone(a,4),metaphone(a,20) from
> (select 'A A COMEAUX MEMORIAL'::varchar AS a) a;
> AKM | AKMKS | AKMKSMMRL
>
> In every case I've found that does this, the 4th and 5th letters are
> always 'KS'.

Nice catch.

There was a bug in the original metaphone algorithm from CPAN. Patch
attached (while I was at it I updated my email address, changed the
copyright to PGDG, and removed an unnecessary palloc). Here's how it
looks now:

regression=# select metaphone(a,4) from (select 'A A COMEAUX
MEMORIAL'::varchar AS a) a;
metaphone
-----------
AKMK
(1 row)

regression=# select metaphone(a,5) from (select 'A A COMEAUX
MEMORIAL'::varchar AS a) a;
metaphone
-----------
AKMKS
(1 row)

Please apply.

Thanks,

Joe

Attachment Content-Type Size
fuzzystrmatch-fix.patch text/plain 3.1 KB

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Joe Conway 2003-06-07 15:43:09 Re: Problem with bytea
Previous Message Jan Wieck 2003-06-07 15:34:56 Re: update phenomenom

Browse pgsql-patches by date

  From Date Subject
Next Message Tom Lane 2003-06-07 15:44:25 Re: [BUGS] Detecting proper bison version before make
Previous Message Bruce Momjian 2003-06-06 22:19:14 Re: pgstattuple for schemas