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