75 int *lenval,
char **strval,
76 int16 *weight,
bool *prefix);
173 }
state = PHRASE_OPEN;
174 char *ptr = pstate->
buf;
195 state = PHRASE_CLOSE;
204 l = strtol(ptr, &endptr, 10);
207 else if (errno == ERANGE || l < 0 || l >
MAXENTRYPOS)
209 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
210 errmsg(
"distance in phrase operator must be an integer value between zero and %d inclusive",
214 state = PHRASE_CLOSE;
222 state = PHRASE_FINISH;
230 *distance = (
int16) l;
246 char *ptr = pstate->
buf;
287 int *lenval,
char **strval,
288 int16 *weight,
bool *prefix)
295 switch (
state->state)
326 NULL, NULL, &
state->buf))
343 (
errcode(ERRCODE_SYNTAX_ERROR),
344 errmsg(
"no operand in tsquery: \"%s\"",
382 else if (*
state->buf ==
'\0')
399 int *lenval,
char **strval,
400 int16 *weight,
bool *prefix)
407 switch (
state->state)
425 *strval =
state->buf;
430 *lenval =
state->buf - *strval;
433 if (*
state->buf !=
'\0')
455 NULL, NULL, &
state->buf))
495 else if (*
state->buf ==
'\0')
515 int *lenval,
char **strval,
516 int16 *weight,
bool *prefix)
521 if (*
state->buf ==
'\0')
524 *strval =
state->buf;
525 *lenval = strlen(
state->buf);
526 state->buf += *lenval;
557 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
558 errmsg(
"value is too big in tsquery: \"%s\"",
562 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
563 errmsg(
"operand is too long in tsquery: \"%s\"",
590 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
591 errmsg(
"word is too long in tsquery: \"%s\"",
608 memcpy(
state->curop, strval, lenval);
609 state->curop += lenval;
610 *(
state->curop) =
'\0';
612 state->sumlen += lenval + 1 ;
631 #define STACKDEPTH 32
645 stack[*lenstack].
op = op;
646 stack[*lenstack].
distance = distance;
666 stack[*lenstack].distance);
694 &weight, &prefix)) !=
PT_END)
699 pushval(opaque,
state, strval, lenval, weight, prefix);
716 (
errcode(ERRCODE_SYNTAX_ERROR),
717 errmsg(
"syntax error in tsquery: \"%s\"",
736 elog(
ERROR,
"malformed tsquery: operand not found");
751 if (ptr[*pos].qoperator.oper ==
OP_NOT)
773 curitem->
left = *pos - tmp;
792 *needcleanup =
false;
797 elog(
ERROR,
"malformed tsquery: extra nodes");
869 *(
state.curop) =
'\0';
883 (
errmsg(
"text-search query doesn't contain lexemes: \"%s\"",
893 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
894 errmsg(
"tsquery is too large")));
905 foreach(cell,
state.polstr)
947 int16 weight,
bool prefix)
981 #define RESIZEBUF(inf, addsize) \
982 while( ( (inf)->cur - (inf)->buf ) + (addsize) + 1 >= (inf)->buflen ) \
984 int len = (inf)->cur - (inf)->buf; \
985 (inf)->buflen *= 2; \
986 (inf)->buf = (char*) repalloc( (void*)(inf)->buf, (inf)->buflen ); \
987 (inf)->cur = (inf)->buf + len; \
1038 if (curpol->
weight & (1 << 3))
1043 if (curpol->
weight & (1 << 2))
1048 if (curpol->
weight & (1 << 1))
1066 if (priority < parentPriority)
1070 in->
cur = strchr(in->
cur,
'\0');
1078 infix(in, priority,
false);
1079 if (priority < parentPriority)
1083 in->
cur = strchr(in->
cur,
'\0');
1092 bool needParenthesis =
false;
1095 if (priority < parentPriority ||
1099 needParenthesis =
true;
1102 in->
cur = strchr(in->
cur,
'\0');
1115 infix(in, priority,
false);
1135 elog(
ERROR,
"unrecognized operator type: %d",
op);
1137 in->
cur = strchr(in->
cur,
'\0');
1140 if (needParenthesis)
1144 in->
cur = strchr(in->
cur,
'\0');
1155 if (query->
size == 0)
1167 infix(&nrm, -1 ,
false);
1202 for (
i = 0;
i < query->
size;
i++)
1219 elog(
ERROR,
"unrecognized tsquery node type: %d", item->
type);
1240 const char **operands;
1248 operands =
palloc(size *
sizeof(
char *));
1257 for (
i = 0;
i < size;
i++)
1273 val_len = strlen(
val);
1278 elog(
ERROR,
"invalid tsquery: invalid weight bitmap");
1281 elog(
ERROR,
"invalid tsquery: operand too long");
1284 elog(
ERROR,
"invalid tsquery: total operand length exceeded");
1304 datalen += val_len + 1;
1312 elog(
ERROR,
"invalid tsquery: unrecognized operator type %d",
1315 elog(
ERROR,
"invalid pointer to right operand");
1322 elog(
ERROR,
"unrecognized tsquery node type: %d", item->
type);
1342 for (
i = 0;
i < size;
i++)
1374 if (query->
size == 0)
1394 infix(&nrm, -1,
false);
#define COMPUTESIZE(size)
static void PGresult * res
elog(ERROR, "%s: %s", p2, msg)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereturn(context, dummy_value,...)
#define errsave(context,...)
#define ereport(elevel,...)
#define PG_FREE_IF_COPY(ptr, n)
#define PG_RETURN_BYTEA_P(x)
#define PG_GETARG_POINTER(n)
#define PG_RETURN_CSTRING(x)
#define PG_GETARG_CSTRING(n)
#define PG_RETURN_TEXT_P(x)
#define PG_RETURN_POINTER(x)
Assert(fmt[strlen(fmt) - 1] !='\n')
List * lcons(void *datum, List *list)
int pg_database_encoding_max_length(void)
int pg_mblen(const char *mbstr)
void pfree(void *pointer)
void * palloc0(Size size)
void * repalloc(void *pointer, Size size)
#define SOFT_ERROR_OCCURRED(escontext)
#define IsA(nodeptr, _type_)
Operator oper(ParseState *pstate, List *opname, Oid ltypeId, Oid rtypeId, bool noError, int location)
#define INIT_LEGACY_CRC32(crc)
#define COMP_LEGACY_CRC32(crc, data, len)
#define FIN_LEGACY_CRC32(crc)
static int list_length(const List *l)
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
void check_stack_depth(void)
static Datum PointerGetDatum(const void *X)
StringInfoData * StringInfo
TSVectorParseState valstate
int t_isspace(const char *ptr)
int t_isalnum(const char *ptr)
int t_isdigit(const char *ptr)
#define PG_GETARG_TSQUERY(n)
#define PG_RETURN_TSQUERY(x)
#define TSQUERY_TOO_BIG(size, lenofoperand)
#define P_TSV_OPR_IS_DELIM
void(* PushFunction)(Datum opaque, TSQueryParserState state, char *token, int tokenlen, int16 tokenweights, bool prefix)
struct OperatorElement OperatorElement
static ts_tokentype gettoken_query_standard(TSQueryParserState state, int8 *operator, int *lenval, char **strval, int16 *weight, bool *prefix)
static void pushOpStack(OperatorElement *stack, int *lenstack, int8 op, int16 distance)
void pushValue(TSQueryParserState state, char *strval, int lenval, int16 weight, bool prefix)
static bool parse_or_operator(TSQueryParserState pstate)
static bool parse_phrase_operator(TSQueryParserState pstate, int16 *distance)
Datum tsqueryrecv(PG_FUNCTION_ARGS)
static void pushValue_internal(TSQueryParserState state, pg_crc32 valcrc, int distance, int lenval, int weight, bool prefix)
Datum tsquerytree(PG_FUNCTION_ARGS)
#define RESIZEBUF(inf, addsize)
ts_tokentype(* ts_tokenizer)(TSQueryParserState state, int8 *operator, int *lenval, char **strval, int16 *weight, bool *prefix)
static void findoprnd(QueryItem *ptr, int size, bool *needcleanup)
const int tsearch_op_priority[OP_COUNT]
TSQuery parse_tsquery(char *buf, PushFunction pushval, Datum opaque, int flags, Node *escontext)
void pushOperator(TSQueryParserState state, int8 oper, int16 distance)
Datum tsquerysend(PG_FUNCTION_ARGS)
static void cleanOpStack(TSQueryParserState state, OperatorElement *stack, int *lenstack, int8 op)
static void makepol(TSQueryParserState state, PushFunction pushval, Datum opaque)
static char * get_modifiers(char *buf, int16 *weight, bool *prefix)
Datum tsqueryin(PG_FUNCTION_ARGS)
Datum tsqueryout(PG_FUNCTION_ARGS)
static void pushval_asis(Datum opaque, TSQueryParserState state, char *strval, int lenval, int16 weight, bool prefix)
static void infix(INFIX *in, int parentPriority, bool rightPhraseOp)
static ts_tokentype gettoken_query_plain(TSQueryParserState state, int8 *operator, int *lenval, char **strval, int16 *weight, bool *prefix)
void pushStop(TSQueryParserState state)
static void findoprnd_recurse(QueryItem *ptr, uint32 *pos, int nnodes, bool *needcleanup)
static ts_tokentype gettoken_query_websearch(TSQueryParserState state, int8 *operator, int *lenval, char **strval, int16 *weight, bool *prefix)
QueryItem * clean_NOT(QueryItem *ptr, int *len)
TSQuery cleanup_tsquery_stopwords(TSQuery in, bool noisy)
void reset_tsvector_parser(TSVectorParseState state, char *input)
void close_tsvector_parser(TSVectorParseState state)
bool gettoken_tsvector(TSVectorParseState state, char **strval, int *lenval, WordEntryPos **pos_ptr, int *poslen, char **endptr)
TSVectorParseState init_tsvector_parser(char *input, int flags, Node *escontext)
#define SET_VARSIZE(PTR, len)
text * cstring_to_text_with_len(const char *s, int len)
text * cstring_to_text(const char *s)