1 /*-------------------------------------------------------------------------
4 * helper utilities for tsearch
6 * Copyright (c) 1998-2014, PostgreSQL Global Development Group
8 * src/include/tsearch/ts_utils.h
10 *-------------------------------------------------------------------------
12 #ifndef _PG_TS_UTILS_H_
13 #define _PG_TS_UTILS_H_
15 #include "tsearch/ts_type.h"
16 #include "tsearch/ts_public.h"
17 #include "nodes/pg_list.h"
20 * Common parse definitions for tsvector and tsquery
23 /* tsvector parser support. */
25 struct TSVectorParseStateData; /* opaque struct in tsvector_parser.c */
26 typedef struct TSVectorParseStateData *TSVectorParseState;
28 extern TSVectorParseState init_tsvector_parser(char *input,
31 extern void reset_tsvector_parser(TSVectorParseState state, char *input);
32 extern bool gettoken_tsvector(TSVectorParseState state,
33 char **token, int *len,
34 WordEntryPos **pos, int *poslen,
36 extern void close_tsvector_parser(TSVectorParseState state);
40 struct TSQueryParserStateData; /* private in backend/utils/adt/tsquery.c */
41 typedef struct TSQueryParserStateData *TSQueryParserState;
43 typedef void (*PushFunction) (Datum opaque, TSQueryParserState state,
44 char *token, int tokenlen,
45 int16 tokenweights, /* bitmap as described
50 extern TSQuery parse_tsquery(char *buf,
52 Datum opaque, bool isplain);
54 /* Functions for use by PushFunction implementations */
55 extern void pushValue(TSQueryParserState state,
56 char *strval, int lenval, int16 weight, bool prefix);
57 extern void pushStop(TSQueryParserState state);
58 extern void pushOperator(TSQueryParserState state, int8 oper);
61 * parse plain text and lexize words
72 * When apos array is used, apos[0] is the number of elements in the
73 * array (excluding apos[0]), and alen is the allocated size of the
78 uint16 flags; /* currently, only TSL_PREFIX */
91 extern void parsetext(Oid cfgId, ParsedText *prs, char *buf, int32 buflen);
94 * headline framework, flow in common to generate:
95 * 1 parse text with hlparsetext
96 * 2 parser-specific function to find part
97 * 3 generateHeadline to generate result text
100 extern void hlparsetext(Oid cfgId, HeadlineParsedText *prs, TSQuery query,
101 char *buf, int32 buflen);
102 extern text *generateHeadline(HeadlineParsedText *prs);
105 * Common check function for tsvector @@ tsquery
107 extern bool TS_execute(QueryItem *curitem, void *checkval, bool calcnot,
108 bool (*chkcond) (void *checkval, QueryOperand *val));
109 extern bool tsquery_requires_match(QueryItem *curitem);
112 * to_ts* - text transformation to tsvector, tsquery
114 extern TSVector make_tsvector(ParsedText *prs);
115 extern int32 tsCompareString(char *a, int lena, char *b, int lenb, bool prefix);
117 extern Datum to_tsvector_byid(PG_FUNCTION_ARGS);
118 extern Datum to_tsvector(PG_FUNCTION_ARGS);
119 extern Datum to_tsquery_byid(PG_FUNCTION_ARGS);
120 extern Datum to_tsquery(PG_FUNCTION_ARGS);
121 extern Datum plainto_tsquery_byid(PG_FUNCTION_ARGS);
122 extern Datum plainto_tsquery(PG_FUNCTION_ARGS);
125 * GiST support function
128 extern Datum gtsvector_compress(PG_FUNCTION_ARGS);
129 extern Datum gtsvector_decompress(PG_FUNCTION_ARGS);
130 extern Datum gtsvector_consistent(PG_FUNCTION_ARGS);
131 extern Datum gtsvector_union(PG_FUNCTION_ARGS);
132 extern Datum gtsvector_same(PG_FUNCTION_ARGS);
133 extern Datum gtsvector_penalty(PG_FUNCTION_ARGS);
134 extern Datum gtsvector_picksplit(PG_FUNCTION_ARGS);
137 * IO functions for pseudotype gtsvector
138 * used internally in tsvector GiST opclass
140 extern Datum gtsvectorin(PG_FUNCTION_ARGS);
141 extern Datum gtsvectorout(PG_FUNCTION_ARGS);
144 * GIN support function
147 extern Datum gin_extract_tsvector(PG_FUNCTION_ARGS);
148 extern Datum gin_cmp_tslexeme(PG_FUNCTION_ARGS);
149 extern Datum gin_cmp_prefix(PG_FUNCTION_ARGS);
150 extern Datum gin_extract_tsquery(PG_FUNCTION_ARGS);
151 extern Datum gin_tsquery_consistent(PG_FUNCTION_ARGS);
152 extern Datum gin_tsquery_triconsistent(PG_FUNCTION_ARGS);
153 extern Datum gin_extract_tsvector_2args(PG_FUNCTION_ARGS);
154 extern Datum gin_extract_tsquery_5args(PG_FUNCTION_ARGS);
155 extern Datum gin_tsquery_consistent_6args(PG_FUNCTION_ARGS);
158 * Possible strategy numbers for indexes
159 * TSearchStrategyNumber - (tsvector|text) @@ tsquery
160 * TSearchWithClassStrategyNumber - tsvector @@@ tsquery
162 #define TSearchStrategyNumber 1
163 #define TSearchWithClassStrategyNumber 2
168 extern QueryItem *clean_NOT(QueryItem *ptr, int32 *len);
169 extern QueryItem *clean_fakeval(QueryItem *ptr, int32 *len);
171 typedef struct QTNode
178 struct QTNode **child;
181 /* bits in QTNode.flags */
182 #define QTN_NEEDFREE 0x01
183 #define QTN_NOCHANGE 0x02
184 #define QTN_WORDFREE 0x04
186 typedef uint64 TSQuerySign;
188 #define TSQS_SIGLEN (sizeof(TSQuerySign)*BITS_PER_BYTE)
190 #define TSQuerySignGetDatum(X) Int64GetDatum((int64) (X))
191 #define DatumGetTSQuerySign(X) ((TSQuerySign) DatumGetInt64(X))
192 #define PG_RETURN_TSQUERYSIGN(X) return TSQuerySignGetDatum(X)
193 #define PG_GETARG_TSQUERYSIGN(n) DatumGetTSQuerySign(PG_GETARG_DATUM(n))
196 extern QTNode *QT2QTN(QueryItem *in, char *operand);
197 extern TSQuery QTN2QT(QTNode *in);
198 extern void QTNFree(QTNode *in);
199 extern void QTNSort(QTNode *in);
200 extern void QTNTernary(QTNode *in);
201 extern void QTNBinary(QTNode *in);
202 extern int QTNodeCompare(QTNode *an, QTNode *bn);
203 extern QTNode *QTNCopy(QTNode *in);
204 extern void QTNClearFlags(QTNode *in, uint32 flags);
205 extern bool QTNEq(QTNode *a, QTNode *b);
206 extern TSQuerySign makeTSQuerySign(TSQuery a);
207 extern QTNode *findsubquery(QTNode *root, QTNode *ex, QTNode *subs,
211 * TSQuery GiST support
213 extern Datum gtsquery_compress(PG_FUNCTION_ARGS);
214 extern Datum gtsquery_decompress(PG_FUNCTION_ARGS);
215 extern Datum gtsquery_consistent(PG_FUNCTION_ARGS);
216 extern Datum gtsquery_union(PG_FUNCTION_ARGS);
217 extern Datum gtsquery_same(PG_FUNCTION_ARGS);
218 extern Datum gtsquery_penalty(PG_FUNCTION_ARGS);
219 extern Datum gtsquery_picksplit(PG_FUNCTION_ARGS);
222 * Parser interface to SQL
224 extern Datum ts_token_type_byid(PG_FUNCTION_ARGS);
225 extern Datum ts_token_type_byname(PG_FUNCTION_ARGS);
226 extern Datum ts_parse_byid(PG_FUNCTION_ARGS);
227 extern Datum ts_parse_byname(PG_FUNCTION_ARGS);
230 * Default word parser
233 extern Datum prsd_start(PG_FUNCTION_ARGS);
234 extern Datum prsd_nexttoken(PG_FUNCTION_ARGS);
235 extern Datum prsd_end(PG_FUNCTION_ARGS);
236 extern Datum prsd_headline(PG_FUNCTION_ARGS);
237 extern Datum prsd_lextype(PG_FUNCTION_ARGS);
240 * Dictionary interface to SQL
242 extern Datum ts_lexize(PG_FUNCTION_ARGS);
245 * Simple built-in dictionary
247 extern Datum dsimple_init(PG_FUNCTION_ARGS);
248 extern Datum dsimple_lexize(PG_FUNCTION_ARGS);
251 * Synonym built-in dictionary
253 extern Datum dsynonym_init(PG_FUNCTION_ARGS);
254 extern Datum dsynonym_lexize(PG_FUNCTION_ARGS);
259 extern Datum dispell_init(PG_FUNCTION_ARGS);
260 extern Datum dispell_lexize(PG_FUNCTION_ARGS);
265 extern Datum thesaurus_init(PG_FUNCTION_ARGS);
266 extern Datum thesaurus_lexize(PG_FUNCTION_ARGS);
271 extern Datum ts_headline_byid_opt(PG_FUNCTION_ARGS);
272 extern Datum ts_headline_byid(PG_FUNCTION_ARGS);
273 extern Datum ts_headline(PG_FUNCTION_ARGS);
274 extern Datum ts_headline_opt(PG_FUNCTION_ARGS);
279 extern Datum get_current_ts_config(PG_FUNCTION_ARGS);
281 #endif /* _PG_TS_UTILS_H_ */