#include "postgres.h"
#include "tsearch/ts_utils.h"
Go to the source code of this file.
Defines | |
#define | CMPFUNC(NAME, CONDITION) |
Functions | |
Datum | tsquery_numnode (PG_FUNCTION_ARGS) |
static QTNode * | join_tsqueries (TSQuery a, TSQuery b, int8 operator) |
Datum | tsquery_and (PG_FUNCTION_ARGS) |
Datum | tsquery_or (PG_FUNCTION_ARGS) |
Datum | tsquery_not (PG_FUNCTION_ARGS) |
static int | CompareTSQ (TSQuery a, TSQuery b) |
Datum | tsquery_cmp (PG_FUNCTION_ARGS) |
CMPFUNC (tsquery_lt, res< 0) | |
CMPFUNC (tsquery_le, res<=0) | |
CMPFUNC (tsquery_eq, res==0) | |
CMPFUNC (tsquery_ge, res >=0) | |
CMPFUNC (tsquery_gt, res > 0) | |
CMPFUNC (tsquery_ne, res!=0) | |
TSQuerySign | makeTSQuerySign (TSQuery a) |
Datum | tsq_mcontains (PG_FUNCTION_ARGS) |
Datum | tsq_mcontained (PG_FUNCTION_ARGS) |
#define CMPFUNC | ( | NAME, | ||
CONDITION | ||||
) |
Datum \ NAME(PG_FUNCTION_ARGS) { \ TSQuery a = PG_GETARG_TSQUERY_COPY(0); \ TSQuery b = PG_GETARG_TSQUERY_COPY(1); \ int res = CompareTSQ(a,b); \ \ PG_FREE_IF_COPY(a,0); \ PG_FREE_IF_COPY(b,1); \ \ PG_RETURN_BOOL( CONDITION ); \ } \ /* keep compiler quiet - no extra ; */ \ extern int no_such_variable
Definition at line 177 of file tsquery_op.c.
CMPFUNC | ( | tsquery_lt | ) |
CMPFUNC | ( | tsquery_le | , | |
res<= | 0 | |||
) |
CMPFUNC | ( | tsquery_eq | , | |
res | = =0 | |||
) |
CMPFUNC | ( | tsquery_ge | , | |
res >= | 0 | |||
) |
CMPFUNC | ( | tsquery_gt | , | |
res | , | |||
0 | ||||
) |
CMPFUNC | ( | tsquery_ne | , | |
res! | = 0 | |||
) |
Definition at line 139 of file tsquery_op.c.
References GETOPERAND, GETQUERY, QT2QTN(), QTNFree(), QTNodeCompare(), TSQueryData::size, and VARSIZE.
Referenced by tsquery_cmp().
{ if (a->size != b->size) { return (a->size < b->size) ? -1 : 1; } else if (VARSIZE(a) != VARSIZE(b)) { return (VARSIZE(a) < VARSIZE(b)) ? -1 : 1; } else if (a->size != 0) { QTNode *an = QT2QTN(GETQUERY(a), GETOPERAND(a)); QTNode *bn = QT2QTN(GETQUERY(b), GETOPERAND(b)); int res = QTNodeCompare(an, bn); QTNFree(an); QTNFree(bn); return res; } return 0; }
Definition at line 30 of file tsquery_op.c.
References QTNode::child, QTNode::flags, GETOPERAND, GETQUERY, QTNode::nchild, QueryOperator::oper, palloc0(), QueryItem::qoperator, QT2QTN(), QueryItem::type, and QTNode::valnode.
Referenced by tsquery_and(), and tsquery_or().
{ QTNode *res = (QTNode *) palloc0(sizeof(QTNode)); res->flags |= QTN_NEEDFREE; res->valnode = (QueryItem *) palloc0(sizeof(QueryItem)); res->valnode->type = QI_OPR; res->valnode->qoperator.oper = operator; res->child = (QTNode **) palloc0(sizeof(QTNode *) * 2); res->child[0] = QT2QTN(GETQUERY(b), GETOPERAND(b)); res->child[1] = QT2QTN(GETQUERY(a), GETOPERAND(a)); res->nchild = 2; return res; }
TSQuerySign makeTSQuerySign | ( | TSQuery | a | ) |
Definition at line 200 of file tsquery_op.c.
References GETQUERY, i, QI_VAL, QueryItem::qoperand, sign, TSQueryData::size, QueryItem::type, and QueryOperand::valcrc.
Referenced by gtsquery_compress(), gtsquery_consistent(), and tsq_mcontains().
Datum tsq_mcontained | ( | PG_FUNCTION_ARGS | ) |
Definition at line 276 of file tsquery_op.c.
References DirectFunctionCall2, PG_GETARG_DATUM, PG_RETURN_DATUM, and tsq_mcontains().
{ PG_RETURN_DATUM( DirectFunctionCall2( tsq_mcontains, PG_GETARG_DATUM(1), PG_GETARG_DATUM(0) ) ); }
Datum tsq_mcontains | ( | PG_FUNCTION_ARGS | ) |
Definition at line 217 of file tsquery_op.c.
References GETQUERY, i, makeTSQuerySign(), PG_FREE_IF_COPY, PG_GETARG_TSQUERY, PG_RETURN_BOOL, QI_VAL, QueryItem::qoperand, TSQueryData::size, NODE::type, and QueryOperand::valcrc.
Referenced by tsq_mcontained().
{ TSQuery query = PG_GETARG_TSQUERY(0); TSQuery ex = PG_GETARG_TSQUERY(1); TSQuerySign sq, se; int i, j; QueryItem *iq, *ie; if (query->size < ex->size) { PG_FREE_IF_COPY(query, 0); PG_FREE_IF_COPY(ex, 1); PG_RETURN_BOOL(false); } sq = makeTSQuerySign(query); se = makeTSQuerySign(ex); if ((sq & se) != se) { PG_FREE_IF_COPY(query, 0); PG_FREE_IF_COPY(ex, 1); PG_RETURN_BOOL(false); } iq = GETQUERY(query); ie = GETQUERY(ex); for (i = 0; i < ex->size; i++) { if (ie[i].type != QI_VAL) continue; for (j = 0; j < query->size; j++) { if (iq[j].type == QI_VAL && ie[i].qoperand.valcrc == iq[j].qoperand.valcrc) break; } if (j >= query->size) { PG_FREE_IF_COPY(query, 0); PG_FREE_IF_COPY(ex, 1); PG_RETURN_BOOL(false); } } PG_FREE_IF_COPY(query, 0); PG_FREE_IF_COPY(ex, 1); PG_RETURN_BOOL(true); }
Datum tsquery_and | ( | PG_FUNCTION_ARGS | ) |
Definition at line 49 of file tsquery_op.c.
References join_tsqueries(), OP_AND, PG_FREE_IF_COPY, PG_GETARG_TSQUERY_COPY, PG_RETURN_POINTER, PG_RETURN_TSQUERY, QTN2QT(), QTNFree(), and TSQueryData::size.
{ TSQuery a = PG_GETARG_TSQUERY_COPY(0); TSQuery b = PG_GETARG_TSQUERY_COPY(1); QTNode *res; TSQuery query; if (a->size == 0) { PG_FREE_IF_COPY(a, 1); PG_RETURN_POINTER(b); } else if (b->size == 0) { PG_FREE_IF_COPY(b, 1); PG_RETURN_POINTER(a); } res = join_tsqueries(a, b, OP_AND); query = QTN2QT(res); QTNFree(res); PG_FREE_IF_COPY(a, 0); PG_FREE_IF_COPY(b, 1); PG_RETURN_TSQUERY(query); }
Datum tsquery_cmp | ( | PG_FUNCTION_ARGS | ) |
Definition at line 165 of file tsquery_op.c.
References CompareTSQ(), PG_FREE_IF_COPY, PG_GETARG_TSQUERY_COPY, and PG_RETURN_INT32.
{ TSQuery a = PG_GETARG_TSQUERY_COPY(0); TSQuery b = PG_GETARG_TSQUERY_COPY(1); int res = CompareTSQ(a, b); PG_FREE_IF_COPY(a, 0); PG_FREE_IF_COPY(b, 1); PG_RETURN_INT32(res); }
Datum tsquery_not | ( | PG_FUNCTION_ARGS | ) |
Definition at line 109 of file tsquery_op.c.
References QTNode::child, QTNode::flags, GETOPERAND, GETQUERY, QTNode::nchild, QueryOperator::oper, palloc0(), PG_FREE_IF_COPY, PG_GETARG_TSQUERY_COPY, PG_RETURN_POINTER, QueryItem::qoperator, QT2QTN(), QTN2QT(), QTNFree(), TSQueryData::size, QueryItem::type, and QTNode::valnode.
{ TSQuery a = PG_GETARG_TSQUERY_COPY(0); QTNode *res; TSQuery query; if (a->size == 0) PG_RETURN_POINTER(a); res = (QTNode *) palloc0(sizeof(QTNode)); res->flags |= QTN_NEEDFREE; res->valnode = (QueryItem *) palloc0(sizeof(QueryItem)); res->valnode->type = QI_OPR; res->valnode->qoperator.oper = OP_NOT; res->child = (QTNode **) palloc0(sizeof(QTNode *)); res->child[0] = QT2QTN(GETQUERY(a), GETOPERAND(a)); res->nchild = 1; query = QTN2QT(res); QTNFree(res); PG_FREE_IF_COPY(a, 0); PG_RETURN_POINTER(query); }
Datum tsquery_numnode | ( | PG_FUNCTION_ARGS | ) |
Definition at line 20 of file tsquery_op.c.
References PG_FREE_IF_COPY, PG_GETARG_TSQUERY, PG_RETURN_INT32, and TSQueryData::size.
{ TSQuery query = PG_GETARG_TSQUERY(0); int nnode = query->size; PG_FREE_IF_COPY(query, 0); PG_RETURN_INT32(nnode); }
Datum tsquery_or | ( | PG_FUNCTION_ARGS | ) |
Definition at line 79 of file tsquery_op.c.
References join_tsqueries(), OP_OR, PG_FREE_IF_COPY, PG_GETARG_TSQUERY_COPY, PG_RETURN_POINTER, QTN2QT(), QTNFree(), and TSQueryData::size.
{ TSQuery a = PG_GETARG_TSQUERY_COPY(0); TSQuery b = PG_GETARG_TSQUERY_COPY(1); QTNode *res; TSQuery query; if (a->size == 0) { PG_FREE_IF_COPY(a, 1); PG_RETURN_POINTER(b); } else if (b->size == 0) { PG_FREE_IF_COPY(b, 1); PG_RETURN_POINTER(a); } res = join_tsqueries(a, b, OP_OR); query = QTN2QT(res); QTNFree(res); PG_FREE_IF_COPY(a, 0); PG_FREE_IF_COPY(b, 1); PG_RETURN_POINTER(query); }