67 int *lenval,
char **strval,
68 int16 *weight,
bool *prefix);
162 }
state = PHRASE_OPEN;
163 char *ptr = pstate->
buf;
184 state = PHRASE_CLOSE;
193 l = strtol(ptr, &endptr, 10);
196 else if (errno == ERANGE || l < 0 || l >
MAXENTRYPOS)
198 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
199 errmsg(
"distance in phrase operator must be an integer value between zero and %d inclusive",
203 state = PHRASE_CLOSE;
211 state = PHRASE_FINISH;
219 *distance = (
int16) l;
235 char *ptr = pstate->
buf;
276 int *lenval,
char **strval,
277 int16 *weight,
bool *prefix)
284 switch (
state->state)
305 (
errcode(ERRCODE_SYNTAX_ERROR),
306 errmsg(
"syntax error in tsquery: \"%s\"",
317 NULL, NULL, &
state->buf))
329 (
errcode(ERRCODE_SYNTAX_ERROR),
330 errmsg(
"no operand in tsquery: \"%s\"",
363 else if (*
state->buf ==
'\0')
380 int *lenval,
char **strval,
381 int16 *weight,
bool *prefix)
388 switch (
state->state)
406 *strval =
state->buf;
411 *lenval =
state->buf - *strval;
414 if (*
state->buf !=
'\0')
436 NULL, NULL, &
state->buf))
471 else if (*
state->buf ==
'\0')
491 int *lenval,
char **strval,
492 int16 *weight,
bool *prefix)
497 if (*
state->buf ==
'\0')
500 *strval =
state->buf;
501 *lenval = strlen(
state->buf);
502 state->buf += *lenval;
533 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
534 errmsg(
"value is too big in tsquery: \"%s\"",
538 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
539 errmsg(
"operand is too long in tsquery: \"%s\"",
566 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
567 errmsg(
"word is too long in tsquery: \"%s\"",
584 memcpy((
void *)
state->curop, (
void *) strval, lenval);
585 state->curop += lenval;
586 *(
state->curop) =
'\0';
588 state->sumlen += lenval + 1 ;
607 #define STACKDEPTH 32
621 stack[*lenstack].
op = op;
622 stack[*lenstack].
distance = distance;
642 stack[*lenstack].distance);
670 &weight, &prefix)) !=
PT_END)
675 pushval(opaque,
state, strval, lenval, weight, prefix);
690 (
errcode(ERRCODE_SYNTAX_ERROR),
691 errmsg(
"syntax error in tsquery: \"%s\"",
706 elog(
ERROR,
"malformed tsquery: operand not found");
721 if (ptr[*pos].qoperator.oper ==
OP_NOT)
743 curitem->
left = *pos - tmp;
762 *needcleanup =
false;
767 elog(
ERROR,
"malformed tsquery: extra nodes");
825 *(
state.curop) =
'\0';
835 (
errmsg(
"text-search query doesn't contain lexemes: \"%s\"",
845 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
846 errmsg(
"tsquery is too large")));
857 foreach(cell,
state.polstr)
899 int16 weight,
bool prefix)
928 #define RESIZEBUF(inf, addsize) \
929 while( ( (inf)->cur - (inf)->buf ) + (addsize) + 1 >= (inf)->buflen ) \
931 int len = (inf)->cur - (inf)->buf; \
932 (inf)->buflen *= 2; \
933 (inf)->buf = (char*) repalloc( (void*)(inf)->buf, (inf)->buflen ); \
934 (inf)->cur = (inf)->buf + len; \
985 if (curpol->
weight & (1 << 3))
990 if (curpol->
weight & (1 << 2))
995 if (curpol->
weight & (1 << 1))
1013 if (priority < parentPriority)
1017 in->
cur = strchr(in->
cur,
'\0');
1025 infix(in, priority,
false);
1026 if (priority < parentPriority)
1030 in->
cur = strchr(in->
cur,
'\0');
1039 bool needParenthesis =
false;
1042 if (priority < parentPriority ||
1046 needParenthesis =
true;
1049 in->
cur = strchr(in->
cur,
'\0');
1062 infix(in, priority,
false);
1082 elog(
ERROR,
"unrecognized operator type: %d",
op);
1084 in->
cur = strchr(in->
cur,
'\0');
1087 if (needParenthesis)
1091 in->
cur = strchr(in->
cur,
'\0');
1102 if (query->
size == 0)
1114 infix(&nrm, -1 ,
false);
1149 for (
i = 0;
i < query->
size;
i++)
1166 elog(
ERROR,
"unrecognized tsquery node type: %d", item->
type);
1187 const char **operands;
1195 operands =
palloc(size *
sizeof(
char *));
1204 for (
i = 0;
i < size;
i++)
1220 val_len = strlen(
val);
1225 elog(
ERROR,
"invalid tsquery: invalid weight bitmap");
1228 elog(
ERROR,
"invalid tsquery: operand too long");
1231 elog(
ERROR,
"invalid tsquery: total operand length exceeded");
1251 datalen += val_len + 1;
1259 elog(
ERROR,
"invalid tsquery: unrecognized operator type %d",
1262 elog(
ERROR,
"invalid pointer to right operand");
1269 elog(
ERROR,
"unrecognized tsquery node type: %d", item->
type);
1289 for (
i = 0;
i < size;
i++)
1321 if (query->
size == 0)
1341 infix(&nrm, -1,
false);
#define COMPUTESIZE(size)
static void PGresult * res
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#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)
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)
#define SET_VARSIZE(PTR, len)
#define PointerGetDatum(X)
StringInfoData * StringInfo
TSVectorParseState valstate
int t_isspace(const char *ptr)
int t_isdigit(const char *ptr)
int t_isalpha(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]
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)
TSQuery parse_tsquery(char *buf, PushFunction pushval, Datum opaque, int flags)
QueryItem * clean_NOT(QueryItem *ptr, int *len)
TSQuery cleanup_tsquery_stopwords(TSQuery in)
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)
text * cstring_to_text_with_len(const char *s, int len)
text * cstring_to_text(const char *s)