8#include "catalog/pg_collation_d.h"
60#define TRGM_BOUND_LEFT 0x01
61#define TRGM_BOUND_RIGHT 0x02
64#define WORD_SIMILARITY_CHECK_ONLY 0x01
66#define WORD_SIMILARITY_STRICT 0x02
77 "Sets the threshold used by the % operator.",
78 "Valid range is 0.0 .. 1.0.",
89 "Sets the threshold used by the <% operator.",
90 "Valid range is 0.0 .. 1.0.",
101 "Sets the threshold used by the <<% operator.",
102 "Valid range is 0.0 .. 1.0.",
116#define CMPCHAR(a,b) ( ((a)==(b)) ? 0 : ( ((a)<(b)) ? -1 : 1 ) )
125#define CMPPCHAR_S(a,b,i) CMPCHAR( *(((const signed char*)(a))+i), *(((const signed char*)(b))+i) )
135#define CMPPCHAR_UNS(a,b,i) CMPCHAR( *(((const unsigned char*)(a))+i), *(((const unsigned char*)(b))+i) )
195 elog(
ERROR,
"unrecognized strategy number: %d", strategy);
397 errmsg(
"out of memory")));
457 for (
i = 0;
i < len1;
i++)
463 for (
i = 0;
i < len2;
i++)
541 for (
i = 0;
i < len2;
i++)
991 val |= *(((
unsigned char *) ptr));
993 val |= *(((
unsigned char *) ptr) + 1);
995 val |= *(((
unsigned char *) ptr) + 2);
1058 if (len1 <= 0 || len2 <= 0)
1149 int mid = (lo + hi) / 2;
ArrayType * construct_array_builtin(Datum *elems, int nelems, Oid elmtype)
#define Assert(condition)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
#define palloc_array(type, count)
#define palloc0_array(type, count)
char * OidOutputFunctionCall(Oid functionId, Datum val)
#define PG_FREE_IF_COPY(ptr, n)
#define PG_GETARG_TEXT_PP(n)
#define DirectFunctionCall2(func, arg1, arg2)
#define PG_MODULE_MAGIC_EXT(...)
#define PG_GETARG_DATUM(n)
#define PG_FUNCTION_INFO_V1(funcname)
#define PG_GETARG_FLOAT4(n)
#define PG_RETURN_POINTER(x)
#define PG_RETURN_FLOAT4(x)
#define PG_RETURN_BOOL(x)
void DefineCustomRealVariable(const char *name, const char *short_desc, const char *long_desc, double *valueAddr, double bootValue, double minValue, double maxValue, GucContext context, int flags, GucRealCheckHook check_hook, GucRealAssignHook assign_hook, GucShowHook show_hook)
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
void MarkGUCPrefixReserved(const char *className)
#define CALCGTSIZE(flag, siglen)
static int pg_cmp_s32(int32 a, int32 b)
void getTypeOutputInfo(Oid type, Oid *typOutput, bool *typIsVarlena)
int pg_database_encoding_max_length(void)
int pg_mblen(const char *mbstr)
void pfree(void *pointer)
void * palloc0(Size size)
#define CHECK_FOR_INTERRUPTS()
Datum lower(PG_FUNCTION_ARGS)
Datum upper(PG_FUNCTION_ARGS)
#define INIT_LEGACY_CRC32(crc)
#define COMP_LEGACY_CRC32(crc, data, len)
#define FIN_LEGACY_CRC32(crc)
static char buf[DEFAULT_XLOG_SEG_SIZE]
#define qsort(a, b, c, d)
static Datum PointerGetDatum(const void *X)
static Datum Float4GetDatum(float4 X)
static float4 DatumGetFloat4(Datum X)
static Pointer DatumGetPointer(Datum X)
static size_t qunique(void *array, size_t elements, size_t width, int(*compare)(const void *, const void *))
static int cmp(const chr *x, const chr *y, size_t len)
#define CALCSML(count, len1, len2)
#define WordSimilarityStrategyNumber
#define StrictWordSimilarityStrategyNumber
#define SimilarityStrategyNumber
#define ISWILDCARDCHAR(x)
#define ISPRINTABLETRGM(t)
static float4 iterate_word_similarity(int *trg2indexes, bool *found, int ulen1, int len2, int len, uint8 flags, TrgmBound *bounds)
Datum strict_word_similarity_commutator_op(PG_FUNCTION_ARGS)
static int CMPTRGM_UNSIGNED(const void *a, const void *b)
Datum set_limit(PG_FUNCTION_ARGS)
static int comp_trgm(const void *a, const void *b)
double strict_word_similarity_threshold
TRGM * generate_trgm(char *str, int slen)
uint32 trgm2int(trgm *ptr)
static int CMPTRGM_CHOOSE(const void *a, const void *b)
int(* CMPTRGM)(const void *a, const void *b)
#define WORD_SIMILARITY_CHECK_ONLY
static void protect_out_of_mem(int slen)
Datum word_similarity(PG_FUNCTION_ARGS)
Datum strict_word_similarity_dist_commutator_op(PG_FUNCTION_ARGS)
void compact_trigram(trgm *tptr, char *str, int bytelen)
bool * trgm_presence_map(TRGM *query, TRGM *key)
static float4 calc_word_similarity(char *str1, int slen1, char *str2, int slen2, uint8 flags)
double word_similarity_threshold
Datum word_similarity_dist_commutator_op(PG_FUNCTION_ARGS)
double index_strategy_get_limit(StrategyNumber strategy)
Datum similarity(PG_FUNCTION_ARGS)
static pos_trgm * make_positional_trgm(trgm *trg1, int len1, trgm *trg2, int len2)
double similarity_threshold
static int CMPTRGM_SIGNED(const void *a, const void *b)
static int comp_ptrgm(const void *v1, const void *v2)
static char * find_word(char *str, int lenstr, char **endword, int *charlen)
Datum show_trgm(PG_FUNCTION_ARGS)
bool trgm_contained_by(TRGM *trg1, TRGM *trg2)
#define CMPPCHAR_S(a, b, i)
Datum show_limit(PG_FUNCTION_ARGS)
#define CMPPCHAR_UNS(a, b, i)
Datum strict_word_similarity_dist_op(PG_FUNCTION_ARGS)
Datum word_similarity_op(PG_FUNCTION_ARGS)
Datum word_similarity_commutator_op(PG_FUNCTION_ARGS)
#define WORD_SIMILARITY_STRICT
TRGM * generate_wildcard_trgm(const char *str, int slen)
static trgm * make_trigrams(trgm *tptr, char *str, int bytelen, int charlen)
float4 cnt_sml(TRGM *trg1, TRGM *trg2, bool inexact)
static int generate_trgm_only(trgm *trg, char *str, int slen, TrgmBound *bounds)
Datum similarity_op(PG_FUNCTION_ARGS)
Datum word_similarity_dist_op(PG_FUNCTION_ARGS)
static const char * get_wildcard_part(const char *str, int lenstr, char *buf, int *bytelen, int *charlen)
Datum strict_word_similarity(PG_FUNCTION_ARGS)
Datum similarity_dist(PG_FUNCTION_ARGS)
Datum strict_word_similarity_op(PG_FUNCTION_ARGS)
static Size VARSIZE_ANY_EXHDR(const void *PTR)
static char * VARDATA(const void *PTR)
static char * VARDATA_ANY(const void *PTR)
static void SET_VARSIZE(void *PTR, Size len)
bool GetDefaultCharSignedness(void)