3
* Teodor Sigaev <teodor@sigaev.ru>
13
#include "ispell/spell.h"
21
PG_FUNCTION_INFO_V1(spell_init);
22
Datum spell_init(PG_FUNCTION_ARGS);
24
PG_FUNCTION_INFO_V1(spell_lexize);
25
Datum spell_lexize(PG_FUNCTION_ARGS);
28
freeDictISpell(DictISpell * d)
31
freestoplist(&(d->stoplist));
36
spell_init(PG_FUNCTION_ARGS)
42
bool affloaded = false,
46
if (PG_ARGISNULL(0) || PG_GETARG_POINTER(0) == NULL)
48
(errcode(ERRCODE_CONFIG_FILE_ERROR),
49
errmsg("ISpell confguration error")));
51
d = (DictISpell *) malloc(sizeof(DictISpell));
54
(errcode(ERRCODE_OUT_OF_MEMORY),
55
errmsg("out of memory")));
56
memset(d, 0, sizeof(DictISpell));
57
d->stoplist.wordop = lowerstr;
59
in = PG_GETARG_TEXT_P(0);
60
parse_cfgdict(in, &cfg);
61
PG_FREE_IF_COPY(in, 0);
65
if (pg_strcasecmp("DictFile", pcfg->key) == 0)
71
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
72
errmsg("dictionary already loaded")));
74
if (NIImportDictionary(&(d->obj), pcfg->value))
78
(errcode(ERRCODE_CONFIG_FILE_ERROR),
79
errmsg("could not load dictionary file \"%s\"",
84
else if (pg_strcasecmp("AffFile", pcfg->key) == 0)
90
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
91
errmsg("affixes already loaded")));
93
if (NIImportAffixes(&(d->obj), pcfg->value))
97
(errcode(ERRCODE_CONFIG_FILE_ERROR),
98
errmsg("could not load affix file \"%s\"",
103
else if (pg_strcasecmp("StopFile", pcfg->key) == 0)
105
text *tmp = char2text(pcfg->value);
111
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
112
errmsg("stop words already loaded")));
114
readstoplist(tmp, &(d->stoplist));
115
sortstoplist(&(d->stoplist));
123
(errcode(ERRCODE_SYNTAX_ERROR),
124
errmsg("unrecognized option: %s => %s",
125
pcfg->key, pcfg->value)));
133
if (affloaded && dictloaded)
135
NISortDictionary(&(d->obj));
136
NISortAffixes(&(d->obj));
142
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
143
errmsg("no affixes")));
149
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
150
errmsg("no dictionary")));
153
PG_RETURN_POINTER(d);
157
spell_lexize(PG_FUNCTION_ARGS)
159
DictISpell *d = (DictISpell *) PG_GETARG_POINTER(0);
160
char *in = (char *) PG_GETARG_POINTER(1);
166
if (!PG_GETARG_INT32(2))
167
PG_RETURN_POINTER(NULL);
169
res = palloc(sizeof(char *) * 2);
170
txt = pnstrdup(in, PG_GETARG_INT32(2));
171
res = NINormalizeWord(&(d->obj), txt);
175
PG_RETURN_POINTER(NULL);
180
if (searchstoplist(&(d->stoplist), *ptr))
195
PG_RETURN_POINTER(res);