head	1.11;
access;
symbols
	REL7_4_29:1.4
	REL8_0_25:1.7
	REL8_1_21:1.8
	REL8_2_17:1.9
	REL7_4_28:1.4
	REL8_0_24:1.7
	REL8_1_20:1.8
	REL8_2_16:1.9
	REL7_4_27:1.4
	REL8_0_23:1.7
	REL8_1_19:1.8
	REL8_2_15:1.9
	REL7_4_26:1.4
	REL8_0_22:1.7
	REL8_1_18:1.8
	REL8_2_14:1.9
	REL7_4_25:1.4
	REL8_0_21:1.7
	REL8_1_17:1.8
	REL8_2_13:1.9
	REL7_4_24:1.4
	REL8_0_20:1.7
	REL8_1_16:1.8
	REL8_2_12:1.9
	REL7_4_23:1.4
	REL8_0_19:1.7
	REL8_1_15:1.8
	REL8_2_11:1.9
	REL7_4_22:1.4
	REL8_0_18:1.7
	REL8_1_14:1.8
	REL8_2_10:1.9
	REL7_4_21:1.4
	REL8_0_17:1.7
	REL8_1_13:1.8
	REL8_2_9:1.9
	REL7_4_20:1.4
	REL8_0_16:1.7
	REL8_1_12:1.8
	REL8_2_8:1.9
	REL8_2_7:1.9
	REL7_3_21:1.2
	REL7_4_19:1.4
	REL8_0_15:1.7
	REL8_1_11:1.8
	REL8_2_6:1.9
	REL8_3_BETA2:1.10
	REL8_3_BETA1:1.10
	REL7_3_20:1.2
	REL7_4_18:1.4
	REL8_0_14:1.7
	REL8_1_10:1.8
	REL8_2_5:1.9
	REL7_3_19:1.2
	REL7_4_17:1.4
	REL8_0_13:1.7
	REL8_1_9:1.8
	REL8_2_4:1.9
	REL8_0_12:1.7
	REL8_1_8:1.8
	REL8_2_3:1.9
	REL7_3_18:1.2
	REL7_4_16:1.4
	REL8_0_11:1.7
	REL8_1_7:1.8
	REL8_2_2:1.9
	REL8_0_10:1.7
	REL8_1_6:1.8
	REL8_2_1:1.9
	REL7_4_15:1.4
	REL7_3_17:1.2
	REL8_2_STABLE:1.9.0.2
	REL8_2_0:1.9
	REL8_2_RC1:1.9
	REL8_2_BETA3:1.9
	REL8_2_BETA2:1.9
	REL8_1_5:1.8
	REL8_0_9:1.7
	REL7_4_14:1.4
	REL7_3_16:1.2
	REL8_2_BETA1:1.9
	REL7_3_15:1.2
	REL7_4_13:1.4
	REL8_0_8:1.7
	REL8_1_4:1.8
	REL7_3_14:1.2
	REL7_4_12:1.4
	REL8_0_7:1.7
	REL8_1_3:1.8
	REL7_3_13:1.2
	REL7_4_11:1.4
	REL8_0_6:1.7
	REL8_1_2:1.8
	REL7_3_12:1.2
	REL7_4_10:1.4
	REL8_0_5:1.7
	REL8_1_1:1.8
	REL8_1_STABLE:1.8.0.2
	REL8_1_0:1.8
	REL8_1_0RC1:1.8
	REL8_1_0BETA4:1.8
	REL8_1_0BETA3:1.8
	REL7_3_11:1.2
	REL7_4_9:1.4
	REL8_0_4:1.7
	REL8_1_0BETA2:1.8
	REL8_1_0BETA1:1.8
	REL7_2_8:1.2
	REL7_3_10:1.2
	REL7_4_8:1.4
	REL8_0_3:1.7
	REL8_0_2:1.7
	REL7_2_7:1.2
	REL7_3_9:1.2
	REL7_4_7:1.4
	REL8_0_1:1.7
	REL8_0_STABLE:1.7.0.4
	REL8_0_0:1.7.0.2
	REL8_0_0RC5:1.7
	REL8_0_0RC4:1.7
	REL8_0_0RC3:1.6
	REL8_0_0RC2:1.6
	REL8_0_0RC1:1.6
	REL8_0_0BETA5:1.6
	REL8_0_0BETA4:1.6
	REL7_4_6:1.4
	REL7_3_8:1.2
	REL7_2_6:1.2
	REL8_0_0BETA3:1.6
	REL8_0_0BETA2:1.6
	REL7_2_5:1.2
	REL7_4_5:1.4
	REL7_3_7:1.2
	REL7_4_4:1.4
	REL8_0_0BETA1:1.5
	REL7_4_3:1.4
	REL7_4_2:1.4
	REL7_3_6:1.2
	REL7_4_1:1.4
	REL7_3_5:1.2
	REL7_4:1.4
	REL7_4_RC2:1.4
	REL7_4_STABLE:1.4.0.4
	REL7_4_RC1:1.4
	REL7_4_BETA5:1.4
	REL7_4_BETA4:1.4
	REL7_4_BETA3:1.4
	REL7_4_BETA2:1.4
	WIN32_DEV:1.4.0.2
	REL7_4_BETA1:1.4
	REL7_3_4:1.2
	REL7_3_2:1.2
	REL7_2_4:1.2
	REL7_3_STABLE:1.2.0.4
	REL7_2_3:1.2
	REL7_2_STABLE:1.2.0.2
	REL7_2:1.2
	REL7_2_RC2:1.2
	REL7_2_RC1:1.2
	REL7_2_BETA5:1.2
	REL7_2_BETA4:1.2
	REL7_2_BETA3:1.2
	REL7_2_BETA2:1.2
	REL7_2_BETA1:1.2;
locks; strict;
comment	@# @;


1.11
date	2007.11.10.23.30.45;	author momjian;	state dead;
branches;
next	1.10;

1.10
date	2007.01.05.22.19.17;	author momjian;	state Exp;
branches;
next	1.9;

1.9
date	2006.03.05.15.58.19;	author momjian;	state Exp;
branches;
next	1.8;

1.8
date	2005.01.26.08.04.04;	author neilc;	state Exp;
branches;
next	1.7;

1.7
date	2005.01.01.20.44.11;	author tgl;	state Exp;
branches;
next	1.6;

1.6
date	2004.08.29.04.12.17;	author momjian;	state Exp;
branches;
next	1.5;

1.5
date	2004.07.01.03.25.48;	author joe;	state Exp;
branches;
next	1.4;

1.4
date	2003.08.04.23.59.37;	author tgl;	state Exp;
branches;
next	1.3;

1.3
date	2003.06.24.22.59.46;	author momjian;	state Exp;
branches;
next	1.2;

1.2
date	2001.08.07.18.16.01;	author momjian;	state Exp;
branches;
next	1.1;

1.1
date	2001.08.07.16.47.43;	author momjian;	state Exp;
branches;
next	;


desc
@@


1.11
log
@Move most /contrib README files into SGML.  Some still need conversion
or will never be converted.
@
text
@/*
 * fuzzystrmatch.c
 *
 * Functions for "fuzzy" comparison of strings
 *
 * Joe Conway <mail@@joeconway.com>
 *
 * Copyright (c) 2001-2007, PostgreSQL Global Development Group
 * ALL RIGHTS RESERVED;
 *
 * levenshtein()
 * -------------
 * Written based on a description of the algorithm by Michael Gilleland
 * found at http://www.merriampark.com/ld.htm
 * Also looked at levenshtein.c in the PHP 4.0.6 distribution for
 * inspiration.
 *
 * metaphone()
 * -----------
 * Modified for PostgreSQL by Joe Conway.
 * Based on CPAN's "Text-Metaphone-1.96" by Michael G Schwern <schwern@@pobox.com>
 * Code slightly modified for use as PostgreSQL function (palloc, elog, etc).
 * 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)
 * to soundex() for consistency.
 *
 * difference()
 * ------------
 * Return the difference between two strings' soundex values.  Kris Jurka
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation for any purpose, without fee, and without a written agreement
 * is hereby granted, provided that the above copyright notice and this
 * paragraph and the following two paragraphs appear in all copies.
 * 
 * IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING
 * LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
 * DOCUMENTATION, EVEN IF THE AUTHOR OR DISTRIBUTORS HAVE BEEN ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 * 
 * THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
 * ON AN "AS IS" BASIS, AND THE AUTHOR AND DISTRIBUTORS HAS NO OBLIGATIONS TO
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 *
 */


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

  Version 0.1
    - initial release    

Installation:
  Place these files in a directory called 'fuzzystrmatch' under 'contrib' in the PostgreSQL source tree. Then run:

    make
    make install

  You can use fuzzystrmatch.sql to create the functions in your database of choice, e.g.

    psql -U postgres template1 < fuzzystrmatch.sql

  installs following functions into database template1:

     levenshtein() - calculates the levenshtein distance between two strings
     metaphone() - calculates the metaphone code of an input string

Documentation
==================================================================
Name

levenshtein -- calculates the levenshtein distance between two strings

Synopsis

levenshtein(text source, text target)

Inputs

  source
    any text string, 255 characters max, NOT NULL

  target
    any text string, 255 characters max, NOT NULL

Outputs

  Returns int

Example usage

  select levenshtein('GUMBO','GAMBOL');

==================================================================
Name

metaphone -- calculates the metaphone code of an input string

Synopsis

metaphone(text source, int max_output_length)

Inputs

  source
    any text string, 255 characters max, NOT NULL

  max_output_length
    maximum length of the output metaphone code; if longer, the output
    is truncated to this length

Outputs

  Returns text

Example usage

  select metaphone('GUMBO',4);

==================================================================
-- Joe Conway

@


1.10
log
@Update CVS HEAD for 2007 copyright.  Back branches are typically not
back-stamped for this.
@
text
@@


1.9
log
@Update copyright for 2006.  Update scripts.
@
text
@d8 1
a8 1
 * Copyright (c) 2001-2006, PostgreSQL Global Development Group
@


1.8
log
@The attached patch implements the soundex difference function which
compares two strings' soundex values for similarity, from Kris Jurka.
Also mark the text_soundex() function as STRICT, to avoid crashing
on NULL input.
@
text
@d8 1
a8 1
 * Copyright (c) 2001-2005, PostgreSQL Global Development Group
@


1.7
log
@Some more missed copyright notices.  Many of these look like they
should have been caught by the src/tools/copyright script ... why
weren't they?
@
text
@d36 4
@


1.6
log
@Update copyright to 2004.
@
text
@d8 1
a8 1
 * Copyright (c) 2001-2004, PostgreSQL Global Development Group
@


1.5
log
@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.
@
text
@d8 1
a8 1
 * Copyright (c) 2001-2003, PostgreSQL Global Development Group
@


1.4
log
@Fix some copyright notices that weren't updated.  Improve copyright tool
so it won't miss 'em again.
@
text
@d26 5
d56 1
a56 3
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
d59 5
@


1.3
log
@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. Patch
attached (while I was at it I updated my email address, changed the
copyright to PGDG, and removed an unnecessary palloc). Here's how it
looks now:

regression=# select metaphone(a,4) from (select 'A A COMEAUX
MEMORIAL'::varchar AS a) a;
   metaphone
-----------
   AKMK
(1 row)

regression=# select metaphone(a,5) from (select 'A A COMEAUX
MEMORIAL'::varchar AS a) a;
   metaphone
-----------
   AKMKS
(1 row)

Joe Conway
@
text
@d8 1
a8 1
 * Copyright (c) 2001, 2002, 2003 by PostgreSQL Global Development Group
@


1.2
log
@Sorry - I should have gotten to this sooner. Here's a patch which you should
be able to apply against what you just committed. It rolls soundex into
fuzzystrmatch.

Remove soundex/metaphone and merge into fuzzystrmatch.

Joe Conway
@
text
@d6 4
a9 1
 * Copyright (c) Joseph Conway <joseph.conway@@home.com>, 2001;
@


1.1
log
@Per this discussion, here's a patch to implement both levenshtein() and
metaphone() in a contrib. There seem to be a fair number of different
approaches to both of these algorithms. I used the simplest case for
levenshtein which has a cost  of 1 for any character insertion, deletion, or
substitution. For metaphone, I adapted the same code from CPAN that the PHP
folks did.

A couple of questions:
1. Does it make sense to fold the soundex contrib together with this one?

2. I was debating trying to add multibyte support to levenshtein (it would
make no sense at all for metaphone), but a quick search through the contrib
directory found no hits on the word MULTIBYTE. Should worry about adding
multibyte support to levenshtein()?

Joe Conway
@
text
@d23 5
d48 1
a48 1
Version 0.1 (3 August, 2001):
d53 3
@
