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/snowball | |
| 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/snowball')
| -rw-r--r-- | src/backend/snowball/dict_snowball.c | 38 | ||||
| -rw-r--r-- | src/backend/snowball/snowball.sql.in | 4 |
2 files changed, 14 insertions, 28 deletions
diff --git a/src/backend/snowball/dict_snowball.c b/src/backend/snowball/dict_snowball.c index f0bc2feedec..03f2dd928c2 100644 --- a/src/backend/snowball/dict_snowball.c +++ b/src/backend/snowball/dict_snowball.c @@ -6,12 +6,13 @@ * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/snowball/dict_snowball.c,v 1.1 2007/08/21 01:11:16 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/snowball/dict_snowball.c,v 1.2 2007/08/22 01:39:44 tgl Exp $ * *------------------------------------------------------------------------- */ #include "postgres.h" +#include "commands/defrem.h" #include "fmgr.h" #include "tsearch/ts_locale.h" #include "tsearch/ts_public.h" @@ -185,59 +186,44 @@ locate_stem_module(DictSnowball * d, char *lang) Datum dsnowball_init(PG_FUNCTION_ARGS) { - text *in; + List *dictoptions = (List *) PG_GETARG_POINTER(0); DictSnowball *d; - Map *cfg, - *pcfg; bool stoploaded = false; - - /* init functions must defend against NULLs for themselves */ - if (PG_ARGISNULL(0) || PG_GETARG_POINTER(0) == NULL) - ereport(ERROR, - (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("NULL config not allowed for Snowball"))); - in = PG_GETARG_TEXT_P(0); + ListCell *l; d = (DictSnowball *) palloc0(sizeof(DictSnowball)); d->stoplist.wordop = recode_and_lowerstr; - parse_keyvalpairs(in, &cfg); - pcfg = cfg; - PG_FREE_IF_COPY(in, 0); - - while (pcfg && pcfg->key) + foreach(l, dictoptions) { - if (pg_strcasecmp("StopWords", pcfg->key) == 0) + DefElem *defel = (DefElem *) lfirst(l); + + if (pg_strcasecmp("StopWords", defel->defname) == 0) { if (stoploaded) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("multiple StopWords parameters"))); - readstoplist(pcfg->value, &d->stoplist); + readstoplist(defGetString(defel), &d->stoplist); sortstoplist(&d->stoplist); stoploaded = true; } - else if (pg_strcasecmp("Language", pcfg->key) == 0) + else if (pg_strcasecmp("Language", defel->defname) == 0) { if (d->stem) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("multiple Language parameters"))); - locate_stem_module(d, pcfg->value); + locate_stem_module(d, defGetString(defel)); } else { ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("unrecognized Snowball parameter: \"%s\"", - pcfg->key))); + defel->defname))); } - - pfree(pcfg->key); - pfree(pcfg->value); - pcfg++; } - pfree(cfg); if (!d->stem) ereport(ERROR, diff --git a/src/backend/snowball/snowball.sql.in b/src/backend/snowball/snowball.sql.in index 5f1f3e772e8..873a5bf5592 100644 --- a/src/backend/snowball/snowball.sql.in +++ b/src/backend/snowball/snowball.sql.in @@ -1,9 +1,9 @@ --- $PostgreSQL: pgsql/src/backend/snowball/snowball.sql.in,v 1.1 2007/08/21 01:11:16 tgl Exp $$ +-- $PostgreSQL: pgsql/src/backend/snowball/snowball.sql.in,v 1.2 2007/08/22 01:39:44 tgl Exp $$ -- text search configuration for _CFGNAME_ language CREATE TEXT SEARCH DICTIONARY _DICTNAME_ (TEMPLATE = snowball, - OPTION = 'Language=_DICTNAME__STOPWORDS_'); + Language = _DICTNAME_ _STOPWORDS_); COMMENT ON TEXT SEARCH DICTIONARY _DICTNAME_ IS 'Snowball stemmer for _DICTNAME_ language'; |
