1 /*-------------------------------------------------------------------------
4 * Simple dictionary: just lowercase and check for stopword
6 * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
10 * $PostgreSQL: pgsql/src/backend/tsearch/dict_simple.c,v 1.7 2008/01/01 19:45:52 momjian Exp $
12 *-------------------------------------------------------------------------
16 #include "commands/defrem.h"
17 #include "tsearch/ts_locale.h"
18 #include "tsearch/ts_public.h"
19 #include "tsearch/ts_utils.h"
20 #include "utils/builtins.h"
31 dsimple_init(PG_FUNCTION_ARGS)
33 List *dictoptions = (List *) PG_GETARG_POINTER(0);
34 DictSimple *d = (DictSimple *) palloc0(sizeof(DictSimple));
35 bool stoploaded = false,
39 d->accept = true; /* default */
41 foreach(l, dictoptions)
43 DefElem *defel = (DefElem *) lfirst(l);
45 if (pg_strcasecmp("StopWords", defel->defname) == 0)
49 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
50 errmsg("multiple StopWords parameters")));
51 readstoplist(defGetString(defel), &d->stoplist, lowerstr);
54 else if (pg_strcasecmp("Accept", defel->defname) == 0)
58 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
59 errmsg("multiple Accept parameters")));
60 d->accept = defGetBoolean(defel);
66 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
67 errmsg("unrecognized simple dictionary parameter: \"%s\"",
76 dsimple_lexize(PG_FUNCTION_ARGS)
78 DictSimple *d = (DictSimple *) PG_GETARG_POINTER(0);
79 char *in = (char *) PG_GETARG_POINTER(1);
80 int32 len = PG_GETARG_INT32(2);
84 txt = lowerstr_with_len(in, len);
86 if (*txt == '\0' || searchstoplist(&(d->stoplist), txt))
88 /* reject as stopword */
90 res = palloc0(sizeof(TSLexeme) * 2);
91 PG_RETURN_POINTER(res);
96 res = palloc0(sizeof(TSLexeme) * 2);
98 PG_RETURN_POINTER(res);
102 /* report as unrecognized */
104 PG_RETURN_POINTER(NULL);