fuzzystrmatch This section describes the fuzzystrmatch module which provides different functions to determine similarities and distance between strings. Soundex The Soundex system is a method of matching similar sounding names (or any words) to the same code. It was initially used by the United States Census in 1880, 1900, and 1910, but it has little use beyond English names (or the English pronunciation of names), and it is not a linguistic tool. When comparing two soundex values to determine similarity, the difference function reports how close the match is on a scale from zero to four, with zero being no match and four being an exact match. The following are some usage examples: SELECT soundex('hello world!'); SELECT soundex('Anne'), soundex('Ann'), difference('Anne', 'Ann'); SELECT soundex('Anne'), soundex('Andrew'), difference('Anne', 'Andrew'); SELECT soundex('Anne'), soundex('Margaret'), difference('Anne', 'Margaret'); CREATE TABLE s (nm text); INSERT INTO s VALUES ('john'); INSERT INTO s VALUES ('joan'); INSERT INTO s VALUES ('wobbly'); INSERT INTO s VALUES ('jack'); SELECT * FROM s WHERE soundex(nm) = soundex('john'); SELECT a.nm, b.nm FROM s a, s b WHERE soundex(a.nm) = soundex(b.nm) AND a.oid <> b.oid; CREATE FUNCTION text_sx_eq(text, text) RETURNS boolean AS 'select soundex($1) = soundex($2)' LANGUAGE SQL; CREATE FUNCTION text_sx_lt(text, text) RETURNS boolean AS 'select soundex($1) < soundex($2)' LANGUAGE SQL; CREATE FUNCTION text_sx_gt(text, text) RETURNS boolean AS 'select soundex($1) > soundex($2)' LANGUAGE SQL; CREATE FUNCTION text_sx_le(text, text) RETURNS boolean AS 'select soundex($1) <= soundex($2)' LANGUAGE SQL; CREATE FUNCTION text_sx_ge(text, text) RETURNS boolean AS 'select soundex($1) >= soundex($2)' LANGUAGE SQL; CREATE FUNCTION text_sx_ne(text, text) RETURNS boolean AS 'select soundex($1) <> soundex($2)' LANGUAGE SQL; DROP OPERATOR #= (text, text); CREATE OPERATOR #= (leftarg=text, rightarg=text, procedure=text_sx_eq, commutator = #=); SELECT * FROM s WHERE text_sx_eq(nm, 'john'); SELECT * FROM s WHERE s.nm #= 'john'; SELECT * FROM s WHERE difference(s.nm, 'john') > 2; levenshtein This function calculates the levenshtein distance between two strings: int levenshtein(text source, text target) Both source and target can be any NOT NULL string with a maximum of 255 characters. Example: SELECT levenshtein('GUMBO','GAMBOL'); metaphone This function calculates and returns the metaphone code of an input string: text metahpone(text source, int max_output_length) source has to be a NOT NULL string with a maximum of 255 characters. max_output_length fixes the maximum length of the output metaphone code; if longer, the output is truncated to this length. Example SELECT metaphone('GUMBO',4);