1
/*-------------------------------------------------------------------------
4
* Ispell dictionary interface
6
* Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
10
* src/backend/tsearch/dict_ispell.c
12
*-------------------------------------------------------------------------
16
#include "commands/defrem.h"
17
#include "tsearch/dicts/spell.h"
18
#include "tsearch/ts_locale.h"
19
#include "tsearch/ts_public.h"
20
#include "tsearch/ts_utils.h"
21
#include "utils/builtins.h"
31
dispell_init(PG_FUNCTION_ARGS)
33
List *dictoptions = (List *) PG_GETARG_POINTER(0);
35
bool affloaded = false,
40
d = (DictISpell *) palloc0(sizeof(DictISpell));
42
NIStartBuild(&(d->obj));
44
foreach(l, dictoptions)
46
DefElem *defel = (DefElem *) lfirst(l);
48
if (pg_strcasecmp(defel->defname, "DictFile") == 0)
52
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
53
errmsg("multiple DictFile parameters")));
54
NIImportDictionary(&(d->obj),
55
get_tsearch_config_filename(defGetString(defel),
59
else if (pg_strcasecmp(defel->defname, "AffFile") == 0)
63
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
64
errmsg("multiple AffFile parameters")));
65
NIImportAffixes(&(d->obj),
66
get_tsearch_config_filename(defGetString(defel),
70
else if (pg_strcasecmp(defel->defname, "StopWords") == 0)
74
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
75
errmsg("multiple StopWords parameters")));
76
readstoplist(defGetString(defel), &(d->stoplist), lowerstr);
82
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
83
errmsg("unrecognized Ispell parameter: \"%s\"",
88
if (affloaded && dictloaded)
90
NISortDictionary(&(d->obj));
91
NISortAffixes(&(d->obj));
96
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
97
errmsg("missing AffFile parameter")));
102
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
103
errmsg("missing DictFile parameter")));
106
NIFinishBuild(&(d->obj));
108
PG_RETURN_POINTER(d);
112
dispell_lexize(PG_FUNCTION_ARGS)
114
DictISpell *d = (DictISpell *) PG_GETARG_POINTER(0);
115
char *in = (char *) PG_GETARG_POINTER(1);
116
int32 len = PG_GETARG_INT32(2);
123
PG_RETURN_POINTER(NULL);
125
txt = lowerstr_with_len(in, len);
126
res = NINormalizeWord(&(d->obj), txt);
129
PG_RETURN_POINTER(NULL);
134
if (searchstoplist(&(d->stoplist), ptr->lexeme))
142
memcpy(cptr, ptr, sizeof(TSLexeme));
149
PG_RETURN_POINTER(res);