00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef _PG_TS_UTILS_H_
00013 #define _PG_TS_UTILS_H_
00014
00015 #include "tsearch/ts_type.h"
00016 #include "tsearch/ts_public.h"
00017 #include "nodes/pg_list.h"
00018
00019
00020
00021
00022
00023
00024
00025 struct TSVectorParseStateData;
00026 typedef struct TSVectorParseStateData *TSVectorParseState;
00027
00028 extern TSVectorParseState init_tsvector_parser(char *input,
00029 bool oprisdelim,
00030 bool is_tsquery);
00031 extern void reset_tsvector_parser(TSVectorParseState state, char *input);
00032 extern bool gettoken_tsvector(TSVectorParseState state,
00033 char **token, int *len,
00034 WordEntryPos **pos, int *poslen,
00035 char **endptr);
00036 extern void close_tsvector_parser(TSVectorParseState state);
00037
00038
00039
00040 struct TSQueryParserStateData;
00041 typedef struct TSQueryParserStateData *TSQueryParserState;
00042
00043 typedef void (*PushFunction) (Datum opaque, TSQueryParserState state,
00044 char *token, int tokenlen,
00045 int16 tokenweights,
00046
00047
00048 bool prefix);
00049
00050 extern TSQuery parse_tsquery(char *buf,
00051 PushFunction pushval,
00052 Datum opaque, bool isplain);
00053
00054
00055 extern void pushValue(TSQueryParserState state,
00056 char *strval, int lenval, int16 weight, bool prefix);
00057 extern void pushStop(TSQueryParserState state);
00058 extern void pushOperator(TSQueryParserState state, int8 oper);
00059
00060
00061
00062
00063 typedef struct
00064 {
00065 uint16 len;
00066 uint16 nvariant;
00067 union
00068 {
00069 uint16 pos;
00070
00071
00072
00073
00074
00075
00076 uint16 *apos;
00077 } pos;
00078 uint16 flags;
00079 char *word;
00080 uint32 alen;
00081 } ParsedWord;
00082
00083 typedef struct
00084 {
00085 ParsedWord *words;
00086 int32 lenwords;
00087 int32 curwords;
00088 int32 pos;
00089 } ParsedText;
00090
00091 extern void parsetext(Oid cfgId, ParsedText *prs, char *buf, int32 buflen);
00092
00093
00094
00095
00096
00097
00098
00099
00100 extern void hlparsetext(Oid cfgId, HeadlineParsedText *prs, TSQuery query,
00101 char *buf, int32 buflen);
00102 extern text *generateHeadline(HeadlineParsedText *prs);
00103
00104
00105
00106
00107 extern bool TS_execute(QueryItem *curitem, void *checkval, bool calcnot,
00108 bool (*chkcond) (void *checkval, QueryOperand *val));
00109 extern bool tsquery_requires_match(QueryItem *curitem);
00110
00111
00112
00113
00114 extern TSVector make_tsvector(ParsedText *prs);
00115 extern int32 tsCompareString(char *a, int lena, char *b, int lenb, bool prefix);
00116
00117 extern Datum to_tsvector_byid(PG_FUNCTION_ARGS);
00118 extern Datum to_tsvector(PG_FUNCTION_ARGS);
00119 extern Datum to_tsquery_byid(PG_FUNCTION_ARGS);
00120 extern Datum to_tsquery(PG_FUNCTION_ARGS);
00121 extern Datum plainto_tsquery_byid(PG_FUNCTION_ARGS);
00122 extern Datum plainto_tsquery(PG_FUNCTION_ARGS);
00123
00124
00125
00126
00127
00128 extern Datum gtsvector_compress(PG_FUNCTION_ARGS);
00129 extern Datum gtsvector_decompress(PG_FUNCTION_ARGS);
00130 extern Datum gtsvector_consistent(PG_FUNCTION_ARGS);
00131 extern Datum gtsvector_union(PG_FUNCTION_ARGS);
00132 extern Datum gtsvector_same(PG_FUNCTION_ARGS);
00133 extern Datum gtsvector_penalty(PG_FUNCTION_ARGS);
00134 extern Datum gtsvector_picksplit(PG_FUNCTION_ARGS);
00135
00136
00137
00138
00139
00140 extern Datum gtsvectorin(PG_FUNCTION_ARGS);
00141 extern Datum gtsvectorout(PG_FUNCTION_ARGS);
00142
00143
00144
00145
00146
00147 extern Datum gin_extract_tsvector(PG_FUNCTION_ARGS);
00148 extern Datum gin_cmp_tslexeme(PG_FUNCTION_ARGS);
00149 extern Datum gin_cmp_prefix(PG_FUNCTION_ARGS);
00150 extern Datum gin_extract_tsquery(PG_FUNCTION_ARGS);
00151 extern Datum gin_tsquery_consistent(PG_FUNCTION_ARGS);
00152 extern Datum gin_extract_tsvector_2args(PG_FUNCTION_ARGS);
00153 extern Datum gin_extract_tsquery_5args(PG_FUNCTION_ARGS);
00154 extern Datum gin_tsquery_consistent_6args(PG_FUNCTION_ARGS);
00155
00156
00157
00158
00159
00160
00161 #define TSearchStrategyNumber 1
00162 #define TSearchWithClassStrategyNumber 2
00163
00164
00165
00166
00167 extern QueryItem *clean_NOT(QueryItem *ptr, int32 *len);
00168 extern QueryItem *clean_fakeval(QueryItem *ptr, int32 *len);
00169
00170 typedef struct QTNode
00171 {
00172 QueryItem *valnode;
00173 uint32 flags;
00174 int32 nchild;
00175 char *word;
00176 uint32 sign;
00177 struct QTNode **child;
00178 } QTNode;
00179
00180
00181 #define QTN_NEEDFREE 0x01
00182 #define QTN_NOCHANGE 0x02
00183 #define QTN_WORDFREE 0x04
00184
00185 typedef uint64 TSQuerySign;
00186
00187 #define TSQS_SIGLEN (sizeof(TSQuerySign)*BITS_PER_BYTE)
00188
00189 #define TSQuerySignGetDatum(X) Int64GetDatum((int64) (X))
00190 #define DatumGetTSQuerySign(X) ((TSQuerySign) DatumGetInt64(X))
00191 #define PG_RETURN_TSQUERYSIGN(X) return TSQuerySignGetDatum(X)
00192 #define PG_GETARG_TSQUERYSIGN(n) DatumGetTSQuerySign(PG_GETARG_DATUM(n))
00193
00194
00195 extern QTNode *QT2QTN(QueryItem *in, char *operand);
00196 extern TSQuery QTN2QT(QTNode *in);
00197 extern void QTNFree(QTNode *in);
00198 extern void QTNSort(QTNode *in);
00199 extern void QTNTernary(QTNode *in);
00200 extern void QTNBinary(QTNode *in);
00201 extern int QTNodeCompare(QTNode *an, QTNode *bn);
00202 extern QTNode *QTNCopy(QTNode *in);
00203 extern void QTNClearFlags(QTNode *in, uint32 flags);
00204 extern bool QTNEq(QTNode *a, QTNode *b);
00205 extern TSQuerySign makeTSQuerySign(TSQuery a);
00206 extern QTNode *findsubquery(QTNode *root, QTNode *ex, QTNode *subs,
00207 bool *isfind);
00208
00209
00210
00211
00212 extern Datum gtsquery_compress(PG_FUNCTION_ARGS);
00213 extern Datum gtsquery_decompress(PG_FUNCTION_ARGS);
00214 extern Datum gtsquery_consistent(PG_FUNCTION_ARGS);
00215 extern Datum gtsquery_union(PG_FUNCTION_ARGS);
00216 extern Datum gtsquery_same(PG_FUNCTION_ARGS);
00217 extern Datum gtsquery_penalty(PG_FUNCTION_ARGS);
00218 extern Datum gtsquery_picksplit(PG_FUNCTION_ARGS);
00219
00220
00221
00222
00223 extern Datum ts_token_type_byid(PG_FUNCTION_ARGS);
00224 extern Datum ts_token_type_byname(PG_FUNCTION_ARGS);
00225 extern Datum ts_parse_byid(PG_FUNCTION_ARGS);
00226 extern Datum ts_parse_byname(PG_FUNCTION_ARGS);
00227
00228
00229
00230
00231
00232 extern Datum prsd_start(PG_FUNCTION_ARGS);
00233 extern Datum prsd_nexttoken(PG_FUNCTION_ARGS);
00234 extern Datum prsd_end(PG_FUNCTION_ARGS);
00235 extern Datum prsd_headline(PG_FUNCTION_ARGS);
00236 extern Datum prsd_lextype(PG_FUNCTION_ARGS);
00237
00238
00239
00240
00241 extern Datum ts_lexize(PG_FUNCTION_ARGS);
00242
00243
00244
00245
00246 extern Datum dsimple_init(PG_FUNCTION_ARGS);
00247 extern Datum dsimple_lexize(PG_FUNCTION_ARGS);
00248
00249
00250
00251
00252 extern Datum dsynonym_init(PG_FUNCTION_ARGS);
00253 extern Datum dsynonym_lexize(PG_FUNCTION_ARGS);
00254
00255
00256
00257
00258 extern Datum dispell_init(PG_FUNCTION_ARGS);
00259 extern Datum dispell_lexize(PG_FUNCTION_ARGS);
00260
00261
00262
00263
00264 extern Datum thesaurus_init(PG_FUNCTION_ARGS);
00265 extern Datum thesaurus_lexize(PG_FUNCTION_ARGS);
00266
00267
00268
00269
00270 extern Datum ts_headline_byid_opt(PG_FUNCTION_ARGS);
00271 extern Datum ts_headline_byid(PG_FUNCTION_ARGS);
00272 extern Datum ts_headline(PG_FUNCTION_ARGS);
00273 extern Datum ts_headline_opt(PG_FUNCTION_ARGS);
00274
00275
00276
00277
00278 extern Datum get_current_ts_config(PG_FUNCTION_ARGS);
00279
00280 #endif