PostgreSQL Source Code  git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
fuzzystrmatch.c
Go to the documentation of this file.
1 /*
2  * fuzzystrmatch.c
3  *
4  * Functions for "fuzzy" comparison of strings
5  *
6  * Joe Conway <mail@joeconway.com>
7  *
8  * contrib/fuzzystrmatch/fuzzystrmatch.c
9  * Copyright (c) 2001-2024, PostgreSQL Global Development Group
10  * ALL RIGHTS RESERVED;
11  *
12  * metaphone()
13  * -----------
14  * Modified for PostgreSQL by Joe Conway.
15  * Based on CPAN's "Text-Metaphone-1.96" by Michael G Schwern <schwern@pobox.com>
16  * Code slightly modified for use as PostgreSQL function (palloc, elog, etc).
17  * Metaphone was originally created by Lawrence Philips and presented in article
18  * in "Computer Language" December 1990 issue.
19  *
20  * Permission to use, copy, modify, and distribute this software and its
21  * documentation for any purpose, without fee, and without a written agreement
22  * is hereby granted, provided that the above copyright notice and this
23  * paragraph and the following two paragraphs appear in all copies.
24  *
25  * IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR
26  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING
27  * LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
28  * DOCUMENTATION, EVEN IF THE AUTHOR OR DISTRIBUTORS HAVE BEEN ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  *
31  * THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
32  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
33  * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
34  * ON AN "AS IS" BASIS, AND THE AUTHOR AND DISTRIBUTORS HAS NO OBLIGATIONS TO
35  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
36  *
37  */
38 
39 #include "postgres.h"
40 
41 #include <ctype.h>
42 
43 #include "utils/builtins.h"
44 #include "utils/varlena.h"
45 #include "varatt.h"
46 
48 
49 /*
50  * Soundex
51  */
52 static void _soundex(const char *instr, char *outstr);
53 
54 #define SOUNDEX_LEN 4
55 
56 /* ABCDEFGHIJKLMNOPQRSTUVWXYZ */
57 static const char *const soundex_table = "01230120022455012623010202";
58 
59 static char
60 soundex_code(char letter)
61 {
62  letter = toupper((unsigned char) letter);
63  /* Defend against non-ASCII letters */
64  if (letter >= 'A' && letter <= 'Z')
65  return soundex_table[letter - 'A'];
66  return letter;
67 }
68 
69 /*
70  * Metaphone
71  */
72 #define MAX_METAPHONE_STRLEN 255
73 
74 /*
75  * Original code by Michael G Schwern starts here.
76  * Code slightly modified for use as PostgreSQL function.
77  */
78 
79 
80 /**************************************************************************
81  metaphone -- Breaks english phrases down into their phonemes.
82 
83  Input
84  word -- An english word to be phonized
85  max_phonemes -- How many phonemes to calculate. If 0, then it
86  will phonize the entire phrase.
87  phoned_word -- The final phonized word. (We'll allocate the
88  memory.)
89  Output
90  error -- A simple error flag, returns true or false
91 
92  NOTES: ALL non-alpha characters are ignored, this includes whitespace,
93  although non-alpha characters will break up phonemes.
94 ****************************************************************************/
95 
96 
97 /* I add modifications to the traditional metaphone algorithm that you
98  might find in books. Define this if you want metaphone to behave
99  traditionally */
100 #undef USE_TRADITIONAL_METAPHONE
101 
102 /* Special encodings */
103 #define SH 'X'
104 #define TH '0'
105 
106 static char Lookahead(char *word, int how_far);
107 static void _metaphone(char *word, int max_phonemes, char **phoned_word);
108 
109 /* Metachar.h ... little bits about characters for metaphone */
110 
111 
112 /*-- Character encoding array & accessing macros --*/
113 /* Stolen directly out of the book... */
114 static const char _codes[26] = {
115  1, 16, 4, 16, 9, 2, 4, 16, 9, 2, 0, 2, 2, 2, 1, 4, 0, 2, 4, 4, 1, 0, 0, 0, 8, 0
116 /* a b c d e f g h i j k l m n o p q r s t u v w x y z */
117 };
118 
119 static int
120 getcode(char c)
121 {
122  if (isalpha((unsigned char) c))
123  {
124  c = toupper((unsigned char) c);
125  /* Defend against non-ASCII letters */
126  if (c >= 'A' && c <= 'Z')
127  return _codes[c - 'A'];
128  }
129  return 0;
130 }
131 
132 #define isvowel(c) (getcode(c) & 1) /* AEIOU */
133 
134 /* These letters are passed through unchanged */
135 #define NOCHANGE(c) (getcode(c) & 2) /* FJMNR */
136 
137 /* These form diphthongs when preceding H */
138 #define AFFECTH(c) (getcode(c) & 4) /* CGPST */
139 
140 /* These make C and G soft */
141 #define MAKESOFT(c) (getcode(c) & 8) /* EIY */
142 
143 /* These prevent GH from becoming F */
144 #define NOGHTOF(c) (getcode(c) & 16) /* BDH */
145 
147 Datum
149 {
150  text *src = PG_GETARG_TEXT_PP(0);
151  text *dst = PG_GETARG_TEXT_PP(1);
152  int ins_c = PG_GETARG_INT32(2);
153  int del_c = PG_GETARG_INT32(3);
154  int sub_c = PG_GETARG_INT32(4);
155  const char *s_data;
156  const char *t_data;
157  int s_bytes,
158  t_bytes;
159 
160  /* Extract a pointer to the actual character data */
161  s_data = VARDATA_ANY(src);
162  t_data = VARDATA_ANY(dst);
163  /* Determine length of each string in bytes */
164  s_bytes = VARSIZE_ANY_EXHDR(src);
165  t_bytes = VARSIZE_ANY_EXHDR(dst);
166 
167  PG_RETURN_INT32(varstr_levenshtein(s_data, s_bytes, t_data, t_bytes,
168  ins_c, del_c, sub_c, false));
169 }
170 
171 
173 Datum
175 {
176  text *src = PG_GETARG_TEXT_PP(0);
177  text *dst = PG_GETARG_TEXT_PP(1);
178  const char *s_data;
179  const char *t_data;
180  int s_bytes,
181  t_bytes;
182 
183  /* Extract a pointer to the actual character data */
184  s_data = VARDATA_ANY(src);
185  t_data = VARDATA_ANY(dst);
186  /* Determine length of each string in bytes */
187  s_bytes = VARSIZE_ANY_EXHDR(src);
188  t_bytes = VARSIZE_ANY_EXHDR(dst);
189 
190  PG_RETURN_INT32(varstr_levenshtein(s_data, s_bytes, t_data, t_bytes,
191  1, 1, 1, false));
192 }
193 
194 
196 Datum
198 {
199  text *src = PG_GETARG_TEXT_PP(0);
200  text *dst = PG_GETARG_TEXT_PP(1);
201  int ins_c = PG_GETARG_INT32(2);
202  int del_c = PG_GETARG_INT32(3);
203  int sub_c = PG_GETARG_INT32(4);
204  int max_d = PG_GETARG_INT32(5);
205  const char *s_data;
206  const char *t_data;
207  int s_bytes,
208  t_bytes;
209 
210  /* Extract a pointer to the actual character data */
211  s_data = VARDATA_ANY(src);
212  t_data = VARDATA_ANY(dst);
213  /* Determine length of each string in bytes */
214  s_bytes = VARSIZE_ANY_EXHDR(src);
215  t_bytes = VARSIZE_ANY_EXHDR(dst);
216 
218  t_data, t_bytes,
219  ins_c, del_c, sub_c,
220  max_d, false));
221 }
222 
223 
225 Datum
227 {
228  text *src = PG_GETARG_TEXT_PP(0);
229  text *dst = PG_GETARG_TEXT_PP(1);
230  int max_d = PG_GETARG_INT32(2);
231  const char *s_data;
232  const char *t_data;
233  int s_bytes,
234  t_bytes;
235 
236  /* Extract a pointer to the actual character data */
237  s_data = VARDATA_ANY(src);
238  t_data = VARDATA_ANY(dst);
239  /* Determine length of each string in bytes */
240  s_bytes = VARSIZE_ANY_EXHDR(src);
241  t_bytes = VARSIZE_ANY_EXHDR(dst);
242 
244  t_data, t_bytes,
245  1, 1, 1,
246  max_d, false));
247 }
248 
249 
250 /*
251  * Calculates the metaphone of an input string.
252  * Returns number of characters requested
253  * (suggested value is 4)
254  */
256 Datum
258 {
259  char *str_i = TextDatumGetCString(PG_GETARG_DATUM(0));
260  size_t str_i_len = strlen(str_i);
261  int reqlen;
262  char *metaph;
263 
264  /* return an empty string if we receive one */
265  if (!(str_i_len > 0))
267 
268  if (str_i_len > MAX_METAPHONE_STRLEN)
269  ereport(ERROR,
270  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
271  errmsg("argument exceeds the maximum length of %d bytes",
273 
274  reqlen = PG_GETARG_INT32(1);
275  if (reqlen > MAX_METAPHONE_STRLEN)
276  ereport(ERROR,
277  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
278  errmsg("output exceeds the maximum length of %d bytes",
280 
281  if (!(reqlen > 0))
282  ereport(ERROR,
283  (errcode(ERRCODE_ZERO_LENGTH_CHARACTER_STRING),
284  errmsg("output cannot be empty string")));
285 
286  _metaphone(str_i, reqlen, &metaph);
288 }
289 
290 
291 /*
292  * Original code by Michael G Schwern starts here.
293  * Code slightly modified for use as PostgreSQL
294  * function (palloc, etc).
295  */
296 
297 /* I suppose I could have been using a character pointer instead of
298  * accessing the array directly... */
299 
300 /* Look at the next letter in the word */
301 #define Next_Letter (toupper((unsigned char) word[w_idx+1]))
302 /* Look at the current letter in the word */
303 #define Curr_Letter (toupper((unsigned char) word[w_idx]))
304 /* Go N letters back. */
305 #define Look_Back_Letter(n) \
306  (w_idx >= (n) ? toupper((unsigned char) word[w_idx-(n)]) : '\0')
307 /* Previous letter. I dunno, should this return null on failure? */
308 #define Prev_Letter (Look_Back_Letter(1))
309 /* Look two letters down. It makes sure you don't walk off the string. */
310 #define After_Next_Letter \
311  (Next_Letter != '\0' ? toupper((unsigned char) word[w_idx+2]) : '\0')
312 #define Look_Ahead_Letter(n) toupper((unsigned char) Lookahead(word+w_idx, n))
313 
314 
315 /* Allows us to safely look ahead an arbitrary # of letters */
316 /* I probably could have just used strlen... */
317 static char
318 Lookahead(char *word, int how_far)
319 {
320  char letter_ahead = '\0'; /* null by default */
321  int idx;
322 
323  for (idx = 0; word[idx] != '\0' && idx < how_far; idx++);
324  /* Edge forward in the string... */
325 
326  letter_ahead = word[idx]; /* idx will be either == to how_far or at the
327  * end of the string */
328  return letter_ahead;
329 }
330 
331 
332 /* phonize one letter */
333 #define Phonize(c) do {(*phoned_word)[p_idx++] = c;} while (0)
334 /* Slap a null character on the end of the phoned word */
335 #define End_Phoned_Word do {(*phoned_word)[p_idx] = '\0';} while (0)
336 /* How long is the phoned word? */
337 #define Phone_Len (p_idx)
338 
339 /* Note is a letter is a 'break' in the word */
340 #define Isbreak(c) (!isalpha((unsigned char) (c)))
341 
342 
343 static void
344 _metaphone(char *word, /* IN */
345  int max_phonemes,
346  char **phoned_word) /* OUT */
347 {
348  int w_idx = 0; /* point in the phonization we're at. */
349  int p_idx = 0; /* end of the phoned phrase */
350 
351  /*-- Parameter checks --*/
352 
353  /*
354  * Shouldn't be necessary, but left these here anyway jec Aug 3, 2001
355  */
356 
357  /* Negative phoneme length is meaningless */
358  if (!(max_phonemes > 0))
359  /* internal error */
360  elog(ERROR, "metaphone: Requested output length must be > 0");
361 
362  /* Empty/null string is meaningless */
363  if ((word == NULL) || !(strlen(word) > 0))
364  /* internal error */
365  elog(ERROR, "metaphone: Input string length must be > 0");
366 
367  /*-- Allocate memory for our phoned_phrase --*/
368  if (max_phonemes == 0)
369  { /* Assume largest possible */
370  *phoned_word = palloc(sizeof(char) * strlen(word) + 1);
371  }
372  else
373  {
374  *phoned_word = palloc(sizeof(char) * max_phonemes + 1);
375  }
376 
377  /*-- The first phoneme has to be processed specially. --*/
378  /* Find our first letter */
379  for (; !isalpha((unsigned char) (Curr_Letter)); w_idx++)
380  {
381  /* On the off chance we were given nothing but crap... */
382  if (Curr_Letter == '\0')
383  {
385  return;
386  }
387  }
388 
389  switch (Curr_Letter)
390  {
391  /* AE becomes E */
392  case 'A':
393  if (Next_Letter == 'E')
394  {
395  Phonize('E');
396  w_idx += 2;
397  }
398  /* Remember, preserve vowels at the beginning */
399  else
400  {
401  Phonize('A');
402  w_idx++;
403  }
404  break;
405  /* [GKP]N becomes N */
406  case 'G':
407  case 'K':
408  case 'P':
409  if (Next_Letter == 'N')
410  {
411  Phonize('N');
412  w_idx += 2;
413  }
414  break;
415 
416  /*
417  * WH becomes H, WR becomes R W if followed by a vowel
418  */
419  case 'W':
420  if (Next_Letter == 'H' ||
421  Next_Letter == 'R')
422  {
424  w_idx += 2;
425  }
426  else if (isvowel(Next_Letter))
427  {
428  Phonize('W');
429  w_idx += 2;
430  }
431  /* else ignore */
432  break;
433  /* X becomes S */
434  case 'X':
435  Phonize('S');
436  w_idx++;
437  break;
438  /* Vowels are kept */
439 
440  /*
441  * We did A already case 'A': case 'a':
442  */
443  case 'E':
444  case 'I':
445  case 'O':
446  case 'U':
448  w_idx++;
449  break;
450  default:
451  /* do nothing */
452  break;
453  }
454 
455 
456 
457  /* On to the metaphoning */
458  for (; Curr_Letter != '\0' &&
459  (max_phonemes == 0 || Phone_Len < max_phonemes);
460  w_idx++)
461  {
462  /*
463  * How many letters to skip because an earlier encoding handled
464  * multiple letters
465  */
466  unsigned short int skip_letter = 0;
467 
468 
469  /*
470  * THOUGHT: It would be nice if, rather than having things like...
471  * well, SCI. For SCI you encode the S, then have to remember to skip
472  * the C. So the phonome SCI invades both S and C. It would be
473  * better, IMHO, to skip the C from the S part of the encoding. Hell,
474  * I'm trying it.
475  */
476 
477  /* Ignore non-alphas */
478  if (!isalpha((unsigned char) (Curr_Letter)))
479  continue;
480 
481  /* Drop duplicates, except CC */
482  if (Curr_Letter == Prev_Letter &&
483  Curr_Letter != 'C')
484  continue;
485 
486  switch (Curr_Letter)
487  {
488  /* B -> B unless in MB */
489  case 'B':
490  if (Prev_Letter != 'M')
491  Phonize('B');
492  break;
493 
494  /*
495  * 'sh' if -CIA- or -CH, but not SCH, except SCHW. (SCHW is
496  * handled in S) S if -CI-, -CE- or -CY- dropped if -SCI-,
497  * SCE-, -SCY- (handed in S) else K
498  */
499  case 'C':
500  if (MAKESOFT(Next_Letter))
501  { /* C[IEY] */
502  if (After_Next_Letter == 'A' &&
503  Next_Letter == 'I')
504  { /* CIA */
505  Phonize(SH);
506  }
507  /* SC[IEY] */
508  else if (Prev_Letter == 'S')
509  {
510  /* Dropped */
511  }
512  else
513  Phonize('S');
514  }
515  else if (Next_Letter == 'H')
516  {
517 #ifndef USE_TRADITIONAL_METAPHONE
518  if (After_Next_Letter == 'R' ||
519  Prev_Letter == 'S')
520  { /* Christ, School */
521  Phonize('K');
522  }
523  else
524  Phonize(SH);
525 #else
526  Phonize(SH);
527 #endif
528  skip_letter++;
529  }
530  else
531  Phonize('K');
532  break;
533 
534  /*
535  * J if in -DGE-, -DGI- or -DGY- else T
536  */
537  case 'D':
538  if (Next_Letter == 'G' &&
540  {
541  Phonize('J');
542  skip_letter++;
543  }
544  else
545  Phonize('T');
546  break;
547 
548  /*
549  * F if in -GH and not B--GH, D--GH, -H--GH, -H---GH else
550  * dropped if -GNED, -GN, else dropped if -DGE-, -DGI- or
551  * -DGY- (handled in D) else J if in -GE-, -GI, -GY and not GG
552  * else K
553  */
554  case 'G':
555  if (Next_Letter == 'H')
556  {
557  if (!(NOGHTOF(Look_Back_Letter(3)) ||
558  Look_Back_Letter(4) == 'H'))
559  {
560  Phonize('F');
561  skip_letter++;
562  }
563  else
564  {
565  /* silent */
566  }
567  }
568  else if (Next_Letter == 'N')
569  {
570  if (Isbreak(After_Next_Letter) ||
571  (After_Next_Letter == 'E' &&
572  Look_Ahead_Letter(3) == 'D'))
573  {
574  /* dropped */
575  }
576  else
577  Phonize('K');
578  }
579  else if (MAKESOFT(Next_Letter) &&
580  Prev_Letter != 'G')
581  Phonize('J');
582  else
583  Phonize('K');
584  break;
585  /* H if before a vowel and not after C,G,P,S,T */
586  case 'H':
587  if (isvowel(Next_Letter) &&
589  Phonize('H');
590  break;
591 
592  /*
593  * dropped if after C else K
594  */
595  case 'K':
596  if (Prev_Letter != 'C')
597  Phonize('K');
598  break;
599 
600  /*
601  * F if before H else P
602  */
603  case 'P':
604  if (Next_Letter == 'H')
605  Phonize('F');
606  else
607  Phonize('P');
608  break;
609 
610  /*
611  * K
612  */
613  case 'Q':
614  Phonize('K');
615  break;
616 
617  /*
618  * 'sh' in -SH-, -SIO- or -SIA- or -SCHW- else S
619  */
620  case 'S':
621  if (Next_Letter == 'I' &&
622  (After_Next_Letter == 'O' ||
623  After_Next_Letter == 'A'))
624  Phonize(SH);
625  else if (Next_Letter == 'H')
626  {
627  Phonize(SH);
628  skip_letter++;
629  }
630 #ifndef USE_TRADITIONAL_METAPHONE
631  else if (Next_Letter == 'C' &&
632  Look_Ahead_Letter(2) == 'H' &&
633  Look_Ahead_Letter(3) == 'W')
634  {
635  Phonize(SH);
636  skip_letter += 2;
637  }
638 #endif
639  else
640  Phonize('S');
641  break;
642 
643  /*
644  * 'sh' in -TIA- or -TIO- else 'th' before H else T
645  */
646  case 'T':
647  if (Next_Letter == 'I' &&
648  (After_Next_Letter == 'O' ||
649  After_Next_Letter == 'A'))
650  Phonize(SH);
651  else if (Next_Letter == 'H')
652  {
653  Phonize(TH);
654  skip_letter++;
655  }
656  else
657  Phonize('T');
658  break;
659  /* F */
660  case 'V':
661  Phonize('F');
662  break;
663  /* W before a vowel, else dropped */
664  case 'W':
665  if (isvowel(Next_Letter))
666  Phonize('W');
667  break;
668  /* KS */
669  case 'X':
670  Phonize('K');
671  if (max_phonemes == 0 || Phone_Len < max_phonemes)
672  Phonize('S');
673  break;
674  /* Y if followed by a vowel */
675  case 'Y':
676  if (isvowel(Next_Letter))
677  Phonize('Y');
678  break;
679  /* S */
680  case 'Z':
681  Phonize('S');
682  break;
683  /* No transformation */
684  case 'F':
685  case 'J':
686  case 'L':
687  case 'M':
688  case 'N':
689  case 'R':
691  break;
692  default:
693  /* nothing */
694  break;
695  } /* END SWITCH */
696 
697  w_idx += skip_letter;
698  } /* END FOR */
699 
701 } /* END metaphone */
702 
703 
704 /*
705  * SQL function: soundex(text) returns text
706  */
708 
709 Datum
711 {
712  char outstr[SOUNDEX_LEN + 1];
713  char *arg;
714 
716 
717  _soundex(arg, outstr);
718 
720 }
721 
722 static void
723 _soundex(const char *instr, char *outstr)
724 {
725  int count;
726 
727  Assert(instr);
728  Assert(outstr);
729 
730  /* Skip leading non-alphabetic characters */
731  while (*instr && !isalpha((unsigned char) *instr))
732  ++instr;
733 
734  /* If no string left, return all-zeroes buffer */
735  if (!*instr)
736  {
737  memset(outstr, '\0', SOUNDEX_LEN + 1);
738  return;
739  }
740 
741  /* Take the first letter as is */
742  *outstr++ = (char) toupper((unsigned char) *instr++);
743 
744  count = 1;
745  while (*instr && count < SOUNDEX_LEN)
746  {
747  if (isalpha((unsigned char) *instr) &&
748  soundex_code(*instr) != soundex_code(*(instr - 1)))
749  {
750  *outstr = soundex_code(*instr);
751  if (*outstr != '0')
752  {
753  ++outstr;
754  ++count;
755  }
756  }
757  ++instr;
758  }
759 
760  /* Fill with 0's */
761  while (count < SOUNDEX_LEN)
762  {
763  *outstr = '0';
764  ++outstr;
765  ++count;
766  }
767 
768  /* And null-terminate */
769  *outstr = '\0';
770 }
771 
773 
774 Datum
776 {
777  char sndx1[SOUNDEX_LEN + 1],
778  sndx2[SOUNDEX_LEN + 1];
779  int i,
780  result;
781 
784 
785  result = 0;
786  for (i = 0; i < SOUNDEX_LEN; i++)
787  {
788  if (sndx1[i] == sndx2[i])
789  result++;
790  }
791 
792  PG_RETURN_INT32(result);
793 }
Datum idx(PG_FUNCTION_ARGS)
Definition: _int_op.c:259
#define TextDatumGetCString(d)
Definition: builtins.h:98
#define Assert(condition)
Definition: c.h:863
int errcode(int sqlerrcode)
Definition: elog.c:853
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:225
#define ereport(elevel,...)
Definition: elog.h:149
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:268
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:372
#define PG_RETURN_INT32(x)
Definition: fmgr.h:354
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define PG_FUNCTION_ARGS
Definition: fmgr.h:193
Datum metaphone(PG_FUNCTION_ARGS)
static void _metaphone(char *word, int max_phonemes, char **phoned_word)
#define SOUNDEX_LEN
Definition: fuzzystrmatch.c:54
#define After_Next_Letter
Datum levenshtein_less_equal_with_costs(PG_FUNCTION_ARGS)
#define Look_Back_Letter(n)
#define Curr_Letter
static const char *const soundex_table
Definition: fuzzystrmatch.c:57
#define SH
#define MAKESOFT(c)
PG_MODULE_MAGIC
Definition: fuzzystrmatch.c:47
Datum soundex(PG_FUNCTION_ARGS)
static char soundex_code(char letter)
Definition: fuzzystrmatch.c:60
static const char _codes[26]
Datum levenshtein_with_costs(PG_FUNCTION_ARGS)
#define Isbreak(c)
#define End_Phoned_Word
#define isvowel(c)
#define Prev_Letter
#define TH
#define NOGHTOF(c)
#define Next_Letter
static void _soundex(const char *instr, char *outstr)
#define Phonize(c)
static int getcode(char c)
Datum difference(PG_FUNCTION_ARGS)
#define MAX_METAPHONE_STRLEN
Definition: fuzzystrmatch.c:72
static char Lookahead(char *word, int how_far)
#define AFFECTH(c)
#define Phone_Len
Datum levenshtein_less_equal(PG_FUNCTION_ARGS)
#define Look_Ahead_Letter(n)
PG_FUNCTION_INFO_V1(levenshtein_with_costs)
Datum levenshtein(PG_FUNCTION_ARGS)
int i
Definition: isn.c:72
int varstr_levenshtein(const char *source, int slen, const char *target, int tlen, int ins_c, int del_c, int sub_c, bool trusted)
Definition: levenshtein.c:73
void * palloc(Size size)
Definition: mcxt.c:1317
void * arg
uintptr_t Datum
Definition: postgres.h:64
char * c
static void word(struct vars *v, int dir, struct state *lp, struct state *rp)
Definition: regcomp.c:1476
Definition: c.h:692
#define VARDATA_ANY(PTR)
Definition: varatt.h:324
#define VARSIZE_ANY_EXHDR(PTR)
Definition: varatt.h:317
char * text_to_cstring(const text *t)
Definition: varlena.c:217
text * cstring_to_text(const char *s)
Definition: varlena.c:184
int varstr_levenshtein_less_equal(const char *source, int slen, const char *target, int tlen, int ins_c, int del_c, int sub_c, int max_d, bool trusted)