init
This commit is contained in:
49
pg_include/tsearch/dicts/regis.h
Executable file
49
pg_include/tsearch/dicts/regis.h
Executable file
@@ -0,0 +1,49 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* regis.h
|
||||
*
|
||||
* Declarations for fast regex subset, used by ISpell
|
||||
*
|
||||
* Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
|
||||
*
|
||||
* src/include/tsearch/dicts/regis.h
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef __REGIS_H__
|
||||
#define __REGIS_H__
|
||||
|
||||
typedef struct RegisNode
|
||||
{
|
||||
uint32
|
||||
type:2,
|
||||
len:16,
|
||||
unused:14;
|
||||
struct RegisNode *next;
|
||||
unsigned char data[1];
|
||||
} RegisNode;
|
||||
|
||||
#define RNHDRSZ (offsetof(RegisNode,data))
|
||||
|
||||
#define RSF_ONEOF 1
|
||||
#define RSF_NONEOF 2
|
||||
|
||||
typedef struct Regis
|
||||
{
|
||||
RegisNode *node;
|
||||
uint32
|
||||
issuffix:1,
|
||||
nchar:16,
|
||||
unused:15;
|
||||
} Regis;
|
||||
|
||||
bool RS_isRegis(const char *str);
|
||||
|
||||
void RS_compile(Regis *r, bool issuffix, const char *str);
|
||||
void RS_free(Regis *r);
|
||||
|
||||
/*returns true if matches */
|
||||
bool RS_execute(Regis *r, char *str);
|
||||
|
||||
#endif
|
||||
179
pg_include/tsearch/dicts/spell.h
Executable file
179
pg_include/tsearch/dicts/spell.h
Executable file
@@ -0,0 +1,179 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* spell.h
|
||||
*
|
||||
* Declarations for ISpell dictionary
|
||||
*
|
||||
* Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
|
||||
*
|
||||
* src/include/tsearch/dicts/spell.h
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef __SPELL_H__
|
||||
#define __SPELL_H__
|
||||
|
||||
#include "regex/regex.h"
|
||||
#include "tsearch/dicts/regis.h"
|
||||
#include "tsearch/ts_public.h"
|
||||
|
||||
/*
|
||||
* Max length of a flag name. Names longer than this will be truncated
|
||||
* to the maximum.
|
||||
*/
|
||||
#define MAXFLAGLEN 16
|
||||
|
||||
struct SPNode;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32 val:8,
|
||||
isword:1,
|
||||
compoundflag:4,
|
||||
affix:19;
|
||||
struct SPNode *node;
|
||||
} SPNodeData;
|
||||
|
||||
/*
|
||||
* Names of FF_ are correlated with Hunspell options in affix file
|
||||
* http://hunspell.sourceforge.net/
|
||||
*/
|
||||
#define FF_COMPOUNDONLY 0x01
|
||||
#define FF_COMPOUNDBEGIN 0x02
|
||||
#define FF_COMPOUNDMIDDLE 0x04
|
||||
#define FF_COMPOUNDLAST 0x08
|
||||
#define FF_COMPOUNDFLAG ( FF_COMPOUNDBEGIN | FF_COMPOUNDMIDDLE | FF_COMPOUNDLAST )
|
||||
#define FF_DICTFLAGMASK 0x0f
|
||||
|
||||
typedef struct SPNode
|
||||
{
|
||||
uint32 length;
|
||||
SPNodeData data[1];
|
||||
} SPNode;
|
||||
|
||||
#define SPNHDRSZ (offsetof(SPNode,data))
|
||||
|
||||
|
||||
typedef struct spell_struct
|
||||
{
|
||||
union
|
||||
{
|
||||
/*
|
||||
* flag is filled in by NIImportDictionary. After NISortDictionary, d
|
||||
* is valid and flag is invalid.
|
||||
*/
|
||||
char flag[MAXFLAGLEN];
|
||||
struct
|
||||
{
|
||||
int affix;
|
||||
int len;
|
||||
} d;
|
||||
} p;
|
||||
char word[1]; /* variable length, null-terminated */
|
||||
} SPELL;
|
||||
|
||||
#define SPELLHDRSZ (offsetof(SPELL, word))
|
||||
|
||||
typedef struct aff_struct
|
||||
{
|
||||
uint32 flag:8,
|
||||
type:1,
|
||||
flagflags:7,
|
||||
issimple:1,
|
||||
isregis:1,
|
||||
replen:14;
|
||||
char *find;
|
||||
char *repl;
|
||||
union
|
||||
{
|
||||
regex_t regex;
|
||||
Regis regis;
|
||||
} reg;
|
||||
} AFFIX;
|
||||
|
||||
/*
|
||||
* affixes use dictionary flags too
|
||||
*/
|
||||
#define FF_COMPOUNDPERMITFLAG 0x10
|
||||
#define FF_COMPOUNDFORBIDFLAG 0x20
|
||||
#define FF_CROSSPRODUCT 0x40
|
||||
|
||||
/*
|
||||
* Don't change the order of these. Initialization sorts by these,
|
||||
* and expects prefixes to come first after sorting.
|
||||
*/
|
||||
#define FF_SUFFIX 1
|
||||
#define FF_PREFIX 0
|
||||
|
||||
struct AffixNode;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32 val:8,
|
||||
naff:24;
|
||||
AFFIX **aff;
|
||||
struct AffixNode *node;
|
||||
} AffixNodeData;
|
||||
|
||||
typedef struct AffixNode
|
||||
{
|
||||
uint32 isvoid:1,
|
||||
length:31;
|
||||
AffixNodeData data[1];
|
||||
} AffixNode;
|
||||
|
||||
#define ANHRDSZ (offsetof(AffixNode, data))
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char *affix;
|
||||
int len;
|
||||
bool issuffix;
|
||||
} CMPDAffix;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int maffixes;
|
||||
int naffixes;
|
||||
AFFIX *Affix;
|
||||
|
||||
AffixNode *Suffix;
|
||||
AffixNode *Prefix;
|
||||
|
||||
SPNode *Dictionary;
|
||||
char **AffixData;
|
||||
int lenAffixData;
|
||||
int nAffixData;
|
||||
|
||||
CMPDAffix *CompoundAffix;
|
||||
|
||||
unsigned char flagval[256];
|
||||
bool usecompound;
|
||||
|
||||
/*
|
||||
* Remaining fields are only used during dictionary construction; they are
|
||||
* set up by NIStartBuild and cleared by NIFinishBuild.
|
||||
*/
|
||||
MemoryContext buildCxt; /* temp context for construction */
|
||||
|
||||
/* Temporary array of all words in the dict file */
|
||||
SPELL **Spell;
|
||||
int nspell; /* number of valid entries in Spell array */
|
||||
int mspell; /* allocated length of Spell array */
|
||||
|
||||
/* These are used to allocate "compact" data without palloc overhead */
|
||||
char *firstfree; /* first free address (always maxaligned) */
|
||||
size_t avail; /* free space remaining at firstfree */
|
||||
} IspellDict;
|
||||
|
||||
extern TSLexeme *NINormalizeWord(IspellDict *Conf, char *word);
|
||||
|
||||
extern void NIStartBuild(IspellDict *Conf);
|
||||
extern void NIImportAffixes(IspellDict *Conf, const char *filename);
|
||||
extern void NIImportDictionary(IspellDict *Conf, const char *filename);
|
||||
extern void NISortDictionary(IspellDict *Conf);
|
||||
extern void NISortAffixes(IspellDict *Conf);
|
||||
extern void NIFinishBuild(IspellDict *Conf);
|
||||
|
||||
#endif
|
||||
98
pg_include/tsearch/ts_cache.h
Executable file
98
pg_include/tsearch/ts_cache.h
Executable file
@@ -0,0 +1,98 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* ts_cache.h
|
||||
* Tsearch related object caches.
|
||||
*
|
||||
* Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* src/include/tsearch/ts_cache.h
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef TS_CACHE_H
|
||||
#define TS_CACHE_H
|
||||
|
||||
#include "utils/guc.h"
|
||||
|
||||
|
||||
/*
|
||||
* All TS*CacheEntry structs must share this common header
|
||||
* (see InvalidateTSCacheCallBack)
|
||||
*/
|
||||
typedef struct TSAnyCacheEntry
|
||||
{
|
||||
Oid objId;
|
||||
bool isvalid;
|
||||
} TSAnyCacheEntry;
|
||||
|
||||
|
||||
typedef struct TSParserCacheEntry
|
||||
{
|
||||
/* prsId is the hash lookup key and MUST BE FIRST */
|
||||
Oid prsId; /* OID of the parser */
|
||||
bool isvalid;
|
||||
|
||||
Oid startOid;
|
||||
Oid tokenOid;
|
||||
Oid endOid;
|
||||
Oid headlineOid;
|
||||
Oid lextypeOid;
|
||||
|
||||
/*
|
||||
* Pre-set-up fmgr call of most needed parser's methods
|
||||
*/
|
||||
FmgrInfo prsstart;
|
||||
FmgrInfo prstoken;
|
||||
FmgrInfo prsend;
|
||||
FmgrInfo prsheadline;
|
||||
} TSParserCacheEntry;
|
||||
|
||||
typedef struct TSDictionaryCacheEntry
|
||||
{
|
||||
/* dictId is the hash lookup key and MUST BE FIRST */
|
||||
Oid dictId;
|
||||
bool isvalid;
|
||||
|
||||
/* most frequent fmgr call */
|
||||
Oid lexizeOid;
|
||||
FmgrInfo lexize;
|
||||
|
||||
MemoryContext dictCtx; /* memory context to store private data */
|
||||
void *dictData;
|
||||
} TSDictionaryCacheEntry;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int len;
|
||||
Oid *dictIds;
|
||||
} ListDictionary;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
/* cfgId is the hash lookup key and MUST BE FIRST */
|
||||
Oid cfgId;
|
||||
bool isvalid;
|
||||
|
||||
Oid prsId;
|
||||
|
||||
int lenmap;
|
||||
ListDictionary *map;
|
||||
} TSConfigCacheEntry;
|
||||
|
||||
|
||||
/*
|
||||
* GUC variable for current configuration
|
||||
*/
|
||||
extern char *TSCurrentConfig;
|
||||
|
||||
|
||||
extern TSParserCacheEntry *lookup_ts_parser_cache(Oid prsId);
|
||||
extern TSDictionaryCacheEntry *lookup_ts_dictionary_cache(Oid dictId);
|
||||
extern TSConfigCacheEntry *lookup_ts_config_cache(Oid cfgId);
|
||||
|
||||
extern Oid getTSCurrentConfig(bool emitError);
|
||||
extern bool check_TSCurrentConfig(char **newval, void **extra, GucSource source);
|
||||
extern void assign_TSCurrentConfig(const char *newval, void *extra);
|
||||
|
||||
#endif /* TS_CACHE_H */
|
||||
76
pg_include/tsearch/ts_locale.h
Executable file
76
pg_include/tsearch/ts_locale.h
Executable file
@@ -0,0 +1,76 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* ts_locale.h
|
||||
* locale compatibility layer for tsearch
|
||||
*
|
||||
* Copyright (c) 1998-2012, PostgreSQL Global Development Group
|
||||
*
|
||||
* src/include/tsearch/ts_locale.h
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef __TSLOCALE_H__
|
||||
#define __TSLOCALE_H__
|
||||
|
||||
#include <ctype.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "utils/pg_locale.h"
|
||||
#include "mb/pg_wchar.h"
|
||||
|
||||
/*
|
||||
* towlower() and friends should be in <wctype.h>, but some pre-C99 systems
|
||||
* declare them in <wchar.h>.
|
||||
*/
|
||||
#ifdef HAVE_WCHAR_H
|
||||
#include <wchar.h>
|
||||
#endif
|
||||
#ifdef HAVE_WCTYPE_H
|
||||
#include <wctype.h>
|
||||
#endif
|
||||
|
||||
/* working state for tsearch_readline (should be a local var in caller) */
|
||||
typedef struct
|
||||
{
|
||||
FILE *fp;
|
||||
const char *filename;
|
||||
int lineno;
|
||||
char *curline;
|
||||
ErrorContextCallback cb;
|
||||
} tsearch_readline_state;
|
||||
|
||||
#define TOUCHAR(x) (*((const unsigned char *) (x)))
|
||||
|
||||
#ifdef USE_WIDE_UPPER_LOWER
|
||||
|
||||
extern int t_isdigit(const char *ptr);
|
||||
extern int t_isspace(const char *ptr);
|
||||
extern int t_isalpha(const char *ptr);
|
||||
extern int t_isprint(const char *ptr);
|
||||
|
||||
/* The second argument of t_iseq() must be a plain ASCII character */
|
||||
#define t_iseq(x,c) (TOUCHAR(x) == (unsigned char) (c))
|
||||
|
||||
#define COPYCHAR(d,s) memcpy(d, s, pg_mblen(s))
|
||||
#else /* not USE_WIDE_UPPER_LOWER */
|
||||
|
||||
#define t_isdigit(x) isdigit(TOUCHAR(x))
|
||||
#define t_isspace(x) isspace(TOUCHAR(x))
|
||||
#define t_isalpha(x) isalpha(TOUCHAR(x))
|
||||
#define t_isprint(x) isprint(TOUCHAR(x))
|
||||
#define t_iseq(x,c) (TOUCHAR(x) == (unsigned char) (c))
|
||||
|
||||
#define COPYCHAR(d,s) (*((unsigned char *) (d)) = TOUCHAR(s))
|
||||
#endif /* USE_WIDE_UPPER_LOWER */
|
||||
|
||||
extern char *lowerstr(const char *str);
|
||||
extern char *lowerstr_with_len(const char *str, int len);
|
||||
|
||||
extern bool tsearch_readline_begin(tsearch_readline_state *stp,
|
||||
const char *filename);
|
||||
extern char *tsearch_readline(tsearch_readline_state *stp);
|
||||
extern void tsearch_readline_end(tsearch_readline_state *stp);
|
||||
|
||||
extern char *t_readline(FILE *fp);
|
||||
|
||||
#endif /* __TSLOCALE_H__ */
|
||||
130
pg_include/tsearch/ts_public.h
Executable file
130
pg_include/tsearch/ts_public.h
Executable file
@@ -0,0 +1,130 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* ts_public.h
|
||||
* Public interface to various tsearch modules, such as
|
||||
* parsers and dictionaries.
|
||||
*
|
||||
* Copyright (c) 1998-2012, PostgreSQL Global Development Group
|
||||
*
|
||||
* src/include/tsearch/ts_public.h
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef _PG_TS_PUBLIC_H_
|
||||
#define _PG_TS_PUBLIC_H_
|
||||
|
||||
#include "tsearch/ts_type.h"
|
||||
|
||||
/*
|
||||
* Parser's framework
|
||||
*/
|
||||
|
||||
/*
|
||||
* returning type for prslextype method of parser
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
int lexid;
|
||||
char *alias;
|
||||
char *descr;
|
||||
} LexDescr;
|
||||
|
||||
/*
|
||||
* Interface to headline generator
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint32 selected:1,
|
||||
in:1,
|
||||
replace:1,
|
||||
repeated:1,
|
||||
skip:1,
|
||||
unused:3,
|
||||
type:8,
|
||||
len:16;
|
||||
char *word;
|
||||
QueryOperand *item;
|
||||
} HeadlineWordEntry;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
HeadlineWordEntry *words;
|
||||
int4 lenwords;
|
||||
int4 curwords;
|
||||
char *startsel;
|
||||
char *stopsel;
|
||||
char *fragdelim;
|
||||
int2 startsellen;
|
||||
int2 stopsellen;
|
||||
int2 fragdelimlen;
|
||||
} HeadlineParsedText;
|
||||
|
||||
/*
|
||||
* Common useful things for tsearch subsystem
|
||||
*/
|
||||
extern char *get_tsearch_config_filename(const char *basename,
|
||||
const char *extension);
|
||||
|
||||
/*
|
||||
* Often useful stopword list management
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
int len;
|
||||
char **stop;
|
||||
} StopList;
|
||||
|
||||
extern void readstoplist(const char *fname, StopList *s,
|
||||
char *(*wordop) (const char *));
|
||||
extern bool searchstoplist(StopList *s, char *key);
|
||||
|
||||
/*
|
||||
* Interface with dictionaries
|
||||
*/
|
||||
|
||||
/* return struct for any lexize function */
|
||||
typedef struct
|
||||
{
|
||||
/*----------
|
||||
* Number of current variant of split word. For example the Norwegian
|
||||
* word 'fotballklubber' has two variants to split: ( fotball, klubb )
|
||||
* and ( fot, ball, klubb ). So, dictionary should return:
|
||||
*
|
||||
* nvariant lexeme
|
||||
* 1 fotball
|
||||
* 1 klubb
|
||||
* 2 fot
|
||||
* 2 ball
|
||||
* 2 klubb
|
||||
*
|
||||
* In general, a TSLexeme will be considered to belong to the same split
|
||||
* variant as the previous one if they have the same nvariant value.
|
||||
* The exact values don't matter, only changes from one lexeme to next.
|
||||
*----------
|
||||
*/
|
||||
uint16 nvariant;
|
||||
|
||||
uint16 flags; /* See flag bits below */
|
||||
|
||||
char *lexeme; /* C string */
|
||||
} TSLexeme;
|
||||
|
||||
/* Flag bits that can appear in TSLexeme.flags */
|
||||
#define TSL_ADDPOS 0x01
|
||||
#define TSL_PREFIX 0x02
|
||||
#define TSL_FILTER 0x04
|
||||
|
||||
/*
|
||||
* Struct for supporting complex dictionaries like thesaurus.
|
||||
* 4th argument for dictlexize method is a pointer to this
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
bool isend; /* in: marks for lexize_info about text end is
|
||||
* reached */
|
||||
bool getnext; /* out: dict wants next lexeme */
|
||||
void *private_state; /* internal dict state between calls with
|
||||
* getnext == true */
|
||||
} DictSubState;
|
||||
|
||||
#endif /* _PG_TS_PUBLIC_H_ */
|
||||
299
pg_include/tsearch/ts_type.h
Executable file
299
pg_include/tsearch/ts_type.h
Executable file
@@ -0,0 +1,299 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* ts_type.h
|
||||
* Definitions for the tsvector and tsquery types
|
||||
*
|
||||
* Copyright (c) 1998-2012, PostgreSQL Global Development Group
|
||||
*
|
||||
* src/include/tsearch/ts_type.h
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef _PG_TSTYPE_H_
|
||||
#define _PG_TSTYPE_H_
|
||||
|
||||
#include "fmgr.h"
|
||||
#include "utils/pg_crc.h"
|
||||
|
||||
|
||||
/*
|
||||
* TSVector type.
|
||||
*
|
||||
* Structure of tsvector datatype:
|
||||
* 1) standard varlena header
|
||||
* 2) int4 size - number of lexemes (WordEntry array entries)
|
||||
* 3) Array of WordEntry - one per lexeme; must be sorted according to
|
||||
* tsCompareString() (ie, memcmp of lexeme strings).
|
||||
* WordEntry->pos gives the number of bytes from end of WordEntry
|
||||
* array to start of lexeme's string, which is of length len.
|
||||
* 4) Per-lexeme data storage:
|
||||
* lexeme string (not null-terminated)
|
||||
* if haspos is true:
|
||||
* padding byte if necessary to make the position data 2-byte aligned
|
||||
* uint16 number of positions that follow
|
||||
* WordEntryPos[] positions
|
||||
*
|
||||
* The positions for each lexeme must be sorted.
|
||||
*
|
||||
* Note, tsvectorsend/recv believe that sizeof(WordEntry) == 4
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32
|
||||
haspos:1,
|
||||
len:11, /* MAX 2Kb */
|
||||
pos:20; /* MAX 1Mb */
|
||||
} WordEntry;
|
||||
|
||||
#define MAXSTRLEN ( (1<<11) - 1)
|
||||
#define MAXSTRPOS ( (1<<20) - 1)
|
||||
|
||||
/*
|
||||
* Equivalent to
|
||||
* typedef struct {
|
||||
* uint16
|
||||
* weight:2,
|
||||
* pos:14;
|
||||
* }
|
||||
*/
|
||||
|
||||
typedef uint16 WordEntryPos;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16 npos;
|
||||
WordEntryPos pos[1]; /* variable length */
|
||||
} WordEntryPosVector;
|
||||
|
||||
|
||||
#define WEP_GETWEIGHT(x) ( (x) >> 14 )
|
||||
#define WEP_GETPOS(x) ( (x) & 0x3fff )
|
||||
|
||||
#define WEP_SETWEIGHT(x,v) ( (x) = ( (v) << 14 ) | ( (x) & 0x3fff ) )
|
||||
#define WEP_SETPOS(x,v) ( (x) = ( (x) & 0xc000 ) | ( (v) & 0x3fff ) )
|
||||
|
||||
#define MAXENTRYPOS (1<<14)
|
||||
#define MAXNUMPOS (256)
|
||||
#define LIMITPOS(x) ( ( (x) >= MAXENTRYPOS ) ? (MAXENTRYPOS-1) : (x) )
|
||||
|
||||
/* This struct represents a complete tsvector datum */
|
||||
typedef struct
|
||||
{
|
||||
int32 vl_len_; /* varlena header (do not touch directly!) */
|
||||
int32 size;
|
||||
WordEntry entries[1]; /* variable length */
|
||||
/* lexemes follow the entries[] array */
|
||||
} TSVectorData;
|
||||
|
||||
typedef TSVectorData *TSVector;
|
||||
|
||||
#define DATAHDRSIZE (offsetof(TSVectorData, entries))
|
||||
#define CALCDATASIZE(nentries, lenstr) (DATAHDRSIZE + (nentries) * sizeof(WordEntry) + (lenstr) )
|
||||
|
||||
/* pointer to start of a tsvector's WordEntry array */
|
||||
#define ARRPTR(x) ( (x)->entries )
|
||||
|
||||
/* pointer to start of a tsvector's lexeme storage */
|
||||
#define STRPTR(x) ( (char *) &(x)->entries[(x)->size] )
|
||||
|
||||
#define _POSVECPTR(x, e) ((WordEntryPosVector *)(STRPTR(x) + SHORTALIGN((e)->pos + (e)->len)))
|
||||
#define POSDATALEN(x,e) ( ( (e)->haspos ) ? (_POSVECPTR(x,e)->npos) : 0 )
|
||||
#define POSDATAPTR(x,e) (_POSVECPTR(x,e)->pos)
|
||||
|
||||
/*
|
||||
* fmgr interface macros
|
||||
*/
|
||||
|
||||
#define DatumGetTSVector(X) ((TSVector) PG_DETOAST_DATUM(X))
|
||||
#define DatumGetTSVectorCopy(X) ((TSVector) PG_DETOAST_DATUM_COPY(X))
|
||||
#define TSVectorGetDatum(X) PointerGetDatum(X)
|
||||
#define PG_GETARG_TSVECTOR(n) DatumGetTSVector(PG_GETARG_DATUM(n))
|
||||
#define PG_GETARG_TSVECTOR_COPY(n) DatumGetTSVectorCopy(PG_GETARG_DATUM(n))
|
||||
#define PG_RETURN_TSVECTOR(x) return TSVectorGetDatum(x)
|
||||
|
||||
/*
|
||||
* I/O
|
||||
*/
|
||||
extern Datum tsvectorin(PG_FUNCTION_ARGS);
|
||||
extern Datum tsvectorout(PG_FUNCTION_ARGS);
|
||||
extern Datum tsvectorsend(PG_FUNCTION_ARGS);
|
||||
extern Datum tsvectorrecv(PG_FUNCTION_ARGS);
|
||||
|
||||
/*
|
||||
* operations with tsvector
|
||||
*/
|
||||
extern Datum tsvector_lt(PG_FUNCTION_ARGS);
|
||||
extern Datum tsvector_le(PG_FUNCTION_ARGS);
|
||||
extern Datum tsvector_eq(PG_FUNCTION_ARGS);
|
||||
extern Datum tsvector_ne(PG_FUNCTION_ARGS);
|
||||
extern Datum tsvector_ge(PG_FUNCTION_ARGS);
|
||||
extern Datum tsvector_gt(PG_FUNCTION_ARGS);
|
||||
extern Datum tsvector_cmp(PG_FUNCTION_ARGS);
|
||||
|
||||
extern Datum tsvector_length(PG_FUNCTION_ARGS);
|
||||
extern Datum tsvector_strip(PG_FUNCTION_ARGS);
|
||||
extern Datum tsvector_setweight(PG_FUNCTION_ARGS);
|
||||
extern Datum tsvector_concat(PG_FUNCTION_ARGS);
|
||||
extern Datum tsvector_update_trigger_byid(PG_FUNCTION_ARGS);
|
||||
extern Datum tsvector_update_trigger_bycolumn(PG_FUNCTION_ARGS);
|
||||
|
||||
extern Datum ts_match_vq(PG_FUNCTION_ARGS);
|
||||
extern Datum ts_match_qv(PG_FUNCTION_ARGS);
|
||||
extern Datum ts_match_tt(PG_FUNCTION_ARGS);
|
||||
extern Datum ts_match_tq(PG_FUNCTION_ARGS);
|
||||
|
||||
extern Datum ts_stat1(PG_FUNCTION_ARGS);
|
||||
extern Datum ts_stat2(PG_FUNCTION_ARGS);
|
||||
|
||||
extern Datum ts_rank_tt(PG_FUNCTION_ARGS);
|
||||
extern Datum ts_rank_wtt(PG_FUNCTION_ARGS);
|
||||
extern Datum ts_rank_ttf(PG_FUNCTION_ARGS);
|
||||
extern Datum ts_rank_wttf(PG_FUNCTION_ARGS);
|
||||
extern Datum ts_rankcd_tt(PG_FUNCTION_ARGS);
|
||||
extern Datum ts_rankcd_wtt(PG_FUNCTION_ARGS);
|
||||
extern Datum ts_rankcd_ttf(PG_FUNCTION_ARGS);
|
||||
extern Datum ts_rankcd_wttf(PG_FUNCTION_ARGS);
|
||||
|
||||
extern Datum tsmatchsel(PG_FUNCTION_ARGS);
|
||||
extern Datum tsmatchjoinsel(PG_FUNCTION_ARGS);
|
||||
|
||||
extern Datum ts_typanalyze(PG_FUNCTION_ARGS);
|
||||
|
||||
|
||||
/*
|
||||
* TSQuery
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
typedef int8 QueryItemType;
|
||||
|
||||
/* Valid values for QueryItemType: */
|
||||
#define QI_VAL 1
|
||||
#define QI_OPR 2
|
||||
#define QI_VALSTOP 3 /* This is only used in an intermediate stack
|
||||
* representation in parse_tsquery. It's not a
|
||||
* legal type elsewhere. */
|
||||
|
||||
/*
|
||||
* QueryItem is one node in tsquery - operator or operand.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
QueryItemType type; /* operand or kind of operator (ts_tokentype) */
|
||||
uint8 weight; /* weights of operand to search. It's a
|
||||
* bitmask of allowed weights. if it =0 then
|
||||
* any weight are allowed. Weights and bit
|
||||
* map: A: 1<<3 B: 1<<2 C: 1<<1 D: 1<<0 */
|
||||
bool prefix; /* true if it's a prefix search */
|
||||
int32 valcrc; /* XXX: pg_crc32 would be a more appropriate
|
||||
* data type, but we use comparisons to signed
|
||||
* integers in the code. They would need to be
|
||||
* changed as well. */
|
||||
|
||||
/* pointer to text value of operand, must correlate with WordEntry */
|
||||
uint32
|
||||
length:12,
|
||||
distance:20;
|
||||
} QueryOperand;
|
||||
|
||||
|
||||
/* Legal values for QueryOperator.operator */
|
||||
#define OP_NOT 1
|
||||
#define OP_AND 2
|
||||
#define OP_OR 3
|
||||
|
||||
typedef struct
|
||||
{
|
||||
QueryItemType type;
|
||||
int8 oper; /* see above */
|
||||
uint32 left; /* pointer to left operand. Right operand is
|
||||
* item + 1, left operand is placed
|
||||
* item+item->left */
|
||||
} QueryOperator;
|
||||
|
||||
/*
|
||||
* Note: TSQuery is 4-bytes aligned, so make sure there's no fields
|
||||
* inside QueryItem requiring 8-byte alignment, like int64.
|
||||
*/
|
||||
typedef union
|
||||
{
|
||||
QueryItemType type;
|
||||
QueryOperator qoperator;
|
||||
QueryOperand qoperand;
|
||||
} QueryItem;
|
||||
|
||||
/*
|
||||
* Storage:
|
||||
* (len)(size)(array of QueryItem)(operands as '\0'-terminated c-strings)
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int32 vl_len_; /* varlena header (do not touch directly!) */
|
||||
int4 size; /* number of QueryItems */
|
||||
char data[1]; /* data starts here */
|
||||
} TSQueryData;
|
||||
|
||||
typedef TSQueryData *TSQuery;
|
||||
|
||||
#define HDRSIZETQ ( VARHDRSZ + sizeof(int4) )
|
||||
|
||||
/* Computes the size of header and all QueryItems. size is the number of
|
||||
* QueryItems, and lenofoperand is the total length of all operands
|
||||
*/
|
||||
#define COMPUTESIZE(size, lenofoperand) ( HDRSIZETQ + (size) * sizeof(QueryItem) + (lenofoperand) )
|
||||
|
||||
/* Returns a pointer to the first QueryItem in a TSQuery */
|
||||
#define GETQUERY(x) ((QueryItem*)( (char*)(x)+HDRSIZETQ ))
|
||||
|
||||
/* Returns a pointer to the beginning of operands in a TSQuery */
|
||||
#define GETOPERAND(x) ( (char*)GETQUERY(x) + ((TSQuery)(x))->size * sizeof(QueryItem) )
|
||||
|
||||
/*
|
||||
* fmgr interface macros
|
||||
* Note, TSQuery type marked as plain storage, so it can't be toasted
|
||||
* but PG_DETOAST_DATUM_COPY is used for simplicity
|
||||
*/
|
||||
|
||||
#define DatumGetTSQuery(X) ((TSQuery) DatumGetPointer(X))
|
||||
#define DatumGetTSQueryCopy(X) ((TSQuery) PG_DETOAST_DATUM_COPY(X))
|
||||
#define TSQueryGetDatum(X) PointerGetDatum(X)
|
||||
#define PG_GETARG_TSQUERY(n) DatumGetTSQuery(PG_GETARG_DATUM(n))
|
||||
#define PG_GETARG_TSQUERY_COPY(n) DatumGetTSQueryCopy(PG_GETARG_DATUM(n))
|
||||
#define PG_RETURN_TSQUERY(x) return TSQueryGetDatum(x)
|
||||
|
||||
/*
|
||||
* I/O
|
||||
*/
|
||||
extern Datum tsqueryin(PG_FUNCTION_ARGS);
|
||||
extern Datum tsqueryout(PG_FUNCTION_ARGS);
|
||||
extern Datum tsquerysend(PG_FUNCTION_ARGS);
|
||||
extern Datum tsqueryrecv(PG_FUNCTION_ARGS);
|
||||
|
||||
/*
|
||||
* operations with tsquery
|
||||
*/
|
||||
extern Datum tsquery_lt(PG_FUNCTION_ARGS);
|
||||
extern Datum tsquery_le(PG_FUNCTION_ARGS);
|
||||
extern Datum tsquery_eq(PG_FUNCTION_ARGS);
|
||||
extern Datum tsquery_ne(PG_FUNCTION_ARGS);
|
||||
extern Datum tsquery_ge(PG_FUNCTION_ARGS);
|
||||
extern Datum tsquery_gt(PG_FUNCTION_ARGS);
|
||||
extern Datum tsquery_cmp(PG_FUNCTION_ARGS);
|
||||
|
||||
extern Datum tsquerytree(PG_FUNCTION_ARGS);
|
||||
extern Datum tsquery_numnode(PG_FUNCTION_ARGS);
|
||||
|
||||
extern Datum tsquery_and(PG_FUNCTION_ARGS);
|
||||
extern Datum tsquery_or(PG_FUNCTION_ARGS);
|
||||
extern Datum tsquery_not(PG_FUNCTION_ARGS);
|
||||
|
||||
extern Datum tsquery_rewrite(PG_FUNCTION_ARGS);
|
||||
extern Datum tsquery_rewrite_query(PG_FUNCTION_ARGS);
|
||||
|
||||
extern Datum tsq_mcontains(PG_FUNCTION_ARGS);
|
||||
extern Datum tsq_mcontained(PG_FUNCTION_ARGS);
|
||||
|
||||
#endif /* _PG_TSTYPE_H_ */
|
||||
280
pg_include/tsearch/ts_utils.h
Executable file
280
pg_include/tsearch/ts_utils.h
Executable file
@@ -0,0 +1,280 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* ts_utils.h
|
||||
* helper utilities for tsearch
|
||||
*
|
||||
* Copyright (c) 1998-2012, PostgreSQL Global Development Group
|
||||
*
|
||||
* src/include/tsearch/ts_utils.h
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef _PG_TS_UTILS_H_
|
||||
#define _PG_TS_UTILS_H_
|
||||
|
||||
#include "tsearch/ts_type.h"
|
||||
#include "tsearch/ts_public.h"
|
||||
#include "nodes/pg_list.h"
|
||||
|
||||
/*
|
||||
* Common parse definitions for tsvector and tsquery
|
||||
*/
|
||||
|
||||
/* tsvector parser support. */
|
||||
|
||||
struct TSVectorParseStateData; /* opaque struct in tsvector_parser.c */
|
||||
typedef struct TSVectorParseStateData *TSVectorParseState;
|
||||
|
||||
extern TSVectorParseState init_tsvector_parser(char *input,
|
||||
bool oprisdelim,
|
||||
bool is_tsquery);
|
||||
extern void reset_tsvector_parser(TSVectorParseState state, char *input);
|
||||
extern bool gettoken_tsvector(TSVectorParseState state,
|
||||
char **token, int *len,
|
||||
WordEntryPos **pos, int *poslen,
|
||||
char **endptr);
|
||||
extern void close_tsvector_parser(TSVectorParseState state);
|
||||
|
||||
/* parse_tsquery */
|
||||
|
||||
struct TSQueryParserStateData; /* private in backend/utils/adt/tsquery.c */
|
||||
typedef struct TSQueryParserStateData *TSQueryParserState;
|
||||
|
||||
typedef void (*PushFunction) (Datum opaque, TSQueryParserState state,
|
||||
char *token, int tokenlen,
|
||||
int2 tokenweights, /* bitmap as described
|
||||
* in QueryOperand
|
||||
* struct */
|
||||
bool prefix);
|
||||
|
||||
extern TSQuery parse_tsquery(char *buf,
|
||||
PushFunction pushval,
|
||||
Datum opaque, bool isplain);
|
||||
|
||||
/* Functions for use by PushFunction implementations */
|
||||
extern void pushValue(TSQueryParserState state,
|
||||
char *strval, int lenval, int2 weight, bool prefix);
|
||||
extern void pushStop(TSQueryParserState state);
|
||||
extern void pushOperator(TSQueryParserState state, int8 oper);
|
||||
|
||||
/*
|
||||
* parse plain text and lexize words
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint16 len;
|
||||
uint16 nvariant;
|
||||
union
|
||||
{
|
||||
uint16 pos;
|
||||
|
||||
/*
|
||||
* When apos array is used, apos[0] is the number of elements in the
|
||||
* array (excluding apos[0]), and alen is the allocated size of the
|
||||
* array.
|
||||
*/
|
||||
uint16 *apos;
|
||||
} pos;
|
||||
uint16 flags; /* currently, only TSL_PREFIX */
|
||||
char *word;
|
||||
uint32 alen;
|
||||
} ParsedWord;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ParsedWord *words;
|
||||
int4 lenwords;
|
||||
int4 curwords;
|
||||
int4 pos;
|
||||
} ParsedText;
|
||||
|
||||
extern void parsetext(Oid cfgId, ParsedText *prs, char *buf, int4 buflen);
|
||||
|
||||
/*
|
||||
* headline framework, flow in common to generate:
|
||||
* 1 parse text with hlparsetext
|
||||
* 2 parser-specific function to find part
|
||||
* 3 generateHeadline to generate result text
|
||||
*/
|
||||
|
||||
extern void hlparsetext(Oid cfgId, HeadlineParsedText *prs, TSQuery query,
|
||||
char *buf, int4 buflen);
|
||||
extern text *generateHeadline(HeadlineParsedText *prs);
|
||||
|
||||
/*
|
||||
* Common check function for tsvector @@ tsquery
|
||||
*/
|
||||
extern bool TS_execute(QueryItem *curitem, void *checkval, bool calcnot,
|
||||
bool (*chkcond) (void *checkval, QueryOperand *val));
|
||||
extern bool tsquery_requires_match(QueryItem *curitem);
|
||||
|
||||
/*
|
||||
* to_ts* - text transformation to tsvector, tsquery
|
||||
*/
|
||||
extern TSVector make_tsvector(ParsedText *prs);
|
||||
extern int32 tsCompareString(char *a, int lena, char *b, int lenb, bool prefix);
|
||||
|
||||
extern Datum to_tsvector_byid(PG_FUNCTION_ARGS);
|
||||
extern Datum to_tsvector(PG_FUNCTION_ARGS);
|
||||
extern Datum to_tsquery_byid(PG_FUNCTION_ARGS);
|
||||
extern Datum to_tsquery(PG_FUNCTION_ARGS);
|
||||
extern Datum plainto_tsquery_byid(PG_FUNCTION_ARGS);
|
||||
extern Datum plainto_tsquery(PG_FUNCTION_ARGS);
|
||||
|
||||
/*
|
||||
* GiST support function
|
||||
*/
|
||||
|
||||
extern Datum gtsvector_compress(PG_FUNCTION_ARGS);
|
||||
extern Datum gtsvector_decompress(PG_FUNCTION_ARGS);
|
||||
extern Datum gtsvector_consistent(PG_FUNCTION_ARGS);
|
||||
extern Datum gtsvector_union(PG_FUNCTION_ARGS);
|
||||
extern Datum gtsvector_same(PG_FUNCTION_ARGS);
|
||||
extern Datum gtsvector_penalty(PG_FUNCTION_ARGS);
|
||||
extern Datum gtsvector_picksplit(PG_FUNCTION_ARGS);
|
||||
|
||||
/*
|
||||
* IO functions for pseudotype gtsvector
|
||||
* used internally in tsvector GiST opclass
|
||||
*/
|
||||
extern Datum gtsvectorin(PG_FUNCTION_ARGS);
|
||||
extern Datum gtsvectorout(PG_FUNCTION_ARGS);
|
||||
|
||||
/*
|
||||
* GIN support function
|
||||
*/
|
||||
|
||||
extern Datum gin_extract_tsvector(PG_FUNCTION_ARGS);
|
||||
extern Datum gin_cmp_tslexeme(PG_FUNCTION_ARGS);
|
||||
extern Datum gin_cmp_prefix(PG_FUNCTION_ARGS);
|
||||
extern Datum gin_extract_tsquery(PG_FUNCTION_ARGS);
|
||||
extern Datum gin_tsquery_consistent(PG_FUNCTION_ARGS);
|
||||
extern Datum gin_extract_tsvector_2args(PG_FUNCTION_ARGS);
|
||||
extern Datum gin_extract_tsquery_5args(PG_FUNCTION_ARGS);
|
||||
extern Datum gin_tsquery_consistent_6args(PG_FUNCTION_ARGS);
|
||||
|
||||
/*
|
||||
* Possible strategy numbers for indexes
|
||||
* TSearchStrategyNumber - (tsvector|text) @@ tsquery
|
||||
* TSearchWithClassStrategyNumber - tsvector @@@ tsquery
|
||||
*/
|
||||
#define TSearchStrategyNumber 1
|
||||
#define TSearchWithClassStrategyNumber 2
|
||||
|
||||
/*
|
||||
* TSQuery Utilities
|
||||
*/
|
||||
extern QueryItem *clean_NOT(QueryItem *ptr, int4 *len);
|
||||
extern QueryItem *clean_fakeval(QueryItem *ptr, int4 *len);
|
||||
|
||||
typedef struct QTNode
|
||||
{
|
||||
QueryItem *valnode;
|
||||
uint32 flags;
|
||||
int4 nchild;
|
||||
char *word;
|
||||
uint32 sign;
|
||||
struct QTNode **child;
|
||||
} QTNode;
|
||||
|
||||
/* bits in QTNode.flags */
|
||||
#define QTN_NEEDFREE 0x01
|
||||
#define QTN_NOCHANGE 0x02
|
||||
#define QTN_WORDFREE 0x04
|
||||
|
||||
typedef uint64 TSQuerySign;
|
||||
|
||||
#define TSQS_SIGLEN (sizeof(TSQuerySign)*BITS_PER_BYTE)
|
||||
|
||||
#define TSQuerySignGetDatum(X) Int64GetDatum((int64) (X))
|
||||
#define DatumGetTSQuerySign(X) ((TSQuerySign) DatumGetInt64(X))
|
||||
#define PG_RETURN_TSQUERYSIGN(X) return TSQuerySignGetDatum(X)
|
||||
#define PG_GETARG_TSQUERYSIGN(n) DatumGetTSQuerySign(PG_GETARG_DATUM(n))
|
||||
|
||||
|
||||
extern QTNode *QT2QTN(QueryItem *in, char *operand);
|
||||
extern TSQuery QTN2QT(QTNode *in);
|
||||
extern void QTNFree(QTNode *in);
|
||||
extern void QTNSort(QTNode *in);
|
||||
extern void QTNTernary(QTNode *in);
|
||||
extern void QTNBinary(QTNode *in);
|
||||
extern int QTNodeCompare(QTNode *an, QTNode *bn);
|
||||
extern QTNode *QTNCopy(QTNode *in);
|
||||
extern void QTNClearFlags(QTNode *in, uint32 flags);
|
||||
extern bool QTNEq(QTNode *a, QTNode *b);
|
||||
extern TSQuerySign makeTSQuerySign(TSQuery a);
|
||||
extern QTNode *findsubquery(QTNode *root, QTNode *ex, QTNode *subs,
|
||||
bool *isfind);
|
||||
|
||||
/*
|
||||
* TSQuery GiST support
|
||||
*/
|
||||
extern Datum gtsquery_compress(PG_FUNCTION_ARGS);
|
||||
extern Datum gtsquery_decompress(PG_FUNCTION_ARGS);
|
||||
extern Datum gtsquery_consistent(PG_FUNCTION_ARGS);
|
||||
extern Datum gtsquery_union(PG_FUNCTION_ARGS);
|
||||
extern Datum gtsquery_same(PG_FUNCTION_ARGS);
|
||||
extern Datum gtsquery_penalty(PG_FUNCTION_ARGS);
|
||||
extern Datum gtsquery_picksplit(PG_FUNCTION_ARGS);
|
||||
|
||||
/*
|
||||
* Parser interface to SQL
|
||||
*/
|
||||
extern Datum ts_token_type_byid(PG_FUNCTION_ARGS);
|
||||
extern Datum ts_token_type_byname(PG_FUNCTION_ARGS);
|
||||
extern Datum ts_parse_byid(PG_FUNCTION_ARGS);
|
||||
extern Datum ts_parse_byname(PG_FUNCTION_ARGS);
|
||||
|
||||
/*
|
||||
* Default word parser
|
||||
*/
|
||||
|
||||
extern Datum prsd_start(PG_FUNCTION_ARGS);
|
||||
extern Datum prsd_nexttoken(PG_FUNCTION_ARGS);
|
||||
extern Datum prsd_end(PG_FUNCTION_ARGS);
|
||||
extern Datum prsd_headline(PG_FUNCTION_ARGS);
|
||||
extern Datum prsd_lextype(PG_FUNCTION_ARGS);
|
||||
|
||||
/*
|
||||
* Dictionary interface to SQL
|
||||
*/
|
||||
extern Datum ts_lexize(PG_FUNCTION_ARGS);
|
||||
|
||||
/*
|
||||
* Simple built-in dictionary
|
||||
*/
|
||||
extern Datum dsimple_init(PG_FUNCTION_ARGS);
|
||||
extern Datum dsimple_lexize(PG_FUNCTION_ARGS);
|
||||
|
||||
/*
|
||||
* Synonym built-in dictionary
|
||||
*/
|
||||
extern Datum dsynonym_init(PG_FUNCTION_ARGS);
|
||||
extern Datum dsynonym_lexize(PG_FUNCTION_ARGS);
|
||||
|
||||
/*
|
||||
* ISpell dictionary
|
||||
*/
|
||||
extern Datum dispell_init(PG_FUNCTION_ARGS);
|
||||
extern Datum dispell_lexize(PG_FUNCTION_ARGS);
|
||||
|
||||
/*
|
||||
* Thesaurus
|
||||
*/
|
||||
extern Datum thesaurus_init(PG_FUNCTION_ARGS);
|
||||
extern Datum thesaurus_lexize(PG_FUNCTION_ARGS);
|
||||
|
||||
/*
|
||||
* headline
|
||||
*/
|
||||
extern Datum ts_headline_byid_opt(PG_FUNCTION_ARGS);
|
||||
extern Datum ts_headline_byid(PG_FUNCTION_ARGS);
|
||||
extern Datum ts_headline(PG_FUNCTION_ARGS);
|
||||
extern Datum ts_headline_opt(PG_FUNCTION_ARGS);
|
||||
|
||||
/*
|
||||
* current cfg
|
||||
*/
|
||||
extern Datum get_current_ts_config(PG_FUNCTION_ARGS);
|
||||
|
||||
#endif /* _PG_TS_UTILS_H_ */
|
||||
Reference in New Issue
Block a user