diff options
author | Tom Lane | 2007-08-22 01:39:46 +0000 |
---|---|---|
committer | Tom Lane | 2007-08-22 01:39:46 +0000 |
commit | d321421d0a409ee4473c996fd2275df0ff215eaf (patch) | |
tree | 016bb5ca76cb61c0876dbc272eb3eb57171d68d8 /src/backend/tsearch/dict_simple.c | |
parent | fd33d90a23150dec944cdfdf4587f7770543acd1 (diff) |
Simplify the syntax of CREATE/ALTER TEXT SEARCH DICTIONARY by treating the
init options of the template as top-level options in the syntax. This also
makes ALTER a bit easier to use, since options can be replaced individually.
I also made these statements verify that the tmplinit method will accept
the new settings before they get stored; in the original coding you didn't
find out about mistakes until the dictionary got invoked.
Under the hood, init methods now get options as a List of DefElem instead
of a raw text string --- that lets tsearch use existing options-pushing code
instead of duplicating functionality.
Diffstat (limited to 'src/backend/tsearch/dict_simple.c')
-rw-r--r-- | src/backend/tsearch/dict_simple.c | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/src/backend/tsearch/dict_simple.c b/src/backend/tsearch/dict_simple.c index 2c1bc3d017e..fcc08ea180d 100644 --- a/src/backend/tsearch/dict_simple.c +++ b/src/backend/tsearch/dict_simple.c @@ -7,12 +7,13 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/tsearch/dict_simple.c,v 1.1 2007/08/21 01:11:18 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/tsearch/dict_simple.c,v 1.2 2007/08/22 01:39:44 tgl Exp $ * *------------------------------------------------------------------------- */ #include "postgres.h" +#include "commands/defrem.h" #include "tsearch/ts_locale.h" #include "tsearch/ts_public.h" #include "tsearch/ts_utils.h" @@ -28,18 +29,34 @@ typedef struct Datum dsimple_init(PG_FUNCTION_ARGS) { + List *dictoptions = (List *) PG_GETARG_POINTER(0); DictExample *d = (DictExample *) palloc0(sizeof(DictExample)); + bool stoploaded = false; + ListCell *l; d->stoplist.wordop = recode_and_lowerstr; - if (!PG_ARGISNULL(0) && PG_GETARG_POINTER(0) != NULL) + foreach(l, dictoptions) { - text *in = PG_GETARG_TEXT_P(0); - char *filename = TextPGetCString(in); + DefElem *defel = (DefElem *) lfirst(l); - readstoplist(filename, &d->stoplist); - sortstoplist(&d->stoplist); - pfree(filename); + if (pg_strcasecmp("StopWords", defel->defname) == 0) + { + if (stoploaded) + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("multiple StopWords parameters"))); + readstoplist(defGetString(defel), &d->stoplist); + sortstoplist(&d->stoplist); + stoploaded = true; + } + else + { + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("unrecognized simple dictionary parameter: \"%s\"", + defel->defname))); + } } PG_RETURN_POINTER(d); |