75 int *lenval,
char **strval,
76 int16 *weight,
bool *prefix);
173 }
state = PHRASE_OPEN;
174 char *ptr = pstate->
buf;
195 state = PHRASE_CLOSE;
200 if (!isdigit((
unsigned char) *ptr))
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;
277 if (!isspace((
unsigned char) *ptr))
287 int *lenval,
char **strval,
288 int16 *weight,
bool *prefix)
295 switch (
state->state)
318 else if (!isspace((
unsigned char) *
state->buf))
326 NULL, NULL, &
state->buf))
343 (
errcode(ERRCODE_SYNTAX_ERROR),
344 errmsg(
"no operand in tsquery: \"%s\"",
382 else if (*
state->buf ==
'\0')
386 else if (!isspace((
unsigned char) *
state->buf))
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')
447 else if (!isspace((
unsigned char) *
state->buf))
455 NULL, NULL, &
state->buf))
479 if (*
state->buf ==
'\0')
495 else if (!isspace((
unsigned char) *
state->buf))
511 int *lenval,
char **strval,
512 int16 *weight,
bool *prefix)
517 if (*
state->buf ==
'\0')
520 *strval =
state->buf;
521 *lenval = strlen(
state->buf);
522 state->buf += *lenval;
553 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
554 errmsg(
"value is too big in tsquery: \"%s\"",
558 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
559 errmsg(
"operand is too long in tsquery: \"%s\"",
586 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
587 errmsg(
"word is too long in tsquery: \"%s\"",
604 memcpy(
state->curop, strval, lenval);
605 state->curop += lenval;
606 *(
state->curop) =
'\0';
608 state->sumlen += lenval + 1 ;
641 stack[*lenstack].
op = op;
642 stack[*lenstack].
distance = distance;
662 stack[*lenstack].distance);
690 &weight, &prefix)) !=
PT_END)
695 pushval(opaque,
state, strval, lenval, weight, prefix);
712 (
errcode(ERRCODE_SYNTAX_ERROR),
713 errmsg(
"syntax error in tsquery: \"%s\"",
732 elog(
ERROR,
"malformed tsquery: operand not found");
747 if (ptr[*pos].qoperator.oper ==
OP_NOT)
769 curitem->
left = *pos - tmp;
788 *needcleanup =
false;
793 elog(
ERROR,
"malformed tsquery: extra nodes");
865 *(
state.curop) =
'\0';
879 (
errmsg(
"text-search query doesn't contain lexemes: \"%s\"",
889 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
890 errmsg(
"tsquery is too large")));
901 foreach(cell,
state.polstr)
943 int16 weight,
bool prefix)
977#define RESIZEBUF(inf, addsize) \
978while( ( (inf)->cur - (inf)->buf ) + (addsize) + 1 >= (inf)->buflen ) \
980 int len = (inf)->cur - (inf)->buf; \
981 (inf)->buflen *= 2; \
982 (inf)->buf = (char*) repalloc( (void*)(inf)->buf, (inf)->buflen ); \
983 (inf)->cur = (inf)->buf + len; \
1034 if (curpol->
weight & (1 << 3))
1039 if (curpol->
weight & (1 << 2))
1044 if (curpol->
weight & (1 << 1))
1062 if (priority < parentPriority)
1066 in->
cur = strchr(in->
cur,
'\0');
1074 infix(in, priority,
false);
1075 if (priority < parentPriority)
1079 in->
cur = strchr(in->
cur,
'\0');
1088 bool needParenthesis =
false;
1091 if (priority < parentPriority ||
1095 needParenthesis =
true;
1098 in->
cur = strchr(in->
cur,
'\0');
1111 infix(in, priority,
false);
1131 elog(
ERROR,
"unrecognized operator type: %d",
op);
1133 in->
cur = strchr(in->
cur,
'\0');
1136 if (needParenthesis)
1140 in->
cur = strchr(in->
cur,
'\0');
1151 if (query->
size == 0)
1163 infix(&nrm, -1 ,
false);
1198 for (
i = 0;
i < query->
size;
i++)
1215 elog(
ERROR,
"unrecognized tsquery node type: %d", item->
type);
1236 const char **operands;
1269 val_len = strlen(
val);
1274 elog(
ERROR,
"invalid tsquery: invalid weight bitmap");
1277 elog(
ERROR,
"invalid tsquery: operand too long");
1280 elog(
ERROR,
"invalid tsquery: total operand length exceeded");
1300 datalen += val_len + 1;
1308 elog(
ERROR,
"invalid tsquery: unrecognized operator type %d",
1311 elog(
ERROR,
"invalid pointer to right operand");
1318 elog(
ERROR,
"unrecognized tsquery node type: %d", item->
type);
1370 if (query->
size == 0)
1390 infix(&nrm, -1,
false);
#define COMPUTESIZE(size)
#define Assert(condition)
static void PGresult * res
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)
List * lcons(void *datum, List *list)
int pg_database_encoding_max_length(void)
int pg_mblen(const char *mbstr)
void * repalloc(void *pointer, Size size)
void pfree(void *pointer)
void * palloc0(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)
static Datum PointerGetDatum(const void *X)
static pg_noinline void Size size
void check_stack_depth(void)
StringInfoData * StringInfo
TSVectorParseState valstate
int t_isalnum(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 char * get_modifiers(char *buf, int16 *weight, bool *prefix)
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)
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)
TSQuery cleanup_tsquery_stopwords(TSQuery in, bool noisy)
QueryItem * clean_NOT(QueryItem *ptr, int *len)
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)