~ubuntu-branches/ubuntu/oneiric/postgresql-9.1/oneiric-security

« back to all changes in this revision

Viewing changes to src/include/tsearch/ts_utils.h

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2011-05-11 10:41:53 UTC
  • Revision ID: james.westby@ubuntu.com-20110511104153-psbh2o58553fv1m0
Tags: upstream-9.1~beta1
ImportĀ upstreamĀ versionĀ 9.1~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-------------------------------------------------------------------------
 
2
 *
 
3
 * ts_utils.h
 
4
 *        helper utilities for tsearch
 
5
 *
 
6
 * Copyright (c) 1998-2011, 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
                                                                                  int2 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, int2 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
        int4            lenwords;
 
87
        int4            curwords;
 
88
        int4            pos;
 
89
} ParsedText;
 
90
 
 
91
extern void parsetext(Oid cfgId, ParsedText *prs, char *buf, int4 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, int4 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_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);
 
155
 
 
156
/*
 
157
 * Possible strategy numbers for indexes
 
158
 *        TSearchStrategyNumber  - (tsvector|text) @@ tsquery
 
159
 *        TSearchWithClassStrategyNumber  - tsvector @@@ tsquery
 
160
 */
 
161
#define TSearchStrategyNumber                   1
 
162
#define TSearchWithClassStrategyNumber  2
 
163
 
 
164
/*
 
165
 * TSQuery Utilities
 
166
 */
 
167
extern QueryItem *clean_NOT(QueryItem *ptr, int4 *len);
 
168
extern QueryItem *clean_fakeval(QueryItem *ptr, int4 *len);
 
169
 
 
170
typedef struct QTNode
 
171
{
 
172
        QueryItem  *valnode;
 
173
        uint32          flags;
 
174
        int4            nchild;
 
175
        char       *word;
 
176
        uint32          sign;
 
177
        struct QTNode **child;
 
178
} QTNode;
 
179
 
 
180
/* bits in QTNode.flags */
 
181
#define QTN_NEEDFREE    0x01
 
182
#define QTN_NOCHANGE    0x02
 
183
#define QTN_WORDFREE    0x04
 
184
 
 
185
typedef uint64 TSQuerySign;
 
186
 
 
187
#define TSQS_SIGLEN  (sizeof(TSQuerySign)*BITS_PER_BYTE)
 
188
 
 
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))
 
193
 
 
194
 
 
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,
 
207
                         bool *isfind);
 
208
 
 
209
/*
 
210
 * TSQuery GiST support
 
211
 */
 
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);
 
219
 
 
220
/*
 
221
 * Parser interface to SQL
 
222
 */
 
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);
 
227
 
 
228
/*
 
229
 * Default word parser
 
230
 */
 
231
 
 
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);
 
237
 
 
238
/*
 
239
 * Dictionary interface to SQL
 
240
 */
 
241
extern Datum ts_lexize(PG_FUNCTION_ARGS);
 
242
 
 
243
/*
 
244
 * Simple built-in dictionary
 
245
 */
 
246
extern Datum dsimple_init(PG_FUNCTION_ARGS);
 
247
extern Datum dsimple_lexize(PG_FUNCTION_ARGS);
 
248
 
 
249
/*
 
250
 * Synonym built-in dictionary
 
251
 */
 
252
extern Datum dsynonym_init(PG_FUNCTION_ARGS);
 
253
extern Datum dsynonym_lexize(PG_FUNCTION_ARGS);
 
254
 
 
255
/*
 
256
 * ISpell dictionary
 
257
 */
 
258
extern Datum dispell_init(PG_FUNCTION_ARGS);
 
259
extern Datum dispell_lexize(PG_FUNCTION_ARGS);
 
260
 
 
261
/*
 
262
 * Thesaurus
 
263
 */
 
264
extern Datum thesaurus_init(PG_FUNCTION_ARGS);
 
265
extern Datum thesaurus_lexize(PG_FUNCTION_ARGS);
 
266
 
 
267
/*
 
268
 * headline
 
269
 */
 
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);
 
274
 
 
275
/*
 
276
 * current cfg
 
277
 */
 
278
extern Datum get_current_ts_config(PG_FUNCTION_ARGS);
 
279
 
 
280
#endif   /* _PG_TS_UTILS_H_ */