1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-27 12:41:57 +03:00

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

@ -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),