21#include "utils/fmgrprotos.h"
28#define DT_USEASIS 0x1000
109 static int ntres = 0;
179 errmsg(
"could not open thesaurus file \"%s\": %m",
193 while (*ptr &&
isspace((
unsigned char) *ptr))
196 if (
t_iseq(ptr,
'#') || *ptr ==
'\0' ||
212 errmsg(
"unexpected delimiter")));
215 else if (!
isspace((
unsigned char) *ptr))
228 else if (
isspace((
unsigned char) *ptr))
242 else if (
t_iseq(ptr,
'\\'))
248 else if (!
isspace((
unsigned char) *ptr))
257 if (
isspace((
unsigned char) *ptr))
262 errmsg(
"unexpected end of line or lexeme")));
278 errmsg(
"unexpected end of line or lexeme")));
287 errmsg(
"unexpected end of line")));
292 errmsg(
"too many lexemes in thesaurus entry")));
314 if (lexeme && lexeme->
lexeme)
340 if (
a->idsubst ==
b->idsubst)
342 if (
a->posinsubst ==
b->posinsubst)
344 if (
a->tnvariant ==
b->tnvariant)
347 return (
a->tnvariant >
b->tnvariant) ? 1 : -1;
350 return (
a->posinsubst >
b->posinsubst) ? 1 : -1;
353 return (
a->idsubst >
b->idsubst) ? 1 : -1;
359 if (
a->lexeme ==
NULL)
361 if (
b->lexeme ==
NULL)
366 else if (
b->lexeme ==
NULL)
369 return strcmp(
a->lexeme,
b->lexeme);
417 errmsg(
"thesaurus sample word \"%s\" isn't recognized by subdictionary (rule %d)",
423 errmsg(
"thesaurus sample word \"%s\" is a stop word (rule %d)",
426 errhint(
"Use \"?\" to represent a stop word within a sample phrase.")));
568 errmsg(
"thesaurus substitute word \"%s\" is a stop word (rule %d)",
575 errmsg(
"thesaurus substitute word \"%s\" isn't recognized by subdictionary (rule %d)",
587 errmsg(
"thesaurus substitute phrase is empty (rule %d)",
617 errmsg(
"multiple DictFile parameters")));
621 else if (
strcmp(
defel->defname,
"dictionary") == 0)
626 errmsg(
"multiple Dictionary parameters")));
633 errmsg(
"unrecognized Thesaurus parameter: \"%s\"",
641 errmsg(
"missing DictFile parameter")));
645 errmsg(
"missing Dictionary parameter")));
800 elog(
ERROR,
"forbidden call of thesaurus or nested call");
863 dstate->private_state = info;
#define Assert(condition)
char * defGetString(DefElem *def)
Datum thesaurus_lexize(PG_FUNCTION_ARGS)
static void addWrd(DictThesaurus *d, char *b, char *e, uint32 idsubst, uint16 nwrd, uint16 posinsubst, bool useasis)
static LexemeInfo * findTheLexeme(DictThesaurus *d, char *lexeme)
static bool matchIdSubst(LexemeInfo *stored, uint32 idsubst)
static void compileTheSubstitute(DictThesaurus *d)
static void thesaurusRead(const char *filename, DictThesaurus *d)
static TSLexeme * copyTSLexeme(TheSubstitute *ts)
static TSLexeme * checkMatch(DictThesaurus *d, LexemeInfo *info, uint16 curpos, bool *moreres)
static LexemeInfo * findVariant(LexemeInfo *in, LexemeInfo *stored, uint16 curpos, LexemeInfo **newin, int newn)
static int cmpLexeme(const TheLexeme *a, const TheLexeme *b)
static TheLexeme * addCompiledLexeme(TheLexeme *newwrds, int *nnw, int *tnm, TSLexeme *lexeme, LexemeInfo *src, uint16 tnvariant)
static void compileTheLexeme(DictThesaurus *d)
Datum thesaurus_init(PG_FUNCTION_ARGS)
static int cmpLexemeInfo(LexemeInfo *a, LexemeInfo *b)
static int cmpLexemeQ(const void *a, const void *b)
static void newLexeme(DictThesaurus *d, char *b, char *e, uint32 idsubst, uint16 posinsubst)
static int cmpTheLexeme(const void *a, const void *b)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
#define palloc_object(type)
#define repalloc_array(pointer, type, count)
#define palloc_array(type, count)
#define palloc0_object(type)
#define PG_GETARG_POINTER(n)
#define PG_GETARG_DATUM(n)
#define FunctionCall4(flinfo, arg1, arg2, arg3, arg4)
#define PG_RETURN_POINTER(x)
int pg_mblen(const char *mbstr)
char * pstrdup(const char *in)
void * repalloc(void *pointer, Size size)
void pfree(void *pointer)
Oid get_ts_dict_oid(List *names, bool missing_ok)
#define qsort(a, b, c, d)
static Datum PointerGetDatum(const void *X)
static Pointer DatumGetPointer(Datum X)
static Datum Int32GetDatum(int32 X)
List * stringToQualifiedNameList(const char *string, Node *escontext)
TSDictionaryCacheEntry * subdict
struct LexemeInfo * nextvariant
struct LexemeInfo * nextentry
TSDictionaryCacheEntry * lookup_ts_dictionary_cache(Oid dictId)
bool tsearch_readline_begin(tsearch_readline_state *stp, const char *filename)
char * tsearch_readline(tsearch_readline_state *stp)
void tsearch_readline_end(tsearch_readline_state *stp)
char * get_tsearch_config_filename(const char *basename, const char *extension)