Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "postgres.h"
00015
00016 #include "commands/defrem.h"
00017 #include "tsearch/ts_locale.h"
00018 #include "tsearch/ts_utils.h"
00019
00020
00021 typedef struct
00022 {
00023 StopList stoplist;
00024 bool accept;
00025 } DictSimple;
00026
00027
00028 Datum
00029 dsimple_init(PG_FUNCTION_ARGS)
00030 {
00031 List *dictoptions = (List *) PG_GETARG_POINTER(0);
00032 DictSimple *d = (DictSimple *) palloc0(sizeof(DictSimple));
00033 bool stoploaded = false,
00034 acceptloaded = false;
00035 ListCell *l;
00036
00037 d->accept = true;
00038
00039 foreach(l, dictoptions)
00040 {
00041 DefElem *defel = (DefElem *) lfirst(l);
00042
00043 if (pg_strcasecmp("StopWords", defel->defname) == 0)
00044 {
00045 if (stoploaded)
00046 ereport(ERROR,
00047 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
00048 errmsg("multiple StopWords parameters")));
00049 readstoplist(defGetString(defel), &d->stoplist, lowerstr);
00050 stoploaded = true;
00051 }
00052 else if (pg_strcasecmp("Accept", defel->defname) == 0)
00053 {
00054 if (acceptloaded)
00055 ereport(ERROR,
00056 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
00057 errmsg("multiple Accept parameters")));
00058 d->accept = defGetBoolean(defel);
00059 acceptloaded = true;
00060 }
00061 else
00062 {
00063 ereport(ERROR,
00064 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
00065 errmsg("unrecognized simple dictionary parameter: \"%s\"",
00066 defel->defname)));
00067 }
00068 }
00069
00070 PG_RETURN_POINTER(d);
00071 }
00072
00073 Datum
00074 dsimple_lexize(PG_FUNCTION_ARGS)
00075 {
00076 DictSimple *d = (DictSimple *) PG_GETARG_POINTER(0);
00077 char *in = (char *) PG_GETARG_POINTER(1);
00078 int32 len = PG_GETARG_INT32(2);
00079 char *txt;
00080 TSLexeme *res;
00081
00082 txt = lowerstr_with_len(in, len);
00083
00084 if (*txt == '\0' || searchstoplist(&(d->stoplist), txt))
00085 {
00086
00087 pfree(txt);
00088 res = palloc0(sizeof(TSLexeme) * 2);
00089 PG_RETURN_POINTER(res);
00090 }
00091 else if (d->accept)
00092 {
00093
00094 res = palloc0(sizeof(TSLexeme) * 2);
00095 res[0].lexeme = txt;
00096 PG_RETURN_POINTER(res);
00097 }
00098 else
00099 {
00100
00101 pfree(txt);
00102 PG_RETURN_POINTER(NULL);
00103 }
00104 }