]> granicus.if.org Git - postgresql/commitdiff
Jim C. Nasby wrote:
authorBruce Momjian <bruce@momjian.us>
Tue, 24 Jun 2003 22:59:46 +0000 (22:59 +0000)
committerBruce Momjian <bruce@momjian.us>
Tue, 24 Jun 2003 22:59:46 +0000 (22:59 +0000)
> 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)

Joe Conway

contrib/fuzzystrmatch/README.fuzzystrmatch
contrib/fuzzystrmatch/fuzzystrmatch.c
contrib/fuzzystrmatch/fuzzystrmatch.h

index 8d310b4ade4c136ea87192757a09253e72e9de6d..9cd80f81b72a649a06ffd80055b7fee39d21c963 100644 (file)
@@ -3,7 +3,10 @@
  *
  * Functions for "fuzzy" comparison of strings
  *
- * Copyright (c) Joseph Conway <joseph.conway@home.com>, 2001;
+ * Joe Conway <mail@joeconway.com>
+ *
+ * Copyright (c) 2001, 2002, 2003 by PostgreSQL Global Development Group
+ * ALL RIGHTS RESERVED;
  *
  * levenshtein()
  * -------------
index 0358fb2b66bede46a8b0b2fd3ab6eb3f49ad7fa1..67e70cfc7e29691bb60005bf9e9d61aa8341655d 100644 (file)
@@ -3,7 +3,10 @@
  *
  * Functions for "fuzzy" comparison of strings
  *
- * Copyright (c) Joseph Conway <joseph.conway@home.com>, 2001;
+ * Joe Conway <mail@joeconway.com>
+ *
+ * Copyright (c) 2001, 2002, 2003 by PostgreSQL Global Development Group
+ * ALL RIGHTS RESERVED;
  *
  * levenshtein()
  * -------------
@@ -221,9 +224,6 @@ metaphone(PG_FUNCTION_ARGS)
        if (!(reqlen > 0))
                elog(ERROR, "metaphone: Requested Metaphone output length must be > 0");
 
-       metaph = palloc(reqlen);
-       memset(metaph, '\0', reqlen);
-
        retval = _metaphone(str_i, reqlen, &metaph);
        if (retval == META_SUCCESS)
        {
@@ -629,7 +629,8 @@ _metaphone(
                                /* KS */
                        case 'X':
                                Phonize('K');
-                               Phonize('S');
+                               if (max_phonemes == 0 || Phone_Len < max_phonemes)
+                                       Phonize('S');
                                break;
                                /* Y if followed by a vowel */
                        case 'Y':
index c8dbddeb0764024ab9949731ab40f3a2e31bb968..079e520b8e5a3105f465745ac5104f33c6f33f4e 100644 (file)
@@ -3,7 +3,10 @@
  *
  * Functions for "fuzzy" comparison of strings
  *
- * Copyright (c) Joseph Conway <joseph.conway@home.com>, 2001;
+ * Joe Conway <mail@joeconway.com>
+ *
+ * Copyright (c) 2001, 2002, 2003 by PostgreSQL Global Development Group
+ * ALL RIGHTS RESERVED;
  *
  * levenshtein()
  * -------------