1 /*-------------------------------------------------------------------------
4 * Ispell dictionary interface
6 * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
10 * $PostgreSQL: pgsql/src/backend/tsearch/dict_ispell.c,v 1.7 2008/01/01 19:45:52 momjian Exp $
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"
22 #include "utils/memutils.h"
32 dispell_init(PG_FUNCTION_ARGS)
34 List *dictoptions = (List *) PG_GETARG_POINTER(0);
36 bool affloaded = false,
41 d = (DictISpell *) palloc0(sizeof(DictISpell));
43 foreach(l, dictoptions)
45 DefElem *defel = (DefElem *) lfirst(l);
47 if (pg_strcasecmp(defel->defname, "DictFile") == 0)
51 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
52 errmsg("multiple DictFile parameters")));
53 NIImportDictionary(&(d->obj),
54 get_tsearch_config_filename(defGetString(defel),
58 else if (pg_strcasecmp(defel->defname, "AffFile") == 0)
62 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
63 errmsg("multiple AffFile parameters")));
64 NIImportAffixes(&(d->obj),
65 get_tsearch_config_filename(defGetString(defel),
69 else if (pg_strcasecmp(defel->defname, "StopWords") == 0)
73 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
74 errmsg("multiple StopWords parameters")));
75 readstoplist(defGetString(defel), &(d->stoplist), lowerstr);
81 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
82 errmsg("unrecognized Ispell parameter: \"%s\"",
87 if (affloaded && dictloaded)
89 NISortDictionary(&(d->obj));
90 NISortAffixes(&(d->obj));
95 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
96 errmsg("missing AffFile parameter")));
101 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
102 errmsg("missing DictFile parameter")));
105 MemoryContextDeleteChildren(CurrentMemoryContext);
107 PG_RETURN_POINTER(d);
111 dispell_lexize(PG_FUNCTION_ARGS)
113 DictISpell *d = (DictISpell *) PG_GETARG_POINTER(0);
114 char *in = (char *) PG_GETARG_POINTER(1);
115 int32 len = PG_GETARG_INT32(2);
122 PG_RETURN_POINTER(NULL);
124 txt = lowerstr_with_len(in, len);
125 res = NINormalizeWord(&(d->obj), txt);
128 PG_RETURN_POINTER(NULL);
133 if (searchstoplist(&(d->stoplist), ptr->lexeme))
141 memcpy(cptr, ptr, sizeof(TSLexeme));
148 PG_RETURN_POINTER(res);