1 /*-------------------------------------------------------------------------
4 * helper utilities for tsearch
6 * Copyright (c) 1998-2007, PostgreSQL Global Development Group
8 * $PostgreSQL: pgsql/src/include/tsearch/ts_utils.h,v 1.4 2007/09/10 12:36:41 teodor Exp $
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;
26 typedef struct TSVectorParseStateData *TSVectorParseState;
28 extern TSVectorParseState init_tsvector_parser(char *input, bool oprisdelim);
29 extern void reset_tsvector_parser(TSVectorParseState state, char *input);
30 extern bool gettoken_tsvector(TSVectorParseState state,
31 char **token, int *len,
32 WordEntryPos **pos, int *poslen,
34 extern void close_tsvector_parser(TSVectorParseState state);
38 struct TSQueryParserStateData; /* private in backend/utils/adt/tsquery.c */
39 typedef struct TSQueryParserStateData *TSQueryParserState;
41 typedef void (*PushFunction)(Datum opaque, TSQueryParserState state,
42 char *token, int tokenlen,
43 int2 tokenweights /* bitmap as described in QueryOperand struct */ );
45 extern TSQuery parse_tsquery(char *buf,
47 Datum opaque, bool isplain);
49 /* Functions for use by PushFunction implementations */
50 extern void pushValue(TSQueryParserState state,
51 char *strval, int lenval, int2 weight);
52 extern void pushStop(TSQueryParserState state);
53 extern void pushOperator(TSQueryParserState state, int8 operator);
56 * parse plain text and lexize words
66 * When apos array is used, apos[0] is the number of elements
67 * in the array (excluding apos[0]), and alen is the allocated
84 extern void parsetext(Oid cfgId, ParsedText * prs, char *buf, int4 buflen);
87 * headline framework, flow in common to generate:
88 * 1 parse text with hlparsetext
89 * 2 parser-specific function to find part
90 * 3 generateHeadline to generate result text
93 extern void hlparsetext(Oid cfgId, HeadlineParsedText * prs, TSQuery query,
94 char *buf, int4 buflen);
95 extern text *generateHeadline(HeadlineParsedText * prs);
98 * Common check function for tsvector @@ tsquery
101 extern bool TS_execute(QueryItem * curitem, void *checkval, bool calcnot,
102 bool (*chkcond) (void *checkval, QueryOperand * val));
105 * Useful conversion macros
107 #define TextPGetCString(t) DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(t)))
108 #define CStringGetTextP(c) DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(c)))
111 * to_ts* - text transformation to tsvector, tsquery
113 extern TSVector make_tsvector(ParsedText *prs);
115 extern Datum to_tsvector_byid(PG_FUNCTION_ARGS);
116 extern Datum to_tsvector(PG_FUNCTION_ARGS);
117 extern Datum to_tsquery_byid(PG_FUNCTION_ARGS);
118 extern Datum to_tsquery(PG_FUNCTION_ARGS);
119 extern Datum plainto_tsquery_byid(PG_FUNCTION_ARGS);
120 extern Datum plainto_tsquery(PG_FUNCTION_ARGS);
123 * GiST support function
126 extern Datum gtsvector_compress(PG_FUNCTION_ARGS);
127 extern Datum gtsvector_decompress(PG_FUNCTION_ARGS);
128 extern Datum gtsvector_consistent(PG_FUNCTION_ARGS);
129 extern Datum gtsvector_union(PG_FUNCTION_ARGS);
130 extern Datum gtsvector_same(PG_FUNCTION_ARGS);
131 extern Datum gtsvector_penalty(PG_FUNCTION_ARGS);
132 extern Datum gtsvector_picksplit(PG_FUNCTION_ARGS);
135 * IO functions for pseudotype gtsvector
136 * used internally in tsvector GiST opclass
138 extern Datum gtsvectorin(PG_FUNCTION_ARGS);
139 extern Datum gtsvectorout(PG_FUNCTION_ARGS);
142 * GIN support function
145 extern Datum gin_extract_tsvector(PG_FUNCTION_ARGS);
146 extern Datum gin_extract_query(PG_FUNCTION_ARGS);
147 extern Datum gin_ts_consistent(PG_FUNCTION_ARGS);
150 * Possible strategy numbers for indexes
151 * TSearchStrategyNumber - (tsvector|text) @@ tsquery
152 * TSearchWithClassStrategyNumber - tsvector @@@ tsquery
154 #define TSearchStrategyNumber 1
155 #define TSearchWithClassStrategyNumber 2
160 extern QueryItem *clean_NOT(QueryItem * ptr, int4 *len);
161 extern QueryItem *clean_fakeval(QueryItem * ptr, int4 *len);
163 typedef struct QTNode
170 struct QTNode **child;
173 #define QTN_NEEDFREE 0x01
174 #define QTN_NOCHANGE 0x02
175 #define QTN_WORDFREE 0x04
177 typedef uint64 TSQuerySign;
179 #define TSQS_SIGLEN (sizeof(TSQuerySign)*BITS_PER_BYTE)
182 extern QTNode *QT2QTN(QueryItem * in, char *operand);
183 extern TSQuery QTN2QT(QTNode *in);
184 extern void QTNFree(QTNode * in);
185 extern void QTNSort(QTNode * in);
186 extern void QTNTernary(QTNode * in);
187 extern void QTNBinary(QTNode * in);
188 extern int QTNodeCompare(QTNode * an, QTNode * bn);
189 extern QTNode *QTNCopy(QTNode *in);
190 extern bool QTNEq(QTNode * a, QTNode * b);
191 extern TSQuerySign makeTSQuerySign(TSQuery a);
194 * TSQuery GiST support
196 extern Datum gtsquery_compress(PG_FUNCTION_ARGS);
197 extern Datum gtsquery_decompress(PG_FUNCTION_ARGS);
198 extern Datum gtsquery_consistent(PG_FUNCTION_ARGS);
199 extern Datum gtsquery_union(PG_FUNCTION_ARGS);
200 extern Datum gtsquery_same(PG_FUNCTION_ARGS);
201 extern Datum gtsquery_penalty(PG_FUNCTION_ARGS);
202 extern Datum gtsquery_picksplit(PG_FUNCTION_ARGS);
205 * Parser interface to SQL
207 extern Datum ts_token_type_byid(PG_FUNCTION_ARGS);
208 extern Datum ts_token_type_byname(PG_FUNCTION_ARGS);
209 extern Datum ts_parse_byid(PG_FUNCTION_ARGS);
210 extern Datum ts_parse_byname(PG_FUNCTION_ARGS);
213 * Default word parser
216 extern Datum prsd_start(PG_FUNCTION_ARGS);
217 extern Datum prsd_nexttoken(PG_FUNCTION_ARGS);
218 extern Datum prsd_end(PG_FUNCTION_ARGS);
219 extern Datum prsd_headline(PG_FUNCTION_ARGS);
220 extern Datum prsd_lextype(PG_FUNCTION_ARGS);
223 * Dictionary interface to SQL
225 extern Datum ts_lexize_byid(PG_FUNCTION_ARGS);
226 extern Datum ts_lexize_byname(PG_FUNCTION_ARGS);
229 * Simple built-in dictionary
231 extern Datum dsimple_init(PG_FUNCTION_ARGS);
232 extern Datum dsimple_lexize(PG_FUNCTION_ARGS);
235 * Synonym built-in dictionary
237 extern Datum dsynonym_init(PG_FUNCTION_ARGS);
238 extern Datum dsynonym_lexize(PG_FUNCTION_ARGS);
243 extern Datum dispell_init(PG_FUNCTION_ARGS);
244 extern Datum dispell_lexize(PG_FUNCTION_ARGS);
249 extern Datum thesaurus_init(PG_FUNCTION_ARGS);
250 extern Datum thesaurus_lexize(PG_FUNCTION_ARGS);
255 extern Datum ts_headline_byid_opt(PG_FUNCTION_ARGS);
256 extern Datum ts_headline_byid(PG_FUNCTION_ARGS);
257 extern Datum ts_headline(PG_FUNCTION_ARGS);
258 extern Datum ts_headline_opt(PG_FUNCTION_ARGS);
263 extern Datum get_current_ts_config(PG_FUNCTION_ARGS);
265 #endif /* _PG_TS_UTILS_H_ */