Add double metaphone code from Andrew Dunstan. Also change metaphone so that

an empty input string causes an empty output string to be returned, instead of
throwing an ERROR -- per complaint from Aaron Hillegass, and consistent with
double metaphone. Fix examples in README.soundex pointed out by James Robinson.
This commit is contained in:
Joe Conway 2004-07-01 03:25:48 +00:00
parent 77a436ba55
commit 13629df5a1
6 changed files with 1489 additions and 7 deletions

View File

@ -1,10 +1,12 @@
# $PostgreSQL: pgsql/contrib/fuzzystrmatch/Makefile,v 1.3 2003/11/29 19:51:35 pgsql Exp $ # $PostgreSQL: pgsql/contrib/fuzzystrmatch/Makefile,v 1.4 2004/07/01 03:25:48 joe Exp $
subdir = contrib/fuzzystrmatch subdir = contrib/fuzzystrmatch
top_builddir = ../.. top_builddir = ../..
include $(top_builddir)/src/Makefile.global include $(top_builddir)/src/Makefile.global
MODULES = fuzzystrmatch MODULE_big = fuzzystrmatch
SRCS += fuzzystrmatch.c dmetaphone.c
OBJS = $(SRCS:.c=.o)
DATA_built = fuzzystrmatch.sql DATA_built = fuzzystrmatch.sql
DOCS = README.fuzzystrmatch README.soundex DOCS = README.fuzzystrmatch README.soundex

View File

@ -23,6 +23,11 @@
* Metaphone was originally created by Lawrence Philips and presented in article * Metaphone was originally created by Lawrence Philips and presented in article
* in "Computer Language" December 1990 issue. * in "Computer Language" December 1990 issue.
* *
* dmetaphone() and dmetaphone_alt()
* ---------------------------------
* A port of the DoubleMetaphone perl module by Andrew Dunstan. See dmetaphone.c
* for more detail.
*
* soundex() * soundex()
* ----------- * -----------
* Folded existing soundex contrib into this one. Renamed text_soundex() (C function) * Folded existing soundex contrib into this one. Renamed text_soundex() (C function)
@ -48,11 +53,14 @@
*/ */
Version 0.2 (7 August, 2001): Version 0.3 (30 June, 2004):
Functions to calculate the degree to which two strings match in a "fuzzy" way
Tested under Linux (Red Hat 6.2 and 7.0) and PostgreSQL 7.2devel
Release Notes: Release Notes:
Version 0.3
- added double metaphone code from Andrew Dunstan
- change metaphone so that an empty input string causes an empty
output string to be returned, instead of throwing an ERROR
- fixed examples in README.soundex
Version 0.2 Version 0.2
- folded soundex contrib into this one - folded soundex contrib into this one

View File

@ -20,7 +20,7 @@ insert into s values ('wobbly')\g
select * from s select * from s
where soundex(nm) = soundex('john')\g where soundex(nm) = soundex('john')\g
select nm from s a, s b select a.nm, b.nm from s a, s b
where soundex(a.nm) = soundex(b.nm) where soundex(a.nm) = soundex(b.nm)
and a.oid <> b.oid\g and a.oid <> b.oid\g
@ -51,7 +51,7 @@ LANGUAGE 'sql';
DROP OPERATOR #= (text,text)\g DROP OPERATOR #= (text,text)\g
CREATE OPERATOR #= (leftarg=text, rightarg=text, procedure=text_sx_eq, CREATE OPERATOR #= (leftarg=text, rightarg=text, procedure=text_sx_eq,
commutator=text_sx_eq)\g commutator = #=)\g
SELECT * SELECT *
FROM s FROM s

File diff suppressed because it is too large Load Diff

View File

@ -202,6 +202,8 @@ levenshtein(PG_FUNCTION_ARGS)
* Returns number of characters requested * Returns number of characters requested
* (suggested value is 4) * (suggested value is 4)
*/ */
#define GET_TEXT(cstrp) DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(cstrp)))
PG_FUNCTION_INFO_V1(metaphone); PG_FUNCTION_INFO_V1(metaphone);
Datum Datum
metaphone(PG_FUNCTION_ARGS) metaphone(PG_FUNCTION_ARGS)
@ -216,6 +218,10 @@ metaphone(PG_FUNCTION_ARGS)
str_i = DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(PG_GETARG_TEXT_P(0)))); str_i = DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(PG_GETARG_TEXT_P(0))));
str_i_len = strlen(str_i); str_i_len = strlen(str_i);
/* return an empty string if we receive one */
if (!(str_i_len > 0))
PG_RETURN_TEXT_P(GET_TEXT(""));
if (str_i_len > MAX_METAPHONE_STRLEN) if (str_i_len > MAX_METAPHONE_STRLEN)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE), (errcode(ERRCODE_INVALID_PARAMETER_VALUE),

View File

@ -18,3 +18,11 @@ LANGUAGE 'C' WITH (iscachable, isstrict);
CREATE FUNCTION text_soundex(text) RETURNS text CREATE FUNCTION text_soundex(text) RETURNS text
AS 'MODULE_PATHNAME', 'soundex' AS 'MODULE_PATHNAME', 'soundex'
LANGUAGE 'C'; LANGUAGE 'C';
CREATE FUNCTION dmetaphone (text) RETURNS text
LANGUAGE C IMMUTABLE STRICT
AS 'MODULE_PATHNAME', 'dmetaphone';
CREATE FUNCTION dmetaphone_alt (text) RETURNS text
LANGUAGE C IMMUTABLE STRICT
AS 'MODULE_PATHNAME', 'dmetaphone_alt';