PostgreSQL Source Code git master
|
#include "postgres.h"
#include "catalog/pg_collation.h"
#include "miscadmin.h"
#include "tsearch/dicts/spell.h"
#include "tsearch/ts_locale.h"
#include "utils/formatting.h"
#include "utils/memutils.h"
Go to the source code of this file.
Data Structures | |
struct | SplitVar |
Macros | |
#define | tmpalloc(sz) MemoryContextAlloc(Conf->buildCxt, (sz)) |
#define | tmpalloc0(sz) MemoryContextAllocZero(Conf->buildCxt, (sz)) |
#define | COMPACT_ALLOC_CHUNK 8192 /* amount to get from palloc at once */ |
#define | COMPACT_MAX_REQ 1024 /* must be < COMPACT_ALLOC_CHUNK */ |
#define | cpalloc(size) compact_palloc0(Conf, size) |
#define | cpalloc0(size) compact_palloc0(Conf, size) |
#define | MAX_NORM 1024 |
#define | MAXNORMLEN 256 |
#define | STRNCMP(s, p) strncmp( (s), (p), strlen(p) ) |
#define | GETWCHAR(W, L, N, T) ( ((const uint8*)(W))[ ((T)==FF_PREFIX) ? (N) : ( (L) - 1 - (N) ) ] ) |
#define | GETCHAR(A, N, T) GETWCHAR( (A)->repl, (A)->replen, N, T ) |
#define | PAE_WAIT_MASK 0 |
#define | PAE_INMASK 1 |
#define | PAE_WAIT_FIND 2 |
#define | PAE_INFIND 3 |
#define | PAE_WAIT_REPL 4 |
#define | PAE_INREPL 5 |
#define | PAE_WAIT_TYPE 6 |
#define | PAE_WAIT_FLAG 7 |
Typedefs | |
typedef struct SplitVar | SplitVar |
Functions | |
void | NIStartBuild (IspellDict *Conf) |
void | NIFinishBuild (IspellDict *Conf) |
static void * | compact_palloc0 (IspellDict *Conf, size_t size) |
static char * | cpstrdup (IspellDict *Conf, const char *str) |
static char * | lowerstr_ctx (IspellDict *Conf, const char *src) |
static int | cmpspell (const void *s1, const void *s2) |
static int | cmpspellaffix (const void *s1, const void *s2) |
static int | cmpcmdflag (const void *f1, const void *f2) |
static char * | findchar (char *str, int c) |
static char * | findchar2 (char *str, int c1, int c2) |
static int | strbcmp (const unsigned char *s1, const unsigned char *s2) |
static int | strbncmp (const unsigned char *s1, const unsigned char *s2, size_t count) |
static int | cmpaffix (const void *s1, const void *s2) |
static void | getNextFlagFromString (IspellDict *Conf, const char **sflagset, char *sflag) |
static bool | IsAffixFlagInUse (IspellDict *Conf, int affix, const char *affixflag) |
static void | NIAddSpell (IspellDict *Conf, const char *word, const char *flag) |
void | NIImportDictionary (IspellDict *Conf, const char *filename) |
static int | FindWord (IspellDict *Conf, const char *word, const char *affixflag, int flag) |
static void | NIAddAffix (IspellDict *Conf, const char *flag, char flagflags, const char *mask, const char *find, const char *repl, int type) |
static bool | get_nextfield (char **str, char *next) |
static int | parse_ooaffentry (char *str, char *type, char *flag, char *find, char *repl, char *mask) |
static bool | parse_affentry (char *str, char *mask, char *find, char *repl) |
static void | setCompoundAffixFlagValue (IspellDict *Conf, CompoundAffixFlag *entry, char *s, uint32 val) |
static void | addCompoundAffixFlagValue (IspellDict *Conf, char *s, uint32 val) |
static int | getCompoundAffixFlagValue (IspellDict *Conf, const char *s) |
static const char * | getAffixFlagSet (IspellDict *Conf, char *s) |
static void | NIImportOOAffixes (IspellDict *Conf, const char *filename) |
void | NIImportAffixes (IspellDict *Conf, const char *filename) |
static int | MergeAffix (IspellDict *Conf, int a1, int a2) |
static uint32 | makeCompoundFlags (IspellDict *Conf, int affix) |
static SPNode * | mkSPNode (IspellDict *Conf, int low, int high, int level) |
void | NISortDictionary (IspellDict *Conf) |
static AffixNode * | mkANode (IspellDict *Conf, int low, int high, int level, int type) |
static void | mkVoidAffix (IspellDict *Conf, bool issuffix, int startsuffix) |
static bool | isAffixInUse (IspellDict *Conf, const char *affixflag) |
void | NISortAffixes (IspellDict *Conf) |
static AffixNodeData * | FindAffixes (AffixNode *node, const char *word, int wrdlen, int *level, int type) |
static char * | CheckAffix (const char *word, size_t len, AFFIX *Affix, int flagflags, char *newword, int *baselen) |
static int | addToResult (char **forms, char **cur, char *word) |
static char ** | NormalizeSubWord (IspellDict *Conf, const char *word, int flag) |
static int | CheckCompoundAffixes (CMPDAffix **ptr, const char *word, int len, bool CheckInPlace) |
static SplitVar * | CopyVar (SplitVar *s, int makedup) |
static void | AddStem (SplitVar *v, char *word) |
static SplitVar * | SplitToVariants (IspellDict *Conf, SPNode *snode, SplitVar *orig, const char *word, int wordlen, int startpos, int minpos) |
static void | addNorm (TSLexeme **lres, TSLexeme **lcur, char *word, int flags, uint16 NVariant) |
TSLexeme * | NINormalizeWord (IspellDict *Conf, const char *word) |
Variables | |
static const char * | VoidString = "" |
#define COMPACT_ALLOC_CHUNK 8192 /* amount to get from palloc at once */ |
#define COMPACT_MAX_REQ 1024 /* must be < COMPACT_ALLOC_CHUNK */ |
#define cpalloc | ( | size | ) | compact_palloc0(Conf, size) |
#define cpalloc0 | ( | size | ) | compact_palloc0(Conf, size) |
#define tmpalloc | ( | sz | ) | MemoryContextAlloc(Conf->buildCxt, (sz)) |
#define tmpalloc0 | ( | sz | ) | MemoryContextAllocZero(Conf->buildCxt, (sz)) |
|
static |
Definition at line 1067 of file spell.c.
References IspellDict::CompoundAffixFlags, COPYCHAR, ereport, errcode(), errmsg(), ERROR, IspellDict::mCompoundAffixFlag, IspellDict::nCompoundAffixFlag, pg_mblen(), repalloc(), setCompoundAffixFlagValue(), tmpalloc, IspellDict::usecompound, and val.
Referenced by NIImportAffixes(), and NIImportOOAffixes().
|
static |
Definition at line 2525 of file spell.c.
References MAX_NORM, palloc(), and word().
Referenced by NINormalizeWord().
|
static |
Definition at line 2362 of file spell.c.
References SplitVar::lenstem, SplitVar::nstem, repalloc(), SplitVar::stem, and word().
Referenced by SplitToVariants().
|
static |
|
static |
Definition at line 2072 of file spell.c.
References data, FF_COMPOUNDBEGIN, FF_COMPOUNDFORBIDFLAG, FF_COMPOUNDLAST, FF_COMPOUNDMIDDLE, FF_COMPOUNDONLY, FF_PREFIX, FF_SUFFIX, aff_struct::find, aff_struct::flagflags, aff_struct::isregis, aff_struct::issimple, len, palloc(), pfree(), pg_mb2wchar_with_len(), pg_regexec(), aff_struct::pregex, aff_struct::reg, REG_OKAY, aff_struct::regis, aff_struct::replen, RS_execute(), aff_struct::type, and word().
Referenced by NormalizeSubWord().
|
static |
Definition at line 2295 of file spell.c.
Referenced by SplitToVariants().
|
static |
Definition at line 312 of file spell.c.
References a1, a2, FF_PREFIX, s1, s2, and strbcmp().
Referenced by NISortAffixes().
|
static |
Definition at line 211 of file spell.c.
References Assert, f1, f2, CompoundAffixFlag::flag, CompoundAffixFlag::flagMode, FM_NUM, CompoundAffixFlag::i, and CompoundAffixFlag::s.
Referenced by getCompoundAffixFlagValue(), and NIImportOOAffixes().
|
static |
Definition at line 198 of file spell.c.
References s1, s2, and word().
Referenced by NISortDictionary().
|
static |
|
static |
Definition at line 131 of file spell.c.
References Assert, IspellDict::avail, IspellDict::buildCxt, COMPACT_ALLOC_CHUNK, COMPACT_MAX_REQ, IspellDict::firstfree, MAXALIGN, palloc0(), and size.
Definition at line 2337 of file spell.c.
References i, SplitVar::lenstem, SplitVar::next, SplitVar::nstem, palloc(), pstrdup(), and SplitVar::stem.
Referenced by SplitToVariants().
|
static |
Definition at line 163 of file spell.c.
References cpalloc, res, and str.
Referenced by NIAddAffix(), NIAddSpell(), NIImportOOAffixes(), NISortDictionary(), and setCompoundAffixFlagValue().
|
static |
Definition at line 2029 of file spell.c.
References AffixNode::data, GETWCHAR, AffixNode::isvoid, AffixNode::length, AffixNodeData::naff, AffixNodeData::node, type, AffixNodeData::val, and word().
Referenced by NormalizeSubWord().
|
static |
Definition at line 230 of file spell.c.
References pg_mblen(), str, and t_iseq.
Referenced by NIImportDictionary().
|
static |
|
static |
Definition at line 603 of file spell.c.
References SPNodeData::affix, SPNodeData::compoundflag, SPNode::data, IspellDict::Dictionary, FF_COMPOUNDFLAGMASK, FF_COMPOUNDONLY, flag(), IsAffixFlagInUse(), SPNodeData::isword, SPNode::length, SPNodeData::node, SPNodeData::val, and word().
Referenced by NormalizeSubWord().
|
static |
Definition at line 792 of file spell.c.
References COPYCHAR, next, PAE_INMASK, PAE_WAIT_MASK, pg_mblen(), str, and t_iseq.
Referenced by parse_ooaffentry().
|
static |
Definition at line 1160 of file spell.c.
References IspellDict::AffixData, ereport, errcode(), errmsg(), ERROR, IspellDict::nAffixData, IspellDict::useFlagAliases, and VoidString.
Referenced by NIImportOOAffixes().
|
static |
Definition at line 1124 of file spell.c.
References cmpcmdflag(), IspellDict::CompoundAffixFlags, flag(), getNextFlagFromString(), sort-test::key, IspellDict::nCompoundAffixFlag, setCompoundAffixFlagValue(), and CompoundAffixFlag::value.
Referenced by makeCompoundFlags(), and NIImportOOAffixes().
|
static |
Definition at line 350 of file spell.c.
References COPYCHAR, elog, ereport, errcode(), errmsg(), ERROR, IspellDict::flagMode, FLAGNUM_MAXSIZE, FM_CHAR, FM_LONG, FM_NUM, next, pg_mblen(), sprintf, and t_iseq.
Referenced by getCompoundAffixFlagValue(), and IsAffixFlagInUse().
|
static |
Definition at line 455 of file spell.c.
References IspellDict::AffixData, Assert, flag(), and getNextFlagFromString().
Referenced by FindWord(), and isAffixInUse().
|
static |
Definition at line 1962 of file spell.c.
References i, IsAffixFlagInUse(), and IspellDict::nAffixData.
Referenced by NISortAffixes().
|
static |
Definition at line 176 of file spell.c.
References IspellDict::buildCxt, MemoryContextSwitchTo(), and str_tolower().
Referenced by NIImportDictionary(), and NIImportOOAffixes().
|
static |
Definition at line 1624 of file spell.c.
References IspellDict::AffixData, Assert, FF_COMPOUNDFLAGMASK, and getCompoundAffixFlagValue().
Referenced by mkSPNode().
|
static |
Definition at line 1573 of file spell.c.
References a1, a2, IspellDict::AffixData, Assert, cpalloc, IspellDict::flagMode, FM_NUM, IspellDict::lenAffixData, IspellDict::nAffixData, repalloc(), and sprintf.
Referenced by mkSPNode().
|
static |
Definition at line 1831 of file spell.c.
References IspellDict::Affix, ANHRDSZ, cpalloc, cpalloc0, AffixNode::data, data, GETCHAR, i, AffixNode::length, mkANode(), pfree(), aff_struct::replen, tmpalloc, and type.
Referenced by mkANode(), and NISortAffixes().
|
static |
Definition at line 1641 of file spell.c.
References spell_struct::affix, cpalloc0, spell_struct::d, SPNode::data, data, FF_COMPOUNDFLAG, FF_COMPOUNDONLY, i, spell_struct::len, SPNode::length, makeCompoundFlags(), MergeAffix(), mkSPNode(), spell_struct::p, IspellDict::Spell, SPNHDRSZ, and spell_struct::word.
Referenced by mkSPNode(), and NISortDictionary().
|
static |
Definition at line 1908 of file spell.c.
References AffixNodeData::aff, IspellDict::Affix, ANHRDSZ, cpalloc, AffixNode::data, i, IspellDict::naffixes, AffixNodeData::node, palloc0(), IspellDict::Prefix, aff_struct::replen, start, and IspellDict::Suffix.
Referenced by NISortAffixes().
|
static |
Definition at line 678 of file spell.c.
References IspellDict::Affix, cpstrdup(), ereport, err(), errcode(), errmsg(), ERROR, FF_COMPOUNDFLAG, FF_COMPOUNDONLY, FF_COMPOUNDPERMITFLAG, FF_SUFFIX, find(), aff_struct::find, aff_struct::flag, flag(), aff_struct::flagflags, aff_struct::isregis, aff_struct::issimple, IspellDict::maffixes, IspellDict::naffixes, palloc(), pg_mb2wchar_with_len(), pg_regcomp(), pg_regerror(), aff_struct::pregex, aff_struct::reg, REG_ADVANCED, REG_NOSUB, regex_t, aff_struct::regis, repalloc(), aff_struct::repl, aff_struct::replen, RS_compile(), RS_isRegis(), sprintf, tmpalloc, type, aff_struct::type, and VoidString.
Referenced by NIImportAffixes(), and NIImportOOAffixes().
|
static |
Definition at line 487 of file spell.c.
References cpstrdup(), spell_struct::flag, flag(), IspellDict::mspell, IspellDict::nspell, spell_struct::p, repalloc(), IspellDict::Spell, SPELLHDRSZ, tmpalloc, VoidString, word(), and spell_struct::word.
Referenced by NIImportDictionary().
void NIFinishBuild | ( | IspellDict * | Conf | ) |
Definition at line 104 of file spell.c.
References IspellDict::buildCxt, IspellDict::CompoundAffixFlags, IspellDict::firstfree, MemoryContextDelete(), and IspellDict::Spell.
Referenced by dispell_init().
void NIImportAffixes | ( | IspellDict * | Conf, |
const char * | filename | ||
) |
Definition at line 1426 of file spell.c.
References addCompoundAffixFlagValue(), COPYCHAR, ereport, errcode(), errmsg(), ERROR, FF_COMPOUNDFLAG, FF_COMPOUNDONLY, FF_CROSSPRODUCT, FF_PREFIX, FF_SUFFIX, filename, find(), findchar2(), flag(), IspellDict::flagMode, FM_CHAR, NIAddAffix(), NIImportOOAffixes(), parse_affentry(), pfree(), pg_mblen(), prefixes(), str_tolower(), STRNCMP, tsearch_readline(), tsearch_readline_begin(), tsearch_readline_end(), IspellDict::usecompound, and IspellDict::useFlagAliases.
Referenced by dispell_init().
void NIImportDictionary | ( | IspellDict * | Conf, |
const char * | filename | ||
) |
Definition at line 518 of file spell.c.
References ereport, errcode(), errmsg(), ERROR, filename, findchar(), flag(), lowerstr_ctx(), NIAddSpell(), pfree(), pg_mblen(), tsearch_readline(), tsearch_readline_begin(), and tsearch_readline_end().
Referenced by dispell_init().
|
static |
Definition at line 1197 of file spell.c.
References addCompoundAffixFlagValue(), IspellDict::AffixData, cmpcmdflag(), IspellDict::CompoundAffixFlags, cpstrdup(), ereport, errcode(), errmsg(), ERROR, FF_COMPOUNDBEGIN, FF_COMPOUNDFLAG, FF_COMPOUNDFORBIDFLAG, FF_COMPOUNDLAST, FF_COMPOUNDMIDDLE, FF_COMPOUNDONLY, FF_COMPOUNDPERMITFLAG, FF_CROSSPRODUCT, FF_PREFIX, FF_SUFFIX, filename, find(), IspellDict::flagMode, FM_CHAR, FM_LONG, FM_NUM, getAffixFlagSet(), getCompoundAffixFlagValue(), IspellDict::lenAffixData, lowerstr_ctx(), IspellDict::nAffixData, IspellDict::nCompoundAffixFlag, NIAddAffix(), palloc0(), parse_ooaffentry(), pfree(), pg_mblen(), qsort, STRNCMP, t_iseq, tsearch_readline(), tsearch_readline_begin(), tsearch_readline_end(), type, IspellDict::usecompound, IspellDict::useFlagAliases, and VoidString.
Referenced by NIImportAffixes().
TSLexeme * NINormalizeWord | ( | IspellDict * | Conf, |
const char * | word | ||
) |
Definition at line 2541 of file spell.c.
References addNorm(), FF_COMPOUNDLAST, i, MAX_NORM, SplitVar::next, NormalizeSubWord(), SplitVar::nstem, pfree(), pstrdup(), res, SplitToVariants(), SplitVar::stem, IspellDict::usecompound, and word().
Referenced by dispell_lexize().
void NISortAffixes | ( | IspellDict * | Conf | ) |
Definition at line 1977 of file spell.c.
References CMPDAffix::affix, IspellDict::Affix, cmpaffix(), IspellDict::CompoundAffix, FF_COMPOUNDFLAG, FF_PREFIX, FF_SUFFIX, aff_struct::flag, aff_struct::flagflags, i, isAffixInUse(), CMPDAffix::issuffix, CMPDAffix::len, mkANode(), mkVoidAffix(), IspellDict::naffixes, palloc(), IspellDict::Prefix, qsort, repalloc(), aff_struct::repl, aff_struct::replen, strbncmp(), IspellDict::Suffix, and aff_struct::type.
Referenced by dispell_init().
void NISortDictionary | ( | IspellDict * | Conf | ) |
Definition at line 1723 of file spell.c.
References spell_struct::affix, IspellDict::AffixData, Assert, cmpspell(), cmpspellaffix(), cpstrdup(), spell_struct::d, IspellDict::Dictionary, ereport, errcode(), errmsg(), ERROR, spell_struct::flag, i, spell_struct::len, IspellDict::lenAffixData, mkSPNode(), IspellDict::nAffixData, IspellDict::nspell, spell_struct::p, palloc0(), qsort, IspellDict::Spell, IspellDict::useFlagAliases, and spell_struct::word.
Referenced by dispell_init().
void NIStartBuild | ( | IspellDict * | Conf | ) |
Definition at line 89 of file spell.c.
References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, IspellDict::buildCxt, and CurTransactionContext.
Referenced by dispell_init().
|
static |
Definition at line 2177 of file spell.c.
References addToResult(), AffixNodeData::aff, CheckAffix(), cur, FF_CROSSPRODUCT, FF_PREFIX, FF_SUFFIX, FindAffixes(), FindWord(), aff_struct::flag, flag(), aff_struct::flagflags, i, if(), j, MAX_NORM, MAXNORMLEN, AffixNodeData::naff, AffixNodeData::node, palloc(), pfree(), IspellDict::Prefix, pstrdup(), IspellDict::Suffix, VoidString, and word().
Referenced by NINormalizeWord(), and SplitToVariants().
|
static |
Definition at line 914 of file spell.c.
References COPYCHAR, elog, ereport, errcode(), errmsg(), ERROR, find(), PAE_INFIND, PAE_INMASK, PAE_INREPL, PAE_WAIT_FIND, PAE_WAIT_MASK, PAE_WAIT_REPL, pg_mblen(), str, t_isalpha(), and t_iseq.
Referenced by NIImportAffixes().
|
static |
Definition at line 858 of file spell.c.
References elog, ERROR, find(), flag(), get_nextfield(), PAE_WAIT_FIND, PAE_WAIT_FLAG, PAE_WAIT_MASK, PAE_WAIT_REPL, PAE_WAIT_TYPE, str, and type.
Referenced by NIImportOOAffixes().
|
static |
Definition at line 1032 of file spell.c.
References cpstrdup(), ereport, errcode(), errmsg(), ERROR, CompoundAffixFlag::flag, CompoundAffixFlag::flagMode, IspellDict::flagMode, FLAGNUM_MAXSIZE, FM_NUM, i, CompoundAffixFlag::i, next, CompoundAffixFlag::s, val, and CompoundAffixFlag::value.
Referenced by addCompoundAffixFlagValue(), and getCompoundAffixFlagValue().
|
static |
Definition at line 2375 of file spell.c.
References AddStem(), buf, check_stack_depth(), CheckCompoundAffixes(), IspellDict::CompoundAffix, SPNodeData::compoundflag, CopyVar(), SPNode::data, IspellDict::Dictionary, FF_COMPOUNDBEGIN, FF_COMPOUNDLAST, FF_COMPOUNDMIDDLE, SPNodeData::isword, SPNode::length, MAXNORMLEN, SplitVar::next, SPNodeData::node, NormalizeSubWord(), palloc(), pfree(), pnstrdup(), SplitToVariants(), startpos, SPNodeData::val, and word().
Referenced by NINormalizeWord(), and SplitToVariants().
|
static |
Definition at line 258 of file spell.c.
Referenced by cmpaffix().
|
static |
Definition at line 281 of file spell.c.
Referenced by NISortAffixes().
|
static |
Definition at line 195 of file spell.c.
Referenced by getAffixFlagSet(), NIAddAffix(), NIAddSpell(), NIImportOOAffixes(), and NormalizeSubWord().