Commit 13629df5 authored by Joe Conway's avatar Joe Conway

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.
parent 77a436ba
# $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
top_builddir = ../..
include $(top_builddir)/src/Makefile.global
MODULES = fuzzystrmatch
MODULE_big = fuzzystrmatch
SRCS += fuzzystrmatch.c dmetaphone.c
OBJS = $(SRCS:.c=.o)
DATA_built = fuzzystrmatch.sql
DOCS = README.fuzzystrmatch README.soundex
......
......@@ -23,6 +23,11 @@
* Metaphone was originally created by Lawrence Philips and presented in article
* 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()
* -----------
* Folded existing soundex contrib into this one. Renamed text_soundex() (C function)
......@@ -48,11 +53,14 @@
*/
Version 0.2 (7 August, 2001):
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
Version 0.3 (30 June, 2004):
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
- folded soundex contrib into this one
......
......@@ -20,7 +20,7 @@ insert into s values ('wobbly')\g
select * from s
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)
and a.oid <> b.oid\g
......@@ -51,7 +51,7 @@ LANGUAGE 'sql';
DROP OPERATOR #= (text,text)\g
CREATE OPERATOR #= (leftarg=text, rightarg=text, procedure=text_sx_eq,
commutator=text_sx_eq)\g
commutator = #=)\g
SELECT *
FROM s
......
This diff is collapsed.
......@@ -202,6 +202,8 @@ levenshtein(PG_FUNCTION_ARGS)
* Returns number of characters requested
* (suggested value is 4)
*/
#define GET_TEXT(cstrp) DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(cstrp)))
PG_FUNCTION_INFO_V1(metaphone);
Datum
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_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)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
......
......@@ -18,3 +18,11 @@ LANGUAGE 'C' WITH (iscachable, isstrict);
CREATE FUNCTION text_soundex(text) RETURNS text
AS 'MODULE_PATHNAME', 'soundex'
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';
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment