OSDN Git Service

rebuid:
[eos/hostdependX86MAC64.git] / util / X86MAC64 / include / postgresql / server / tsearch / ts_utils.h
1 /*-------------------------------------------------------------------------
2  *
3  * ts_utils.h
4  *        helper utilities for tsearch
5  *
6  * Copyright (c) 1998-2014, PostgreSQL Global Development Group
7  *
8  * src/include/tsearch/ts_utils.h
9  *
10  *-------------------------------------------------------------------------
11  */
12 #ifndef _PG_TS_UTILS_H_
13 #define _PG_TS_UTILS_H_
14
15 #include "tsearch/ts_type.h"
16 #include "tsearch/ts_public.h"
17 #include "nodes/pg_list.h"
18
19 /*
20  * Common parse definitions for tsvector and tsquery
21  */
22
23 /* tsvector parser support. */
24
25 struct TSVectorParseStateData;  /* opaque struct in tsvector_parser.c */
26 typedef struct TSVectorParseStateData *TSVectorParseState;
27
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);
37
38 /* parse_tsquery */
39
40 struct TSQueryParserStateData;  /* private in backend/utils/adt/tsquery.c */
41 typedef struct TSQueryParserStateData *TSQueryParserState;
42
43 typedef void (*PushFunction) (Datum opaque, TSQueryParserState state,
44                                                                                   char *token, int tokenlen,
45                                                                                   int16 tokenweights,   /* bitmap as described
46                                                                                                                                  * in QueryOperand
47                                                                                                                                  * struct */
48                                                                                   bool prefix);
49
50 extern TSQuery parse_tsquery(char *buf,
51                           PushFunction pushval,
52                           Datum opaque, bool isplain);
53
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);
59
60 /*
61  * parse plain text and lexize words
62  */
63 typedef struct
64 {
65         uint16          len;
66         uint16          nvariant;
67         union
68         {
69                 uint16          pos;
70
71                 /*
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.
75                  */
76                 uint16     *apos;
77         }                       pos;
78         uint16          flags;                  /* currently, only TSL_PREFIX */
79         char       *word;
80         uint32          alen;
81 } ParsedWord;
82
83 typedef struct
84 {
85         ParsedWord *words;
86         int32           lenwords;
87         int32           curwords;
88         int32           pos;
89 } ParsedText;
90
91 extern void parsetext(Oid cfgId, ParsedText *prs, char *buf, int32 buflen);
92
93 /*
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
98  */
99
100 extern void hlparsetext(Oid cfgId, HeadlineParsedText *prs, TSQuery query,
101                         char *buf, int32 buflen);
102 extern text *generateHeadline(HeadlineParsedText *prs);
103
104 /*
105  * Common check function for tsvector @@ tsquery
106  */
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);
110
111 /*
112  * to_ts* - text transformation to tsvector, tsquery
113  */
114 extern TSVector make_tsvector(ParsedText *prs);
115 extern int32 tsCompareString(char *a, int lena, char *b, int lenb, bool prefix);
116
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);
123
124 /*
125  * GiST support function
126  */
127
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);
135
136 /*
137  * IO functions for pseudotype gtsvector
138  * used internally in tsvector GiST opclass
139  */
140 extern Datum gtsvectorin(PG_FUNCTION_ARGS);
141 extern Datum gtsvectorout(PG_FUNCTION_ARGS);
142
143 /*
144  * GIN support function
145  */
146
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);
156
157 /*
158  * Possible strategy numbers for indexes
159  *        TSearchStrategyNumber  - (tsvector|text) @@ tsquery
160  *        TSearchWithClassStrategyNumber  - tsvector @@@ tsquery
161  */
162 #define TSearchStrategyNumber                   1
163 #define TSearchWithClassStrategyNumber  2
164
165 /*
166  * TSQuery Utilities
167  */
168 extern QueryItem *clean_NOT(QueryItem *ptr, int32 *len);
169 extern QueryItem *clean_fakeval(QueryItem *ptr, int32 *len);
170
171 typedef struct QTNode
172 {
173         QueryItem  *valnode;
174         uint32          flags;
175         int32           nchild;
176         char       *word;
177         uint32          sign;
178         struct QTNode **child;
179 } QTNode;
180
181 /* bits in QTNode.flags */
182 #define QTN_NEEDFREE    0x01
183 #define QTN_NOCHANGE    0x02
184 #define QTN_WORDFREE    0x04
185
186 typedef uint64 TSQuerySign;
187
188 #define TSQS_SIGLEN  (sizeof(TSQuerySign)*BITS_PER_BYTE)
189
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))
194
195
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,
208                          bool *isfind);
209
210 /*
211  * TSQuery GiST support
212  */
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);
220
221 /*
222  * Parser interface to SQL
223  */
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);
228
229 /*
230  * Default word parser
231  */
232
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);
238
239 /*
240  * Dictionary interface to SQL
241  */
242 extern Datum ts_lexize(PG_FUNCTION_ARGS);
243
244 /*
245  * Simple built-in dictionary
246  */
247 extern Datum dsimple_init(PG_FUNCTION_ARGS);
248 extern Datum dsimple_lexize(PG_FUNCTION_ARGS);
249
250 /*
251  * Synonym built-in dictionary
252  */
253 extern Datum dsynonym_init(PG_FUNCTION_ARGS);
254 extern Datum dsynonym_lexize(PG_FUNCTION_ARGS);
255
256 /*
257  * ISpell dictionary
258  */
259 extern Datum dispell_init(PG_FUNCTION_ARGS);
260 extern Datum dispell_lexize(PG_FUNCTION_ARGS);
261
262 /*
263  * Thesaurus
264  */
265 extern Datum thesaurus_init(PG_FUNCTION_ARGS);
266 extern Datum thesaurus_lexize(PG_FUNCTION_ARGS);
267
268 /*
269  * headline
270  */
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);
275
276 /*
277  * current cfg
278  */
279 extern Datum get_current_ts_config(PG_FUNCTION_ARGS);
280
281 #endif   /* _PG_TS_UTILS_H_ */