PostgreSQL Source Code
git master
|
#include "postgres.h"
#include <ctype.h>
#include "catalog/pg_type.h"
#include "common/int.h"
#include "lib/qunique.h"
#include "miscadmin.h"
#include "trgm.h"
#include "tsearch/ts_locale.h"
#include "utils/guc.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
#include "utils/pg_crc.h"
Go to the source code of this file.
Data Structures | |
struct | pos_trgm |
Macros | |
#define | TRGM_BOUND_LEFT 0x01 /* trigram is left bound of word */ |
#define | TRGM_BOUND_RIGHT 0x02 /* trigram is right bound of word */ |
#define | WORD_SIMILARITY_CHECK_ONLY |
#define | WORD_SIMILARITY_STRICT |
Typedefs | |
typedef uint8 | TrgmBound |
Variables | |
PG_MODULE_MAGIC | |
double | similarity_threshold = 0.3f |
double | word_similarity_threshold = 0.6f |
double | strict_word_similarity_threshold = 0.5f |
#define TRGM_BOUND_LEFT 0x01 /* trigram is left bound of word */ |
#define TRGM_BOUND_RIGHT 0x02 /* trigram is right bound of word */ |
#define WORD_SIMILARITY_CHECK_ONLY |
#define WORD_SIMILARITY_STRICT |
void _PG_init | ( | void | ) |
Definition at line 63 of file trgm_op.c.
References DefineCustomRealVariable(), MarkGUCPrefixReserved(), PGC_USERSET, similarity_threshold, strict_word_similarity_threshold, and word_similarity_threshold.
|
static |
Definition at line 622 of file trgm_op.c.
References cmp(), CMPTRGM, comp_ptrgm(), generate_trgm_only(), i, pos_trgm::index, iterate_word_similarity(), j, len, make_positional_trgm(), palloc(), palloc0(), pfree(), protect_out_of_mem(), qsort, and WORD_SIMILARITY_STRICT.
Referenced by strict_word_similarity(), strict_word_similarity_commutator_op(), strict_word_similarity_dist_commutator_op(), strict_word_similarity_dist_op(), strict_word_similarity_op(), word_similarity(), word_similarity_commutator_op(), word_similarity_dist_commutator_op(), word_similarity_dist_op(), and word_similarity_op().
Definition at line 992 of file trgm_op.c.
References ARRNELEM, CALCSML, CMPTRGM, GETARR, and res.
Referenced by gtrgm_consistent(), gtrgm_distance(), and similarity().
|
static |
Definition at line 425 of file trgm_op.c.
References cmp(), CMPTRGM, pos_trgm::index, p2, pg_cmp_s32(), and pos_trgm::trg.
Referenced by calc_word_similarity().
|
static |
Definition at line 162 of file trgm_op.c.
Referenced by generate_trgm(), and generate_wildcard_trgm().
void compact_trigram | ( | trgm * | tptr, |
char * | str, | ||
int | bytelen | ||
) |
Definition at line 199 of file trgm_op.c.
References COMP_LEGACY_CRC32, CPTRGM, crc, FIN_LEGACY_CRC32, INIT_LEGACY_CRC32, and str.
Referenced by fillTrgm(), and make_trigrams().
|
static |
Definition at line 172 of file trgm_op.c.
References ISWORDCHR, pg_mblen(), and str.
Referenced by generate_trgm_only().
TRGM* generate_trgm | ( | char * | str, |
int | slen | ||
) |
Definition at line 357 of file trgm_op.c.
References ARRKEY, CALCGTSIZE, comp_trgm(), TRGM::flag, generate_trgm_only(), GETARR, len, palloc(), protect_out_of_mem(), qsort, qunique(), SET_VARSIZE, str, and TRGMHDRSIZE.
Referenced by gin_extract_query_trgm(), gin_extract_value_trgm(), gtrgm_compress(), gtrgm_consistent(), gtrgm_distance(), show_trgm(), and similarity().
Definition at line 276 of file trgm_op.c.
References buf, find_word(), lowerstr_with_len(), LPADDING, make_trigrams(), palloc(), pfree(), pg_database_encoding_max_length(), RPADDING, str, TRGM_BOUND_LEFT, and TRGM_BOUND_RIGHT.
Referenced by calc_word_similarity(), and generate_trgm().
TRGM* generate_wildcard_trgm | ( | const char * | str, |
int | slen | ||
) |
Definition at line 867 of file trgm_op.c.
References ARRKEY, buf, CALCGTSIZE, comp_trgm(), TRGM::flag, get_wildcard_part(), GETARR, len, lowerstr_with_len(), LPADDING, make_trigrams(), palloc(), pfree(), protect_out_of_mem(), qsort, qunique(), RPADDING, SET_VARSIZE, str, and TRGMHDRSIZE.
Referenced by gin_extract_query_trgm(), and gtrgm_consistent().
|
static |
Definition at line 722 of file trgm_op.c.
References buf, ISESCAPECHAR, ISWILDCARDCHAR, ISWORDCHR, LPADDING, pg_mblen(), RPADDING, and str.
Referenced by generate_wildcard_trgm().
double index_strategy_get_limit | ( | StrategyNumber | strategy | ) |
Definition at line 133 of file trgm_op.c.
References elog, ERROR, similarity_threshold, SimilarityStrategyNumber, strict_word_similarity_threshold, StrictWordSimilarityStrategyNumber, word_similarity_threshold, and WordSimilarityStrategyNumber.
Referenced by gin_trgm_consistent(), gin_trgm_triconsistent(), and gtrgm_consistent().
|
static |
Definition at line 454 of file trgm_op.c.
References Assert, CALCSML, CHECK_FOR_INTERRUPTS, i, len, lower(), Max, palloc(), pfree(), strict_word_similarity_threshold, TRGM_BOUND_LEFT, TRGM_BOUND_RIGHT, upper(), WORD_SIMILARITY_CHECK_ONLY, WORD_SIMILARITY_STRICT, and word_similarity_threshold.
Referenced by calc_word_similarity().
Definition at line 398 of file trgm_op.c.
References i, pos_trgm::index, len, and palloc().
Referenced by calc_word_similarity().
Definition at line 224 of file trgm_op.c.
References Assert, compact_trigram(), CPTRGM, pg_mblen(), and str.
Referenced by generate_trgm_only(), and generate_wildcard_trgm().
PG_FUNCTION_INFO_V1 | ( | set_limit | ) |
PG_FUNCTION_INFO_V1 | ( | show_limit | ) |
PG_FUNCTION_INFO_V1 | ( | show_trgm | ) |
PG_FUNCTION_INFO_V1 | ( | similarity | ) |
PG_FUNCTION_INFO_V1 | ( | similarity_dist | ) |
PG_FUNCTION_INFO_V1 | ( | similarity_op | ) |
PG_FUNCTION_INFO_V1 | ( | strict_word_similarity | ) |
PG_FUNCTION_INFO_V1 | ( | strict_word_similarity_commutator_op | ) |
PG_FUNCTION_INFO_V1 | ( | strict_word_similarity_dist_commutator_op | ) |
PG_FUNCTION_INFO_V1 | ( | strict_word_similarity_dist_op | ) |
PG_FUNCTION_INFO_V1 | ( | strict_word_similarity_op | ) |
PG_FUNCTION_INFO_V1 | ( | word_similarity | ) |
PG_FUNCTION_INFO_V1 | ( | word_similarity_commutator_op | ) |
PG_FUNCTION_INFO_V1 | ( | word_similarity_dist_commutator_op | ) |
PG_FUNCTION_INFO_V1 | ( | word_similarity_dist_op | ) |
PG_FUNCTION_INFO_V1 | ( | word_similarity_op | ) |
|
static |
Definition at line 340 of file trgm_op.c.
References ereport, errcode(), errmsg(), ERROR, MaxAllocSize, and pg_database_encoding_max_length().
Referenced by calc_word_similarity(), generate_trgm(), and generate_wildcard_trgm().
Datum set_limit | ( | PG_FUNCTION_ARGS | ) |
Definition at line 111 of file trgm_op.c.
References Float4GetDatum(), getTypeOutputInfo(), OidOutputFunctionCall(), PG_GETARG_FLOAT4, PG_RETURN_FLOAT4, PGC_S_SESSION, PGC_USERSET, SetConfigOption(), and similarity_threshold.
Datum show_limit | ( | PG_FUNCTION_ARGS | ) |
Definition at line 156 of file trgm_op.c.
References PG_RETURN_FLOAT4, and similarity_threshold.
Datum show_trgm | ( | PG_FUNCTION_ARGS | ) |
Definition at line 950 of file trgm_op.c.
References a, ARRNELEM, construct_array_builtin(), CPTRGM, DatumGetPointer(), generate_trgm(), GETARR, i, ISPRINTABLETRGM, Max, palloc(), pfree(), pg_database_encoding_max_length(), PG_FREE_IF_COPY, PG_GETARG_TEXT_PP, PG_RETURN_POINTER, PointerGetDatum(), SET_VARSIZE, snprintf, trgm2int(), VARDATA, VARDATA_ANY, VARHDRSZ, and VARSIZE_ANY_EXHDR.
Datum similarity | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1118 of file trgm_op.c.
References cnt_sml(), generate_trgm(), pfree(), PG_FREE_IF_COPY, PG_GETARG_TEXT_PP, PG_RETURN_FLOAT4, res, VARDATA_ANY, and VARSIZE_ANY_EXHDR.
Referenced by similarity_dist(), and similarity_op().
Datum similarity_dist | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1172 of file trgm_op.c.
References DatumGetFloat4(), DirectFunctionCall2, PG_GETARG_DATUM, PG_RETURN_FLOAT4, res, and similarity().
Datum similarity_op | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1182 of file trgm_op.c.
References DatumGetFloat4(), DirectFunctionCall2, PG_GETARG_DATUM, PG_RETURN_BOOL, res, similarity(), and similarity_threshold.
Datum strict_word_similarity | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1156 of file trgm_op.c.
References calc_word_similarity(), PG_FREE_IF_COPY, PG_GETARG_TEXT_PP, PG_RETURN_FLOAT4, res, VARDATA_ANY, VARSIZE_ANY_EXHDR, and WORD_SIMILARITY_STRICT.
Datum strict_word_similarity_commutator_op | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1272 of file trgm_op.c.
References calc_word_similarity(), PG_FREE_IF_COPY, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, res, strict_word_similarity_threshold, VARDATA_ANY, VARSIZE_ANY_EXHDR, WORD_SIMILARITY_CHECK_ONLY, and WORD_SIMILARITY_STRICT.
Datum strict_word_similarity_dist_commutator_op | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1304 of file trgm_op.c.
References calc_word_similarity(), PG_FREE_IF_COPY, PG_GETARG_TEXT_PP, PG_RETURN_FLOAT4, res, VARDATA_ANY, VARSIZE_ANY_EXHDR, and WORD_SIMILARITY_STRICT.
Datum strict_word_similarity_dist_op | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1288 of file trgm_op.c.
References calc_word_similarity(), PG_FREE_IF_COPY, PG_GETARG_TEXT_PP, PG_RETURN_FLOAT4, res, VARDATA_ANY, VARSIZE_ANY_EXHDR, and WORD_SIMILARITY_STRICT.
Datum strict_word_similarity_op | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1256 of file trgm_op.c.
References calc_word_similarity(), PG_FREE_IF_COPY, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, res, strict_word_similarity_threshold, VARDATA_ANY, VARSIZE_ANY_EXHDR, WORD_SIMILARITY_CHECK_ONLY, and WORD_SIMILARITY_STRICT.
Definition at line 936 of file trgm_op.c.
References val.
Referenced by gin_extract_query_trgm(), gin_extract_value_trgm(), and show_trgm().
Definition at line 1079 of file trgm_op.c.
References ARRNELEM, CMPTRGM, GETARR, i, sort-test::key, palloc0(), and res.
Referenced by gtrgm_consistent().
Datum word_similarity | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1140 of file trgm_op.c.
References calc_word_similarity(), PG_FREE_IF_COPY, PG_GETARG_TEXT_PP, PG_RETURN_FLOAT4, res, VARDATA_ANY, and VARSIZE_ANY_EXHDR.
Datum word_similarity_commutator_op | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1208 of file trgm_op.c.
References calc_word_similarity(), PG_FREE_IF_COPY, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, res, VARDATA_ANY, VARSIZE_ANY_EXHDR, WORD_SIMILARITY_CHECK_ONLY, and word_similarity_threshold.
Datum word_similarity_dist_commutator_op | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1240 of file trgm_op.c.
References calc_word_similarity(), PG_FREE_IF_COPY, PG_GETARG_TEXT_PP, PG_RETURN_FLOAT4, res, VARDATA_ANY, and VARSIZE_ANY_EXHDR.
Datum word_similarity_dist_op | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1224 of file trgm_op.c.
References calc_word_similarity(), PG_FREE_IF_COPY, PG_GETARG_TEXT_PP, PG_RETURN_FLOAT4, res, VARDATA_ANY, and VARSIZE_ANY_EXHDR.
Datum word_similarity_op | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1192 of file trgm_op.c.
References calc_word_similarity(), PG_FREE_IF_COPY, PG_GETARG_TEXT_PP, PG_RETURN_BOOL, res, VARDATA_ANY, VARSIZE_ANY_EXHDR, WORD_SIMILARITY_CHECK_ONLY, and word_similarity_threshold.
double similarity_threshold = 0.3f |
Definition at line 22 of file trgm_op.c.
Referenced by _PG_init(), index_strategy_get_limit(), set_limit(), show_limit(), and similarity_op().
double strict_word_similarity_threshold = 0.5f |
Definition at line 24 of file trgm_op.c.
Referenced by _PG_init(), index_strategy_get_limit(), iterate_word_similarity(), strict_word_similarity_commutator_op(), and strict_word_similarity_op().
double word_similarity_threshold = 0.6f |
Definition at line 23 of file trgm_op.c.
Referenced by _PG_init(), index_strategy_get_limit(), iterate_word_similarity(), word_similarity_commutator_op(), and word_similarity_op().