2007-08-21 03:11:32 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* dict_simple.c
|
|
|
|
* Simple dictionary: just lowercase and check for stopword
|
|
|
|
*
|
|
|
|
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
2007-08-22 03:39:46 +02:00
|
|
|
* $PostgreSQL: pgsql/src/backend/tsearch/dict_simple.c,v 1.2 2007/08/22 01:39:44 tgl Exp $
|
2007-08-21 03:11:32 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#include "postgres.h"
|
|
|
|
|
2007-08-22 03:39:46 +02:00
|
|
|
#include "commands/defrem.h"
|
2007-08-21 03:11:32 +02:00
|
|
|
#include "tsearch/ts_locale.h"
|
|
|
|
#include "tsearch/ts_public.h"
|
|
|
|
#include "tsearch/ts_utils.h"
|
|
|
|
#include "utils/builtins.h"
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
StopList stoplist;
|
|
|
|
} DictExample;
|
|
|
|
|
|
|
|
|
|
|
|
Datum
|
|
|
|
dsimple_init(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2007-08-22 03:39:46 +02:00
|
|
|
List *dictoptions = (List *) PG_GETARG_POINTER(0);
|
2007-08-21 03:11:32 +02:00
|
|
|
DictExample *d = (DictExample *) palloc0(sizeof(DictExample));
|
2007-08-22 03:39:46 +02:00
|
|
|
bool stoploaded = false;
|
|
|
|
ListCell *l;
|
2007-08-21 03:11:32 +02:00
|
|
|
|
|
|
|
d->stoplist.wordop = recode_and_lowerstr;
|
|
|
|
|
2007-08-22 03:39:46 +02:00
|
|
|
foreach(l, dictoptions)
|
2007-08-21 03:11:32 +02:00
|
|
|
{
|
2007-08-22 03:39:46 +02:00
|
|
|
DefElem *defel = (DefElem *) lfirst(l);
|
2007-08-21 03:11:32 +02:00
|
|
|
|
2007-08-22 03:39:46 +02:00
|
|
|
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)));
|
|
|
|
}
|
2007-08-21 03:11:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
PG_RETURN_POINTER(d);
|
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
|
|
|
dsimple_lexize(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
DictExample *d = (DictExample *) PG_GETARG_POINTER(0);
|
|
|
|
char *in = (char *) PG_GETARG_POINTER(1);
|
|
|
|
int32 len = PG_GETARG_INT32(2);
|
|
|
|
char *txt = lowerstr_with_len(in, len);
|
|
|
|
TSLexeme *res = palloc0(sizeof(TSLexeme) * 2);
|
|
|
|
|
|
|
|
if (*txt == '\0' || searchstoplist(&(d->stoplist), txt))
|
|
|
|
{
|
|
|
|
pfree(txt);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
res[0].lexeme = txt;
|
|
|
|
|
|
|
|
PG_RETURN_POINTER(res);
|
|
|
|
}
|