Fix xslt_process() to ensure that it inserts a NULL terminator after the
[PostgreSQL.git] / src / include / tsearch / ts_utils.h
blobc2f2c8af5531de4fd1041bde5c7090cb30536fbb
1 /*-------------------------------------------------------------------------
3 * ts_utils.h
4 * helper utilities for tsearch
6 * Copyright (c) 1998-2009, PostgreSQL Global Development Group
8 * $PostgreSQL$
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,
29 bool oprisdelim,
30 bool is_tsquery);
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,
35 char **endptr);
36 extern void close_tsvector_parser(TSVectorParseState state);
38 /* parse_tsquery */
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
46 * in QueryOperand
47 * struct */
48 bool prefix);
50 extern TSQuery parse_tsquery(char *buf,
51 PushFunction pushval,
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 operator);
61 * parse plain text and lexize words
63 typedef struct
65 uint16 len;
66 uint16 nvariant;
67 union
69 uint16 pos;
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
74 * array.
76 uint16 *apos;
77 } pos;
78 uint16 flags; /* currently, only TSL_PREFIX */
79 char *word;
80 uint32 alen;
81 } ParsedWord;
83 typedef struct
85 ParsedWord *words;
86 int4 lenwords;
87 int4 curwords;
88 int4 pos;
89 } ParsedText;
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
108 extern bool TS_execute(QueryItem *curitem, void *checkval, bool calcnot,
109 bool (*chkcond) (void *checkval, QueryOperand *val));
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);
154 * Possible strategy numbers for indexes
155 * TSearchStrategyNumber - (tsvector|text) @@ tsquery
156 * TSearchWithClassStrategyNumber - tsvector @@@ tsquery
158 #define TSearchStrategyNumber 1
159 #define TSearchWithClassStrategyNumber 2
162 * TSQuery Utilities
164 extern QueryItem *clean_NOT(QueryItem *ptr, int4 *len);
165 extern QueryItem *clean_fakeval(QueryItem *ptr, int4 *len);
167 typedef struct QTNode
169 QueryItem *valnode;
170 uint32 flags;
171 int4 nchild;
172 char *word;
173 uint32 sign;
174 struct QTNode **child;
175 } QTNode;
177 /* bits in QTNode.flags */
178 #define QTN_NEEDFREE 0x01
179 #define QTN_NOCHANGE 0x02
180 #define QTN_WORDFREE 0x04
182 typedef uint64 TSQuerySign;
184 #define TSQS_SIGLEN (sizeof(TSQuerySign)*BITS_PER_BYTE)
186 #define TSQuerySignGetDatum(X) Int64GetDatum((int64) (X))
187 #define DatumGetTSQuerySign(X) ((TSQuerySign) DatumGetInt64(X))
188 #define PG_RETURN_TSQUERYSIGN(X) return TSQuerySignGetDatum(X)
189 #define PG_GETARG_TSQUERYSIGN(n) DatumGetTSQuerySign(PG_GETARG_DATUM(n))
192 extern QTNode *QT2QTN(QueryItem *in, char *operand);
193 extern TSQuery QTN2QT(QTNode *in);
194 extern void QTNFree(QTNode *in);
195 extern void QTNSort(QTNode *in);
196 extern void QTNTernary(QTNode *in);
197 extern void QTNBinary(QTNode *in);
198 extern int QTNodeCompare(QTNode *an, QTNode *bn);
199 extern QTNode *QTNCopy(QTNode *in);
200 extern void QTNClearFlags(QTNode *in, uint32 flags);
201 extern bool QTNEq(QTNode *a, QTNode *b);
202 extern TSQuerySign makeTSQuerySign(TSQuery a);
203 extern QTNode *findsubquery(QTNode *root, QTNode *ex, QTNode *subs,
204 bool *isfind);
207 * TSQuery GiST support
209 extern Datum gtsquery_compress(PG_FUNCTION_ARGS);
210 extern Datum gtsquery_decompress(PG_FUNCTION_ARGS);
211 extern Datum gtsquery_consistent(PG_FUNCTION_ARGS);
212 extern Datum gtsquery_union(PG_FUNCTION_ARGS);
213 extern Datum gtsquery_same(PG_FUNCTION_ARGS);
214 extern Datum gtsquery_penalty(PG_FUNCTION_ARGS);
215 extern Datum gtsquery_picksplit(PG_FUNCTION_ARGS);
218 * Parser interface to SQL
220 extern Datum ts_token_type_byid(PG_FUNCTION_ARGS);
221 extern Datum ts_token_type_byname(PG_FUNCTION_ARGS);
222 extern Datum ts_parse_byid(PG_FUNCTION_ARGS);
223 extern Datum ts_parse_byname(PG_FUNCTION_ARGS);
226 * Default word parser
229 extern Datum prsd_start(PG_FUNCTION_ARGS);
230 extern Datum prsd_nexttoken(PG_FUNCTION_ARGS);
231 extern Datum prsd_end(PG_FUNCTION_ARGS);
232 extern Datum prsd_headline(PG_FUNCTION_ARGS);
233 extern Datum prsd_lextype(PG_FUNCTION_ARGS);
236 * Dictionary interface to SQL
238 extern Datum ts_lexize(PG_FUNCTION_ARGS);
241 * Simple built-in dictionary
243 extern Datum dsimple_init(PG_FUNCTION_ARGS);
244 extern Datum dsimple_lexize(PG_FUNCTION_ARGS);
247 * Synonym built-in dictionary
249 extern Datum dsynonym_init(PG_FUNCTION_ARGS);
250 extern Datum dsynonym_lexize(PG_FUNCTION_ARGS);
253 * ISpell dictionary
255 extern Datum dispell_init(PG_FUNCTION_ARGS);
256 extern Datum dispell_lexize(PG_FUNCTION_ARGS);
259 * Thesaurus
261 extern Datum thesaurus_init(PG_FUNCTION_ARGS);
262 extern Datum thesaurus_lexize(PG_FUNCTION_ARGS);
265 * headline
267 extern Datum ts_headline_byid_opt(PG_FUNCTION_ARGS);
268 extern Datum ts_headline_byid(PG_FUNCTION_ARGS);
269 extern Datum ts_headline(PG_FUNCTION_ARGS);
270 extern Datum ts_headline_opt(PG_FUNCTION_ARGS);
273 * current cfg
275 extern Datum get_current_ts_config(PG_FUNCTION_ARGS);
277 #endif /* _PG_TS_UTILS_H_ */