67 int *lenval,
char **strval,
68 int16 *weight,
bool *prefix);
163 }
state = PHRASE_OPEN;
164 char *ptr = pstate->
buf;
185 state = PHRASE_CLOSE;
194 l = strtol(ptr, &endptr, 10);
197 else if (errno == ERANGE || l < 0 || l >
MAXENTRYPOS)
199 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
200 errmsg(
"distance in phrase operator should not be greater than %d",
204 state = PHRASE_CLOSE;
212 state = PHRASE_FINISH;
220 *distance = (
int16) l;
236 char *ptr = pstate->
buf;
280 int *lenval,
char **strval,
281 int16 *weight,
bool *prefix)
288 switch (state->
state)
309 (
errcode(ERRCODE_SYNTAX_ERROR),
310 errmsg(
"syntax error in tsquery: \"%s\"",
321 NULL, NULL, &state->
buf))
333 (
errcode(ERRCODE_SYNTAX_ERROR),
334 errmsg(
"no operand in tsquery: \"%s\"",
367 else if (*state->
buf ==
'\0')
384 int *lenval,
char **strval,
385 int16 *weight,
bool *prefix)
392 switch (state->
state)
415 if (strchr(state->
buf,
'"'))
449 NULL, NULL, &state->
buf))
495 else if (*state->
buf ==
'\0')
525 int *lenval,
char **strval,
526 int16 *weight,
bool *prefix)
531 if (*state->
buf ==
'\0')
534 *strval = state->
buf;
535 *lenval = strlen(state->
buf);
536 state->
buf += *lenval;
567 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
568 errmsg(
"value is too big in tsquery: \"%s\"",
572 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
573 errmsg(
"operand is too long in tsquery: \"%s\"",
600 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
601 errmsg(
"word is too long in tsquery: \"%s\"",
610 while (state->
curop - state->
op + lenval + 1 >= state->
lenop)
612 int used = state->
curop - state->
op;
616 state->
curop = state->
op + used;
618 memcpy((
void *) state->
curop, (
void *) strval, lenval);
619 state->
curop += lenval;
620 *(state->
curop) =
'\0';
622 state->
sumlen += lenval + 1 ;
641 #define STACKDEPTH 32 655 stack[*lenstack].
op =
op;
656 stack[*lenstack].
distance = distance;
676 stack[*lenstack].distance);
702 while ((type = state->
gettoken(state, &
operator,
704 &weight, &prefix)) !=
PT_END)
709 pushval(opaque, state, strval, lenval, weight, prefix);
716 makepol(state, pushval, opaque);
724 (
errcode(ERRCODE_SYNTAX_ERROR),
725 errmsg(
"syntax error in tsquery: \"%s\"",
740 elog(
ERROR,
"malformed tsquery: operand not found");
755 if (ptr[*pos].qoperator.oper ==
OP_NOT)
777 curitem->
left = *pos - tmp;
796 *needcleanup =
false;
801 elog(
ERROR,
"malformed tsquery: extra nodes");
860 *(state.
curop) =
'\0';
863 makepol(&state, pushval, opaque);
870 (
errmsg(
"text-search query doesn't contain lexemes: \"%s\"",
880 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
881 errmsg(
"tsquery is too large")));
892 foreach(cell, state.
polstr)
934 int16 weight,
bool prefix)
936 pushValue(state, strval, lenval, weight, prefix);
963 #define RESIZEBUF(inf, addsize) \ 964 while( ( (inf)->cur - (inf)->buf ) + (addsize) + 1 >= (inf)->buflen ) \ 966 int len = (inf)->cur - (inf)->buf; \ 967 (inf)->buflen *= 2; \ 968 (inf)->buf = (char*) repalloc( (void*)(inf)->buf, (inf)->buflen ); \ 969 (inf)->cur = (inf)->buf + len; \ 998 else if (
t_iseq(op,
'\\'))
1020 if (curpol->
weight & (1 << 3))
1025 if (curpol->
weight & (1 << 2))
1030 if (curpol->
weight & (1 << 1))
1048 if (priority < parentPriority)
1052 in->
cur = strchr(in->
cur,
'\0');
1060 infix(in, priority,
false);
1061 if (priority < parentPriority)
1065 in->
cur = strchr(in->
cur,
'\0');
1074 bool needParenthesis =
false;
1077 if (priority < parentPriority ||
1081 needParenthesis =
true;
1084 in->
cur = strchr(in->
cur,
'\0');
1097 infix(in, priority,
false);
1117 elog(
ERROR,
"unrecognized operator type: %d", op);
1119 in->
cur = strchr(in->
cur,
'\0');
1122 if (needParenthesis)
1126 in->
cur = strchr(in->
cur,
'\0');
1137 if (query->
size == 0)
1149 infix(&nrm, -1 ,
false);
1184 for (i = 0; i < query->
size; i++)
1201 elog(
ERROR,
"unrecognized tsquery node type: %d", item->
type);
1222 const char **operands;
1230 operands =
palloc(size *
sizeof(
char *));
1239 for (i = 0; i < size; i++)
1255 val_len = strlen(val);
1260 elog(
ERROR,
"invalid tsquery: invalid weight bitmap");
1263 elog(
ERROR,
"invalid tsquery: operand too long");
1266 elog(
ERROR,
"invalid tsquery: total operand length exceeded");
1286 datalen += val_len + 1;
1294 elog(
ERROR,
"invalid tsquery: unrecognized operator type %d",
1297 elog(
ERROR,
"invalid pointer to right operand");
1304 elog(
ERROR,
"unrecognized tsquery node type: %d", item->
type);
1324 for (i = 0; i < size; i++)
1356 if (query->
size == 0)
1376 infix(&nrm, -1,
false);
#define PG_RETURN_POINTER(x)
#define INIT_LEGACY_CRC32(crc)
#define TSQUERY_TOO_BIG(size, lenofoperand)
Datum tsquerytree(PG_FUNCTION_ARGS)
static void makepol(TSQueryParserState state, PushFunction pushval, Datum opaque)
#define PointerGetDatum(X)
bool gettoken_tsvector(TSVectorParseState state, char **strval, int *lenval, WordEntryPos **pos_ptr, int *poslen, char **endptr)
const int tsearch_op_priority[OP_COUNT]
#define PG_GETARG_TSQUERY(n)
static void pushOpStack(OperatorElement *stack, int *lenstack, int8 op, int16 distance)
StringInfoData * StringInfo
void close_tsvector_parser(TSVectorParseState state)
static ts_tokentype gettoken_query_websearch(TSQueryParserState state, int8 *operator, int *lenval, char **strval, int16 *weight, bool *prefix)
TSVectorParseState valstate
void(* PushFunction)(Datum opaque, TSQueryParserState state, char *token, int tokenlen, int16 tokenweights, bool prefix)
int errcode(int sqlerrcode)
static void pushValue_internal(TSQueryParserState state, pg_crc32 valcrc, int distance, int lenval, int weight, bool prefix)
#define PG_GETARG_POINTER(n)
TSQuery cleanup_tsquery_stopwords(TSQuery in)
#define PG_RETURN_BYTEA_P(x)
struct OperatorElement OperatorElement
#define FIN_LEGACY_CRC32(crc)
#define RESIZEBUF(inf, addsize)
ts_tokentype(* ts_tokenizer)(TSQueryParserState state, int8 *operator, int *lenval, char **strval, int16 *weight, bool *prefix)
#define PG_RETURN_TSQUERY(x)
Datum tsquerysend(PG_FUNCTION_ARGS)
int t_isdigit(const char *ptr)
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
void pfree(void *pointer)
static void findoprnd_recurse(QueryItem *ptr, uint32 *pos, int nnodes, bool *needcleanup)
static void infix(INFIX *in, int parentPriority, bool rightPhraseOp)
static void pushval_asis(Datum opaque, TSQueryParserState state, char *strval, int lenval, int16 weight, bool prefix)
void pushStop(TSQueryParserState state)
int t_isspace(const char *ptr)
static bool parse_phrase_operator(TSQueryParserState pstate, int16 *distance)
text * cstring_to_text_with_len(const char *s, int len)
QueryItem * clean_NOT(QueryItem *ptr, int *len)
void check_stack_depth(void)
void pushValue(TSQueryParserState state, char *strval, int lenval, int16 weight, bool prefix)
static char * get_modifiers(char *buf, int16 *weight, bool *prefix)
void * palloc0(Size size)
#define COMPUTESIZE(size)
void reset_tsvector_parser(TSVectorParseState state, char *input)
#define P_TSV_OPR_IS_DELIM
void pushOperator(TSQueryParserState state, int8 oper, int16 distance)
#define ereport(elevel,...)
#define PG_RETURN_TEXT_P(x)
List * lcons(void *datum, List *list)
text * cstring_to_text(const char *s)
#define Assert(condition)
TSVectorParseState init_tsvector_parser(char *input, int flags)
static bool parse_or_operator(TSQueryParserState pstate)
#define PG_RETURN_CSTRING(x)
Datum tsqueryrecv(PG_FUNCTION_ARGS)
static int list_length(const List *l)
#define PG_FREE_IF_COPY(ptr, n)
int pg_mblen(const char *mbstr)
void * repalloc(void *pointer, Size size)
int pg_database_encoding_max_length(void)
Datum tsqueryout(PG_FUNCTION_ARGS)
TSQuery parse_tsquery(char *buf, PushFunction pushval, Datum opaque, int flags)
int errmsg(const char *fmt,...)
#define COMP_LEGACY_CRC32(crc, data, len)
#define PG_GETARG_CSTRING(n)
#define SET_VARSIZE(PTR, len)
int t_isalpha(const char *ptr)
Operator oper(ParseState *pstate, List *opname, Oid ltypeId, Oid rtypeId, bool noError, int location)
static ts_tokentype gettoken_query_plain(TSQueryParserState state, int8 *operator, int *lenval, char **strval, int16 *weight, bool *prefix)
static void cleanOpStack(TSQueryParserState state, OperatorElement *stack, int *lenstack, int8 op)
Datum tsqueryin(PG_FUNCTION_ARGS)
static ts_tokentype gettoken_query_standard(TSQueryParserState state, int8 *operator, int *lenval, char **strval, int16 *weight, bool *prefix)
static void findoprnd(QueryItem *ptr, int size, bool *needcleanup)