mirror of
https://github.com/postgres/postgres.git
synced 2025-04-24 10:47:04 +03:00
Optimize. Improve ispell support for compound words. This work was sponsored by ABC Startsiden AS.
This commit is contained in:
parent
6a04c571d4
commit
c63c1946a2
@ -27,7 +27,7 @@ Datum spell_lexize(PG_FUNCTION_ARGS);
|
|||||||
static void
|
static void
|
||||||
freeDictISpell(DictISpell * d)
|
freeDictISpell(DictISpell * d)
|
||||||
{
|
{
|
||||||
FreeIspell(&(d->obj));
|
NIFree(&(d->obj));
|
||||||
freestoplist(&(d->stoplist));
|
freestoplist(&(d->stoplist));
|
||||||
free(d);
|
free(d);
|
||||||
}
|
}
|
||||||
@ -71,7 +71,7 @@ spell_init(PG_FUNCTION_ARGS)
|
|||||||
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
|
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
|
||||||
errmsg("dictionary already loaded")));
|
errmsg("dictionary already loaded")));
|
||||||
}
|
}
|
||||||
if (ImportDictionary(&(d->obj), pcfg->value))
|
if (NIImportDictionary(&(d->obj), pcfg->value))
|
||||||
{
|
{
|
||||||
freeDictISpell(d);
|
freeDictISpell(d);
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
@ -90,7 +90,7 @@ spell_init(PG_FUNCTION_ARGS)
|
|||||||
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
|
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
|
||||||
errmsg("affixes already loaded")));
|
errmsg("affixes already loaded")));
|
||||||
}
|
}
|
||||||
if (ImportAffixes(&(d->obj), pcfg->value))
|
if (NIImportAffixes(&(d->obj), pcfg->value))
|
||||||
{
|
{
|
||||||
freeDictISpell(d);
|
freeDictISpell(d);
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
@ -132,8 +132,8 @@ spell_init(PG_FUNCTION_ARGS)
|
|||||||
|
|
||||||
if (affloaded && dictloaded)
|
if (affloaded && dictloaded)
|
||||||
{
|
{
|
||||||
SortDictionary(&(d->obj));
|
NISortDictionary(&(d->obj));
|
||||||
SortAffixes(&(d->obj));
|
NISortAffixes(&(d->obj));
|
||||||
}
|
}
|
||||||
else if (!affloaded)
|
else if (!affloaded)
|
||||||
{
|
{
|
||||||
@ -168,7 +168,7 @@ spell_lexize(PG_FUNCTION_ARGS)
|
|||||||
|
|
||||||
res = palloc(sizeof(char *) * 2);
|
res = palloc(sizeof(char *) * 2);
|
||||||
txt = pnstrdup(in, PG_GETARG_INT32(2));
|
txt = pnstrdup(in, PG_GETARG_INT32(2));
|
||||||
res = NormalizeWord(&(d->obj), txt);
|
res = NINormalizeWord(&(d->obj), txt);
|
||||||
pfree(txt);
|
pfree(txt);
|
||||||
|
|
||||||
if (res == NULL)
|
if (res == NULL)
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -4,15 +4,43 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <regex.h>
|
#include <regex.h>
|
||||||
|
|
||||||
|
|
||||||
|
struct SPNode;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
u_int32_t
|
||||||
|
val:8,
|
||||||
|
isword:1,
|
||||||
|
compoundallow:1,
|
||||||
|
affix:22;
|
||||||
|
struct SPNode *node;
|
||||||
|
} SPNodeData;
|
||||||
|
|
||||||
|
typedef struct SPNode {
|
||||||
|
u_int32_t length;
|
||||||
|
SPNodeData data[1];
|
||||||
|
} SPNode;
|
||||||
|
|
||||||
|
#define SPNHRDSZ (sizeof(u_int32_t))
|
||||||
|
|
||||||
|
|
||||||
typedef struct spell_struct
|
typedef struct spell_struct
|
||||||
{
|
{
|
||||||
char *word;
|
char *word;
|
||||||
char flag[10];
|
union {
|
||||||
|
char flag[16];
|
||||||
|
struct {
|
||||||
|
int affix;
|
||||||
|
int len;
|
||||||
|
} d;
|
||||||
|
} p;
|
||||||
} SPELL;
|
} SPELL;
|
||||||
|
|
||||||
typedef struct aff_struct
|
typedef struct aff_struct
|
||||||
{
|
{
|
||||||
char flag;
|
char flag;
|
||||||
|
char flagflags;
|
||||||
char type;
|
char type;
|
||||||
char mask[33];
|
char mask[33];
|
||||||
char find[16];
|
char find[16];
|
||||||
@ -22,35 +50,66 @@ typedef struct aff_struct
|
|||||||
char compile;
|
char compile;
|
||||||
} AFFIX;
|
} AFFIX;
|
||||||
|
|
||||||
|
#define FF_CROSSPRODUCT 0x01
|
||||||
|
#define FF_COMPOUNDWORD 0x02
|
||||||
|
#define FF_COMPOUNDONLYAFX 0x04
|
||||||
|
|
||||||
|
struct AffixNode;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
u_int32_t
|
||||||
|
val:8,
|
||||||
|
naff:24;
|
||||||
|
AFFIX **aff;
|
||||||
|
struct AffixNode *node;
|
||||||
|
} AffixNodeData;
|
||||||
|
|
||||||
|
typedef struct AffixNode {
|
||||||
|
u_int32_t length;
|
||||||
|
AffixNodeData data[1];
|
||||||
|
} AffixNode;
|
||||||
|
|
||||||
|
#define ANHRDSZ (sizeof(u_int32_t))
|
||||||
|
|
||||||
typedef struct Tree_struct
|
typedef struct Tree_struct
|
||||||
{
|
{
|
||||||
int Left[256],
|
int Left[256],
|
||||||
Right[256];
|
Right[256];
|
||||||
} Tree_struct;
|
} Tree_struct;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char *affix;
|
||||||
|
int len;
|
||||||
|
} CMPDAffix;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
int maffixes;
|
int maffixes;
|
||||||
int naffixes;
|
int naffixes;
|
||||||
AFFIX *Affix;
|
AFFIX *Affix;
|
||||||
|
char compoundcontrol;
|
||||||
|
|
||||||
int nspell;
|
int nspell;
|
||||||
int mspell;
|
int mspell;
|
||||||
SPELL *Spell;
|
SPELL *Spell;
|
||||||
Tree_struct SpellTree;
|
|
||||||
Tree_struct PrefixTree;
|
AffixNode *Suffix;
|
||||||
Tree_struct SuffixTree;
|
AffixNode *Prefix;
|
||||||
|
|
||||||
|
SPNode *Dictionary;
|
||||||
|
char **AffixData;
|
||||||
|
CMPDAffix *CompoundAffix;
|
||||||
|
|
||||||
} IspellDict;
|
} IspellDict;
|
||||||
|
|
||||||
char **NormalizeWord(IspellDict * Conf, char *word);
|
char **NINormalizeWord(IspellDict * Conf, char *word);
|
||||||
int ImportAffixes(IspellDict * Conf, const char *filename);
|
int NIImportAffixes(IspellDict * Conf, const char *filename);
|
||||||
int ImportDictionary(IspellDict * Conf, const char *filename);
|
int NIImportDictionary(IspellDict * Conf, const char *filename);
|
||||||
|
|
||||||
int AddSpell(IspellDict * Conf, const char *word, const char *flag);
|
int NIAddSpell(IspellDict * Conf, const char *word, const char *flag);
|
||||||
int AddAffix(IspellDict * Conf, int flag, const char *mask, const char *find, const char *repl, int type);
|
int NIAddAffix(IspellDict * Conf, int flag, char flagflags, const char *mask, const char *find, const char *repl, int type);
|
||||||
void SortDictionary(IspellDict * Conf);
|
void NISortDictionary(IspellDict * Conf);
|
||||||
void SortAffixes(IspellDict * Conf);
|
void NISortAffixes(IspellDict * Conf);
|
||||||
void FreeIspell(IspellDict * Conf);
|
void NIFree(IspellDict * Conf);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user