PostgreSQL Source Code git master
Loading...
Searching...
No Matches
fuzzystrmatch.c File Reference
#include "postgres.h"
#include <ctype.h>
#include "utils/builtins.h"
#include "utils/varlena.h"
#include "varatt.h"
Include dependency graph for fuzzystrmatch.c:

Go to the source code of this file.

Macros

#define SOUNDEX_LEN   4
 
#define MAX_METAPHONE_STRLEN   255
 
#define SH   'X'
 
#define TH   '0'
 
#define isvowel(c)   (getcode(c) & 1) /* AEIOU */
 
#define NOCHANGE(c)   (getcode(c) & 2) /* FJMNR */
 
#define AFFECTH(c)   (getcode(c) & 4) /* CGPST */
 
#define MAKESOFT(c)   (getcode(c) & 8) /* EIY */
 
#define NOGHTOF(c)   (getcode(c) & 16) /* BDH */
 
#define Next_Letter   (pg_ascii_toupper((unsigned char) word[w_idx+1]))
 
#define Curr_Letter   (pg_ascii_toupper((unsigned char) word[w_idx]))
 
#define Look_Back_Letter(n)    (w_idx >= (n) ? pg_ascii_toupper((unsigned char) word[w_idx-(n)]) : '\0')
 
#define Prev_Letter   (Look_Back_Letter(1))
 
#define After_Next_Letter    (Next_Letter != '\0' ? pg_ascii_toupper((unsigned char) word[w_idx+2]) : '\0')
 
#define Look_Ahead_Letter(n)   pg_ascii_toupper((unsigned char) Lookahead(word+w_idx, n))
 
#define Phonize(c)   do {(*phoned_word)[p_idx++] = c;} while (0)
 
#define End_Phoned_Word   do {(*phoned_word)[p_idx] = '\0';} while (0)
 
#define Phone_Len   (p_idx)
 
#define Isbreak(c)   (!ascii_isalpha((unsigned char) (c)))
 

Functions

 PG_MODULE_MAGIC_EXT (.name="fuzzystrmatch",.version=PG_VERSION)
 
static void _soundex (const char *instr, char *outstr)
 
static char soundex_code (char letter)
 
static char Lookahead (char *word, int how_far)
 
static void _metaphone (char *word, int max_phonemes, char **phoned_word)
 
static int getcode (char c)
 
static bool ascii_isalpha (char c)
 
 PG_FUNCTION_INFO_V1 (levenshtein_with_costs)
 
Datum levenshtein_with_costs (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (levenshtein)
 
Datum levenshtein (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (levenshtein_less_equal_with_costs)
 
Datum levenshtein_less_equal_with_costs (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (levenshtein_less_equal)
 
Datum levenshtein_less_equal (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (metaphone)
 
Datum metaphone (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (soundex)
 
Datum soundex (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (difference)
 
Datum difference (PG_FUNCTION_ARGS)
 

Variables

static const char *const soundex_table = "01230120022455012623010202"
 
static const char _codes [26]
 

Macro Definition Documentation

◆ AFFECTH

#define AFFECTH (   c)    (getcode(c) & 4) /* CGPST */

Definition at line 148 of file fuzzystrmatch.c.

◆ After_Next_Letter

#define After_Next_Letter    (Next_Letter != '\0' ? pg_ascii_toupper((unsigned char) word[w_idx+2]) : '\0')

Definition at line 322 of file fuzzystrmatch.c.

323 : '\0')

◆ Curr_Letter

#define Curr_Letter   (pg_ascii_toupper((unsigned char) word[w_idx]))

Definition at line 315 of file fuzzystrmatch.c.

◆ End_Phoned_Word

#define End_Phoned_Word   do {(*phoned_word)[p_idx] = '\0';} while (0)

Definition at line 347 of file fuzzystrmatch.c.

◆ Isbreak

#define Isbreak (   c)    (!ascii_isalpha((unsigned char) (c)))

Definition at line 352 of file fuzzystrmatch.c.

◆ isvowel

#define isvowel (   c)    (getcode(c) & 1) /* AEIOU */

Definition at line 142 of file fuzzystrmatch.c.

◆ Look_Ahead_Letter

#define Look_Ahead_Letter (   n)    pg_ascii_toupper((unsigned char) Lookahead(word+w_idx, n))

Definition at line 324 of file fuzzystrmatch.c.

◆ Look_Back_Letter

#define Look_Back_Letter (   n)     (w_idx >= (n) ? pg_ascii_toupper((unsigned char) word[w_idx-(n)]) : '\0')

Definition at line 317 of file fuzzystrmatch.c.

318 : '\0')

◆ MAKESOFT

#define MAKESOFT (   c)    (getcode(c) & 8) /* EIY */

Definition at line 151 of file fuzzystrmatch.c.

◆ MAX_METAPHONE_STRLEN

#define MAX_METAPHONE_STRLEN   255

Definition at line 75 of file fuzzystrmatch.c.

◆ Next_Letter

#define Next_Letter   (pg_ascii_toupper((unsigned char) word[w_idx+1]))

Definition at line 313 of file fuzzystrmatch.c.

◆ NOCHANGE

#define NOCHANGE (   c)    (getcode(c) & 2) /* FJMNR */

Definition at line 145 of file fuzzystrmatch.c.

◆ NOGHTOF

#define NOGHTOF (   c)    (getcode(c) & 16) /* BDH */

Definition at line 154 of file fuzzystrmatch.c.

◆ Phone_Len

#define Phone_Len   (p_idx)

Definition at line 349 of file fuzzystrmatch.c.

◆ Phonize

#define Phonize (   c)    do {(*phoned_word)[p_idx++] = c;} while (0)

Definition at line 345 of file fuzzystrmatch.c.

◆ Prev_Letter

#define Prev_Letter   (Look_Back_Letter(1))

Definition at line 320 of file fuzzystrmatch.c.

◆ SH

#define SH   'X'

Definition at line 108 of file fuzzystrmatch.c.

◆ SOUNDEX_LEN

#define SOUNDEX_LEN   4

Definition at line 57 of file fuzzystrmatch.c.

◆ TH

#define TH   '0'

Definition at line 109 of file fuzzystrmatch.c.

Function Documentation

◆ _metaphone()

static void _metaphone ( char word,
int  max_phonemes,
char **  phoned_word 
)
static

Definition at line 356 of file fuzzystrmatch.c.

359{
360 int w_idx = 0; /* point in the phonization we're at. */
361 int p_idx = 0; /* end of the phoned phrase */
362
363 /*-- Parameter checks --*/
364
365 /*
366 * Shouldn't be necessary, but left these here anyway jec Aug 3, 2001
367 */
368
369 /* Negative phoneme length is meaningless */
370 if (!(max_phonemes > 0))
371 /* internal error */
372 elog(ERROR, "metaphone: Requested output length must be > 0");
373
374 /* Empty/null string is meaningless */
375 if ((word == NULL) || !(strlen(word) > 0))
376 /* internal error */
377 elog(ERROR, "metaphone: Input string length must be > 0");
378
379 /*-- Allocate memory for our phoned_phrase --*/
380 if (max_phonemes == 0)
381 { /* Assume largest possible */
382 *phoned_word = palloc(sizeof(char) * strlen(word) + 1);
383 }
384 else
385 {
386 *phoned_word = palloc(sizeof(char) * max_phonemes + 1);
387 }
388
389 /*-- The first phoneme has to be processed specially. --*/
390 /* Find our first letter */
391 for (; !ascii_isalpha((unsigned char) (Curr_Letter)); w_idx++)
392 {
393 /* On the off chance we were given nothing but crap... */
394 if (Curr_Letter == '\0')
395 {
397 return;
398 }
399 }
400
401 switch (Curr_Letter)
402 {
403 /* AE becomes E */
404 case 'A':
405 if (Next_Letter == 'E')
406 {
407 Phonize('E');
408 w_idx += 2;
409 }
410 /* Remember, preserve vowels at the beginning */
411 else
412 {
413 Phonize('A');
414 w_idx++;
415 }
416 break;
417 /* [GKP]N becomes N */
418 case 'G':
419 case 'K':
420 case 'P':
421 if (Next_Letter == 'N')
422 {
423 Phonize('N');
424 w_idx += 2;
425 }
426 break;
427
428 /*
429 * WH becomes H, WR becomes R W if followed by a vowel
430 */
431 case 'W':
432 if (Next_Letter == 'H' ||
433 Next_Letter == 'R')
434 {
436 w_idx += 2;
437 }
438 else if (isvowel(Next_Letter))
439 {
440 Phonize('W');
441 w_idx += 2;
442 }
443 /* else ignore */
444 break;
445 /* X becomes S */
446 case 'X':
447 Phonize('S');
448 w_idx++;
449 break;
450 /* Vowels are kept */
451
452 /*
453 * We did A already case 'A': case 'a':
454 */
455 case 'E':
456 case 'I':
457 case 'O':
458 case 'U':
460 w_idx++;
461 break;
462 default:
463 /* do nothing */
464 break;
465 }
466
467
468
469 /* On to the metaphoning */
470 for (; Curr_Letter != '\0' &&
472 w_idx++)
473 {
474 /*
475 * How many letters to skip because an earlier encoding handled
476 * multiple letters
477 */
478 unsigned short int skip_letter = 0;
479
480
481 /*
482 * THOUGHT: It would be nice if, rather than having things like...
483 * well, SCI. For SCI you encode the S, then have to remember to skip
484 * the C. So the phonome SCI invades both S and C. It would be
485 * better, IMHO, to skip the C from the S part of the encoding. Hell,
486 * I'm trying it.
487 */
488
489 /* Ignore non-alphas */
490 if (!ascii_isalpha((unsigned char) (Curr_Letter)))
491 continue;
492
493 /* Drop duplicates, except CC */
494 if (Curr_Letter == Prev_Letter &&
495 Curr_Letter != 'C')
496 continue;
497
498 switch (Curr_Letter)
499 {
500 /* B -> B unless in MB */
501 case 'B':
502 if (Prev_Letter != 'M')
503 Phonize('B');
504 break;
505
506 /*
507 * 'sh' if -CIA- or -CH, but not SCH, except SCHW. (SCHW is
508 * handled in S) S if -CI-, -CE- or -CY- dropped if -SCI-,
509 * SCE-, -SCY- (handed in S) else K
510 */
511 case 'C':
513 { /* C[IEY] */
514 if (After_Next_Letter == 'A' &&
515 Next_Letter == 'I')
516 { /* CIA */
517 Phonize(SH);
518 }
519 /* SC[IEY] */
520 else if (Prev_Letter == 'S')
521 {
522 /* Dropped */
523 }
524 else
525 Phonize('S');
526 }
527 else if (Next_Letter == 'H')
528 {
529#ifndef USE_TRADITIONAL_METAPHONE
530 if (After_Next_Letter == 'R' ||
531 Prev_Letter == 'S')
532 { /* Christ, School */
533 Phonize('K');
534 }
535 else
536 Phonize(SH);
537#else
538 Phonize(SH);
539#endif
540 skip_letter++;
541 }
542 else
543 Phonize('K');
544 break;
545
546 /*
547 * J if in -DGE-, -DGI- or -DGY- else T
548 */
549 case 'D':
550 if (Next_Letter == 'G' &&
552 {
553 Phonize('J');
554 skip_letter++;
555 }
556 else
557 Phonize('T');
558 break;
559
560 /*
561 * F if in -GH and not B--GH, D--GH, -H--GH, -H---GH else
562 * dropped if -GNED, -GN, else dropped if -DGE-, -DGI- or
563 * -DGY- (handled in D) else J if in -GE-, -GI, -GY and not GG
564 * else K
565 */
566 case 'G':
567 if (Next_Letter == 'H')
568 {
569 if (!(NOGHTOF(Look_Back_Letter(3)) ||
570 Look_Back_Letter(4) == 'H'))
571 {
572 Phonize('F');
573 skip_letter++;
574 }
575 else
576 {
577 /* silent */
578 }
579 }
580 else if (Next_Letter == 'N')
581 {
583 (After_Next_Letter == 'E' &&
584 Look_Ahead_Letter(3) == 'D'))
585 {
586 /* dropped */
587 }
588 else
589 Phonize('K');
590 }
591 else if (MAKESOFT(Next_Letter) &&
592 Prev_Letter != 'G')
593 Phonize('J');
594 else
595 Phonize('K');
596 break;
597 /* H if before a vowel and not after C,G,P,S,T */
598 case 'H':
599 if (isvowel(Next_Letter) &&
601 Phonize('H');
602 break;
603
604 /*
605 * dropped if after C else K
606 */
607 case 'K':
608 if (Prev_Letter != 'C')
609 Phonize('K');
610 break;
611
612 /*
613 * F if before H else P
614 */
615 case 'P':
616 if (Next_Letter == 'H')
617 Phonize('F');
618 else
619 Phonize('P');
620 break;
621
622 /*
623 * K
624 */
625 case 'Q':
626 Phonize('K');
627 break;
628
629 /*
630 * 'sh' in -SH-, -SIO- or -SIA- or -SCHW- else S
631 */
632 case 'S':
633 if (Next_Letter == 'I' &&
634 (After_Next_Letter == 'O' ||
635 After_Next_Letter == 'A'))
636 Phonize(SH);
637 else if (Next_Letter == 'H')
638 {
639 Phonize(SH);
640 skip_letter++;
641 }
642#ifndef USE_TRADITIONAL_METAPHONE
643 else if (Next_Letter == 'C' &&
644 Look_Ahead_Letter(2) == 'H' &&
645 Look_Ahead_Letter(3) == 'W')
646 {
647 Phonize(SH);
648 skip_letter += 2;
649 }
650#endif
651 else
652 Phonize('S');
653 break;
654
655 /*
656 * 'sh' in -TIA- or -TIO- else 'th' before H else T
657 */
658 case 'T':
659 if (Next_Letter == 'I' &&
660 (After_Next_Letter == 'O' ||
661 After_Next_Letter == 'A'))
662 Phonize(SH);
663 else if (Next_Letter == 'H')
664 {
665 Phonize(TH);
666 skip_letter++;
667 }
668 else
669 Phonize('T');
670 break;
671 /* F */
672 case 'V':
673 Phonize('F');
674 break;
675 /* W before a vowel, else dropped */
676 case 'W':
677 if (isvowel(Next_Letter))
678 Phonize('W');
679 break;
680 /* KS */
681 case 'X':
682 Phonize('K');
683 if (max_phonemes == 0 || Phone_Len < max_phonemes)
684 Phonize('S');
685 break;
686 /* Y if followed by a vowel */
687 case 'Y':
688 if (isvowel(Next_Letter))
689 Phonize('Y');
690 break;
691 /* S */
692 case 'Z':
693 Phonize('S');
694 break;
695 /* No transformation */
696 case 'F':
697 case 'J':
698 case 'L':
699 case 'M':
700 case 'N':
701 case 'R':
703 break;
704 default:
705 /* nothing */
706 break;
707 } /* END SWITCH */
708
710 } /* END FOR */
711
713} /* END metaphone */
#define ERROR
Definition elog.h:40
#define elog(elevel,...)
Definition elog.h:228
#define After_Next_Letter
#define Look_Back_Letter(n)
#define Curr_Letter
#define SH
#define MAKESOFT(c)
#define Isbreak(c)
#define End_Phoned_Word
#define isvowel(c)
#define Prev_Letter
static bool ascii_isalpha(char c)
#define TH
#define NOGHTOF(c)
#define Next_Letter
#define Phonize(c)
#define AFFECTH(c)
#define Phone_Len
#define Look_Ahead_Letter(n)
void * palloc(Size size)
Definition mcxt.c:1390
static int fb(int x)
static void word(struct vars *v, int dir, struct state *lp, struct state *rp)
Definition regcomp.c:1477

References AFFECTH, After_Next_Letter, ascii_isalpha(), Curr_Letter, elog, End_Phoned_Word, ERROR, fb(), Isbreak, isvowel, Look_Ahead_Letter, Look_Back_Letter, MAKESOFT, Next_Letter, NOGHTOF, palloc(), Phone_Len, Phonize, Prev_Letter, SH, TH, and word().

Referenced by metaphone().

◆ _soundex()

static void _soundex ( const char instr,
char outstr 
)
static

Definition at line 735 of file fuzzystrmatch.c.

736{
737 int count;
738
739 Assert(instr);
740 Assert(outstr);
741
742 /* Skip leading non-alphabetic characters */
743 while (*instr && !ascii_isalpha((unsigned char) *instr))
744 ++instr;
745
746 /* If no string left, return all-zeroes buffer */
747 if (!*instr)
748 {
749 memset(outstr, '\0', SOUNDEX_LEN + 1);
750 return;
751 }
752
753 /* Take the first letter as is */
754 *outstr++ = (char) pg_ascii_toupper((unsigned char) *instr++);
755
756 count = 1;
757 while (*instr && count < SOUNDEX_LEN)
758 {
759 if (ascii_isalpha((unsigned char) *instr) &&
760 soundex_code(*instr) != soundex_code(*(instr - 1)))
761 {
762 *outstr = soundex_code(*instr);
763 if (*outstr != '0')
764 {
765 ++outstr;
766 ++count;
767 }
768 }
769 ++instr;
770 }
771
772 /* Fill with 0's */
773 while (count < SOUNDEX_LEN)
774 {
775 *outstr = '0';
776 ++outstr;
777 ++count;
778 }
779
780 /* And null-terminate */
781 *outstr = '\0';
782}
#define Assert(condition)
Definition c.h:943
#define SOUNDEX_LEN
static char soundex_code(char letter)
static unsigned char pg_ascii_toupper(unsigned char ch)
Definition port.h:178

References ascii_isalpha(), Assert, fb(), pg_ascii_toupper(), soundex_code(), and SOUNDEX_LEN.

Referenced by difference(), and soundex().

◆ ascii_isalpha()

static bool ascii_isalpha ( char  c)
static

Definition at line 136 of file fuzzystrmatch.c.

137{
138 return (c >= 'A' && c <= 'Z') ||
139 (c >= 'a' && c <= 'z');
140}
char * c

Referenced by _metaphone(), and _soundex().

◆ difference()

Datum difference ( PG_FUNCTION_ARGS  )

Definition at line 787 of file fuzzystrmatch.c.

788{
789 char sndx1[SOUNDEX_LEN + 1],
790 sndx2[SOUNDEX_LEN + 1];
791 int i,
792 result;
793
796
797 result = 0;
798 for (i = 0; i < SOUNDEX_LEN; i++)
799 {
800 if (sndx1[i] == sndx2[i])
801 result++;
802 }
803
805}
uint32 result
#define PG_GETARG_TEXT_PP(n)
Definition fmgr.h:310
#define PG_RETURN_INT32(x)
Definition fmgr.h:355
static void _soundex(const char *instr, char *outstr)
int i
Definition isn.c:77
char * text_to_cstring(const text *t)
Definition varlena.c:217

References _soundex(), fb(), i, PG_GETARG_TEXT_PP, PG_RETURN_INT32, result, SOUNDEX_LEN, and text_to_cstring().

Referenced by checkcondition_str(), ExtendMultiXactMember(), find_wordentry(), getKeyJsonValueFromContainer(), hstore_concat(), hstore_delete_array(), hstore_delete_hstore(), hstore_subscript_assign(), and hstoreFindKey().

◆ getcode()

static int getcode ( char  c)
static

Definition at line 125 of file fuzzystrmatch.c.

126{
127 c = pg_ascii_toupper((unsigned char) c);
128 /* Defend against non-ASCII letters */
129 if (c >= 'A' && c <= 'Z')
130 return _codes[c - 'A'];
131
132 return 0;
133}
static const char _codes[26]

References _codes, and pg_ascii_toupper().

◆ levenshtein()

Datum levenshtein ( PG_FUNCTION_ARGS  )

Definition at line 184 of file fuzzystrmatch.c.

185{
186 text *src = PG_GETARG_TEXT_PP(0);
188 const char *s_data;
189 const char *t_data;
190 int s_bytes,
191 t_bytes;
192
193 /* Extract a pointer to the actual character data */
194 s_data = VARDATA_ANY(src);
195 t_data = VARDATA_ANY(dst);
196 /* Determine length of each string in bytes */
199
201 1, 1, 1, false));
202}
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
Definition c.h:776
static Size VARSIZE_ANY_EXHDR(const void *PTR)
Definition varatt.h:472
static char * VARDATA_ANY(const void *PTR)
Definition varatt.h:486

References fb(), PG_GETARG_TEXT_PP, PG_RETURN_INT32, VARDATA_ANY(), VARSIZE_ANY_EXHDR(), and varstr_levenshtein().

◆ levenshtein_less_equal()

Datum levenshtein_less_equal ( PG_FUNCTION_ARGS  )

Definition at line 236 of file fuzzystrmatch.c.

237{
238 text *src = PG_GETARG_TEXT_PP(0);
240 int max_d = PG_GETARG_INT32(2);
241 const char *s_data;
242 const char *t_data;
243 int s_bytes,
244 t_bytes;
245
246 /* Extract a pointer to the actual character data */
247 s_data = VARDATA_ANY(src);
248 t_data = VARDATA_ANY(dst);
249 /* Determine length of each string in bytes */
252
254 t_data, t_bytes,
255 1, 1, 1,
256 max_d, false));
257}
#define PG_GETARG_INT32(n)
Definition fmgr.h:269
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)

References fb(), PG_GETARG_INT32, PG_GETARG_TEXT_PP, PG_RETURN_INT32, VARDATA_ANY(), VARSIZE_ANY_EXHDR(), and varstr_levenshtein_less_equal().

◆ levenshtein_less_equal_with_costs()

Datum levenshtein_less_equal_with_costs ( PG_FUNCTION_ARGS  )

Definition at line 207 of file fuzzystrmatch.c.

208{
209 text *src = PG_GETARG_TEXT_PP(0);
211 int ins_c = PG_GETARG_INT32(2);
212 int del_c = PG_GETARG_INT32(3);
213 int sub_c = PG_GETARG_INT32(4);
214 int max_d = PG_GETARG_INT32(5);
215 const char *s_data;
216 const char *t_data;
217 int s_bytes,
218 t_bytes;
219
220 /* Extract a pointer to the actual character data */
221 s_data = VARDATA_ANY(src);
222 t_data = VARDATA_ANY(dst);
223 /* Determine length of each string in bytes */
226
228 t_data, t_bytes,
229 ins_c, del_c, sub_c,
230 max_d, false));
231}

References fb(), PG_GETARG_INT32, PG_GETARG_TEXT_PP, PG_RETURN_INT32, VARDATA_ANY(), VARSIZE_ANY_EXHDR(), and varstr_levenshtein_less_equal().

◆ levenshtein_with_costs()

Datum levenshtein_with_costs ( PG_FUNCTION_ARGS  )

Definition at line 158 of file fuzzystrmatch.c.

159{
160 text *src = PG_GETARG_TEXT_PP(0);
162 int ins_c = PG_GETARG_INT32(2);
163 int del_c = PG_GETARG_INT32(3);
164 int sub_c = PG_GETARG_INT32(4);
165 const char *s_data;
166 const char *t_data;
167 int s_bytes,
168 t_bytes;
169
170 /* Extract a pointer to the actual character data */
171 s_data = VARDATA_ANY(src);
172 t_data = VARDATA_ANY(dst);
173 /* Determine length of each string in bytes */
176
178 ins_c, del_c, sub_c, false));
179}

References fb(), PG_GETARG_INT32, PG_GETARG_TEXT_PP, PG_RETURN_INT32, VARDATA_ANY(), VARSIZE_ANY_EXHDR(), and varstr_levenshtein().

◆ Lookahead()

static char Lookahead ( char word,
int  how_far 
)
static

Definition at line 330 of file fuzzystrmatch.c.

331{
332 char letter_ahead = '\0'; /* null by default */
333 int idx;
334
335 for (idx = 0; word[idx] != '\0' && idx < how_far; idx++);
336 /* Edge forward in the string... */
337
338 letter_ahead = word[idx]; /* idx will be either == to how_far or at the
339 * end of the string */
340 return letter_ahead;
341}
Datum idx(PG_FUNCTION_ARGS)
Definition _int_op.c:263

References fb(), idx(), and word().

◆ metaphone()

Datum metaphone ( PG_FUNCTION_ARGS  )

Definition at line 267 of file fuzzystrmatch.c.

268{
270 size_t str_i_len = strlen(str_i);
271 int reqlen;
272 char *metaph;
273
274 /* return an empty string if we receive one */
275 if (!(str_i_len > 0))
277
281 errmsg("argument exceeds the maximum length of %d bytes",
283
288 errmsg("output exceeds the maximum length of %d bytes",
290
291 if (!(reqlen > 0))
294 errmsg("output cannot be empty string")));
295
298}
#define TextDatumGetCString(d)
Definition builtins.h:99
int errcode(int sqlerrcode)
Definition elog.c:875
#define ereport(elevel,...)
Definition elog.h:152
#define PG_GETARG_DATUM(n)
Definition fmgr.h:268
#define PG_RETURN_TEXT_P(x)
Definition fmgr.h:374
static void _metaphone(char *word, int max_phonemes, char **phoned_word)
#define MAX_METAPHONE_STRLEN
static char * errmsg
text * cstring_to_text(const char *s)
Definition varlena.c:184

References _metaphone(), cstring_to_text(), ereport, errcode(), errmsg, ERROR, fb(), MAX_METAPHONE_STRLEN, PG_GETARG_DATUM, PG_GETARG_INT32, PG_RETURN_TEXT_P, and TextDatumGetCString.

◆ PG_FUNCTION_INFO_V1() [1/7]

PG_FUNCTION_INFO_V1 ( difference  )

◆ PG_FUNCTION_INFO_V1() [2/7]

PG_FUNCTION_INFO_V1 ( levenshtein  )

◆ PG_FUNCTION_INFO_V1() [3/7]

PG_FUNCTION_INFO_V1 ( levenshtein_less_equal  )

◆ PG_FUNCTION_INFO_V1() [4/7]

PG_FUNCTION_INFO_V1 ( levenshtein_less_equal_with_costs  )

◆ PG_FUNCTION_INFO_V1() [5/7]

PG_FUNCTION_INFO_V1 ( levenshtein_with_costs  )

◆ PG_FUNCTION_INFO_V1() [6/7]

PG_FUNCTION_INFO_V1 ( metaphone  )

◆ PG_FUNCTION_INFO_V1() [7/7]

PG_FUNCTION_INFO_V1 ( soundex  )

◆ PG_MODULE_MAGIC_EXT()

PG_MODULE_MAGIC_EXT ( name = "fuzzystrmatch",
version = PG_VERSION 
)

◆ soundex()

◆ soundex_code()

static char soundex_code ( char  letter)
static

Definition at line 63 of file fuzzystrmatch.c.

64{
65 letter = pg_ascii_toupper((unsigned char) letter);
66 /* Defend against non-ASCII letters */
67 if (letter >= 'A' && letter <= 'Z')
68 return soundex_table[letter - 'A'];
69 return letter;
70}
static const char *const soundex_table

References fb(), pg_ascii_toupper(), and soundex_table.

Referenced by _soundex().

Variable Documentation

◆ _codes

const char _codes[26]
static
Initial value:
= {
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
}

Definition at line 119 of file fuzzystrmatch.c.

119 {
120 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
121/* 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 */
122};

Referenced by getcode().

◆ soundex_table

const char* const soundex_table = "01230120022455012623010202"
static

Definition at line 60 of file fuzzystrmatch.c.

Referenced by soundex_code().