mirror of
https://github.com/postgres/postgres.git
synced 2025-12-06 00:02:13 +03:00
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.
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user