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 146 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 318 of file fuzzystrmatch.c.

319 : '\0')

◆ Curr_Letter

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

Definition at line 311 of file fuzzystrmatch.c.

◆ End_Phoned_Word

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

Definition at line 343 of file fuzzystrmatch.c.

◆ Isbreak

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

Definition at line 348 of file fuzzystrmatch.c.

◆ isvowel

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

Definition at line 140 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 320 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 313 of file fuzzystrmatch.c.

314 : '\0')

◆ MAKESOFT

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

Definition at line 149 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 309 of file fuzzystrmatch.c.

◆ NOCHANGE

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

Definition at line 143 of file fuzzystrmatch.c.

◆ NOGHTOF

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

Definition at line 152 of file fuzzystrmatch.c.

◆ Phone_Len

#define Phone_Len   (p_idx)

Definition at line 345 of file fuzzystrmatch.c.

◆ Phonize

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

Definition at line 341 of file fuzzystrmatch.c.

◆ Prev_Letter

#define Prev_Letter   (Look_Back_Letter(1))

Definition at line 316 of file fuzzystrmatch.c.

◆ SH

#define SH   'X'

Definition at line 106 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 107 of file fuzzystrmatch.c.

Function Documentation

◆ _metaphone()

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

Definition at line 352 of file fuzzystrmatch.c.

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

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 731 of file fuzzystrmatch.c.

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

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 134 of file fuzzystrmatch.c.

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

Referenced by _metaphone(), and _soundex().

◆ difference()

Datum difference ( PG_FUNCTION_ARGS  )

Definition at line 783 of file fuzzystrmatch.c.

784{
785 char sndx1[SOUNDEX_LEN + 1],
786 sndx2[SOUNDEX_LEN + 1];
787 int i,
788 result;
789
792
793 result = 0;
794 for (i = 0; i < SOUNDEX_LEN; i++)
795 {
796 if (sndx1[i] == sndx2[i])
797 result++;
798 }
799
800 PG_RETURN_INT32(result);
801}
#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:214

References _soundex(), fb(), i, PG_GETARG_TEXT_PP, PG_RETURN_INT32, 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 123 of file fuzzystrmatch.c.

124{
125 c = pg_ascii_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}
static const char _codes[26]

References _codes, and pg_ascii_toupper().

◆ levenshtein()

Datum levenshtein ( PG_FUNCTION_ARGS  )

Definition at line 182 of file fuzzystrmatch.c.

183{
184 text *src = PG_GETARG_TEXT_PP(0);
186 const char *s_data;
187 const char *t_data;
188 int s_bytes,
189 t_bytes;
190
191 /* Extract a pointer to the actual character data */
192 s_data = VARDATA_ANY(src);
193 t_data = VARDATA_ANY(dst);
194 /* Determine length of each string in bytes */
197
199 1, 1, 1, false));
200}
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:706
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 234 of file fuzzystrmatch.c.

235{
236 text *src = PG_GETARG_TEXT_PP(0);
238 int max_d = PG_GETARG_INT32(2);
239 const char *s_data;
240 const char *t_data;
241 int s_bytes,
242 t_bytes;
243
244 /* Extract a pointer to the actual character data */
245 s_data = VARDATA_ANY(src);
246 t_data = VARDATA_ANY(dst);
247 /* Determine length of each string in bytes */
250
252 t_data, t_bytes,
253 1, 1, 1,
254 max_d, false));
255}
#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 205 of file fuzzystrmatch.c.

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

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 156 of file fuzzystrmatch.c.

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

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 326 of file fuzzystrmatch.c.

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

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

◆ metaphone()

Datum metaphone ( PG_FUNCTION_ARGS  )

Definition at line 265 of file fuzzystrmatch.c.

266{
268 size_t str_i_len = strlen(str_i);
269 int reqlen;
270 char *metaph;
271
272 /* return an empty string if we receive one */
273 if (!(str_i_len > 0))
275
279 errmsg("argument exceeds the maximum length of %d bytes",
281
286 errmsg("output exceeds the maximum length of %d bytes",
288
289 if (!(reqlen > 0))
292 errmsg("output cannot be empty string")));
293
296}
#define TextDatumGetCString(d)
Definition builtins.h:98
int errcode(int sqlerrcode)
Definition elog.c:863
int errmsg(const char *fmt,...)
Definition elog.c:1080
#define ereport(elevel,...)
Definition elog.h:150
#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
text * cstring_to_text(const char *s)
Definition varlena.c:181

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 117 of file fuzzystrmatch.c.

117 {
118 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
119/* 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 */
120};

Referenced by getcode().

◆ soundex_table

const char* const soundex_table = "01230120022455012623010202"
static

Definition at line 60 of file fuzzystrmatch.c.

Referenced by soundex_code().