1
/*-------------------------------------------------------------------------
4
* helper utilities for tsearch
6
* Copyright (c) 1998-2011, 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
int2 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, int2 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, int4 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, int4 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_extract_tsvector_2args(PG_FUNCTION_ARGS);
153
extern Datum gin_extract_tsquery_5args(PG_FUNCTION_ARGS);
154
extern Datum gin_tsquery_consistent_6args(PG_FUNCTION_ARGS);
157
* Possible strategy numbers for indexes
158
* TSearchStrategyNumber - (tsvector|text) @@ tsquery
159
* TSearchWithClassStrategyNumber - tsvector @@@ tsquery
161
#define TSearchStrategyNumber 1
162
#define TSearchWithClassStrategyNumber 2
167
extern QueryItem *clean_NOT(QueryItem *ptr, int4 *len);
168
extern QueryItem *clean_fakeval(QueryItem *ptr, int4 *len);
170
typedef struct QTNode
177
struct QTNode **child;
180
/* bits in QTNode.flags */
181
#define QTN_NEEDFREE 0x01
182
#define QTN_NOCHANGE 0x02
183
#define QTN_WORDFREE 0x04
185
typedef uint64 TSQuerySign;
187
#define TSQS_SIGLEN (sizeof(TSQuerySign)*BITS_PER_BYTE)
189
#define TSQuerySignGetDatum(X) Int64GetDatum((int64) (X))
190
#define DatumGetTSQuerySign(X) ((TSQuerySign) DatumGetInt64(X))
191
#define PG_RETURN_TSQUERYSIGN(X) return TSQuerySignGetDatum(X)
192
#define PG_GETARG_TSQUERYSIGN(n) DatumGetTSQuerySign(PG_GETARG_DATUM(n))
195
extern QTNode *QT2QTN(QueryItem *in, char *operand);
196
extern TSQuery QTN2QT(QTNode *in);
197
extern void QTNFree(QTNode *in);
198
extern void QTNSort(QTNode *in);
199
extern void QTNTernary(QTNode *in);
200
extern void QTNBinary(QTNode *in);
201
extern int QTNodeCompare(QTNode *an, QTNode *bn);
202
extern QTNode *QTNCopy(QTNode *in);
203
extern void QTNClearFlags(QTNode *in, uint32 flags);
204
extern bool QTNEq(QTNode *a, QTNode *b);
205
extern TSQuerySign makeTSQuerySign(TSQuery a);
206
extern QTNode *findsubquery(QTNode *root, QTNode *ex, QTNode *subs,
210
* TSQuery GiST support
212
extern Datum gtsquery_compress(PG_FUNCTION_ARGS);
213
extern Datum gtsquery_decompress(PG_FUNCTION_ARGS);
214
extern Datum gtsquery_consistent(PG_FUNCTION_ARGS);
215
extern Datum gtsquery_union(PG_FUNCTION_ARGS);
216
extern Datum gtsquery_same(PG_FUNCTION_ARGS);
217
extern Datum gtsquery_penalty(PG_FUNCTION_ARGS);
218
extern Datum gtsquery_picksplit(PG_FUNCTION_ARGS);
221
* Parser interface to SQL
223
extern Datum ts_token_type_byid(PG_FUNCTION_ARGS);
224
extern Datum ts_token_type_byname(PG_FUNCTION_ARGS);
225
extern Datum ts_parse_byid(PG_FUNCTION_ARGS);
226
extern Datum ts_parse_byname(PG_FUNCTION_ARGS);
229
* Default word parser
232
extern Datum prsd_start(PG_FUNCTION_ARGS);
233
extern Datum prsd_nexttoken(PG_FUNCTION_ARGS);
234
extern Datum prsd_end(PG_FUNCTION_ARGS);
235
extern Datum prsd_headline(PG_FUNCTION_ARGS);
236
extern Datum prsd_lextype(PG_FUNCTION_ARGS);
239
* Dictionary interface to SQL
241
extern Datum ts_lexize(PG_FUNCTION_ARGS);
244
* Simple built-in dictionary
246
extern Datum dsimple_init(PG_FUNCTION_ARGS);
247
extern Datum dsimple_lexize(PG_FUNCTION_ARGS);
250
* Synonym built-in dictionary
252
extern Datum dsynonym_init(PG_FUNCTION_ARGS);
253
extern Datum dsynonym_lexize(PG_FUNCTION_ARGS);
258
extern Datum dispell_init(PG_FUNCTION_ARGS);
259
extern Datum dispell_lexize(PG_FUNCTION_ARGS);
264
extern Datum thesaurus_init(PG_FUNCTION_ARGS);
265
extern Datum thesaurus_lexize(PG_FUNCTION_ARGS);
270
extern Datum ts_headline_byid_opt(PG_FUNCTION_ARGS);
271
extern Datum ts_headline_byid(PG_FUNCTION_ARGS);
272
extern Datum ts_headline(PG_FUNCTION_ARGS);
273
extern Datum ts_headline_opt(PG_FUNCTION_ARGS);
278
extern Datum get_current_ts_config(PG_FUNCTION_ARGS);
280
#endif /* _PG_TS_UTILS_H_ */