Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7b1f6ff

Browse files
committed
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. Patchattached (while I was at it I updated my email address, changed thecopyright to PGDG, and removed an unnecessary palloc). Here's how itlooks now:regression=# select metaphone(a,4) from (select 'A A COMEAUXMEMORIAL'::varchar AS a) a; metaphone----------- AKMK(1 row)regression=# select metaphone(a,5) from (select 'A A COMEAUXMEMORIAL'::varchar AS a) a; metaphone----------- AKMKS(1 row)Joe Conway
1 parent4b1fe23 commit7b1f6ff

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

‎contrib/fuzzystrmatch/README.fuzzystrmatch

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
*
44
* Functions for "fuzzy" comparison of strings
55
*
6-
* Copyright (c) Joseph Conway <joseph.conway@home.com>, 2001;
6+
* Joe Conway <mail@joeconway.com>
7+
*
8+
* Copyright (c) 2001, 2002, 2003 by PostgreSQL Global Development Group
9+
* ALL RIGHTS RESERVED;
710
*
811
* levenshtein()
912
* -------------

‎contrib/fuzzystrmatch/fuzzystrmatch.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
*
44
* Functions for "fuzzy" comparison of strings
55
*
6-
* Copyright (c) Joseph Conway <joseph.conway@home.com>, 2001;
6+
* Joe Conway <mail@joeconway.com>
7+
*
8+
* Copyright (c) 2001, 2002, 2003 by PostgreSQL Global Development Group
9+
* ALL RIGHTS RESERVED;
710
*
811
* levenshtein()
912
* -------------
@@ -221,9 +224,6 @@ metaphone(PG_FUNCTION_ARGS)
221224
if (!(reqlen>0))
222225
elog(ERROR,"metaphone: Requested Metaphone output length must be > 0");
223226

224-
metaph=palloc(reqlen);
225-
memset(metaph,'\0',reqlen);
226-
227227
retval=_metaphone(str_i,reqlen,&metaph);
228228
if (retval==META_SUCCESS)
229229
{
@@ -629,7 +629,8 @@ _metaphone(
629629
/* KS */
630630
case'X':
631631
Phonize('K');
632-
Phonize('S');
632+
if (max_phonemes==0||Phone_Len<max_phonemes)
633+
Phonize('S');
633634
break;
634635
/* Y if followed by a vowel */
635636
case'Y':

‎contrib/fuzzystrmatch/fuzzystrmatch.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
*
44
* Functions for "fuzzy" comparison of strings
55
*
6-
* Copyright (c) Joseph Conway <joseph.conway@home.com>, 2001;
6+
* Joe Conway <mail@joeconway.com>
7+
*
8+
* Copyright (c) 2001, 2002, 2003 by PostgreSQL Global Development Group
9+
* ALL RIGHTS RESERVED;
710
*
811
* levenshtein()
912
* -------------

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp