diff options
| author | Teodor Sigaev <teodor@sigaev.ru> | 2003-07-21 10:27:44 +0000 |
|---|---|---|
| committer | Teodor Sigaev <teodor@sigaev.ru> | 2003-07-21 10:27:44 +0000 |
| commit | b88605337ea37ce1080a696937540cf8b48338d1 (patch) | |
| tree | ed26ee96ed8ca176fca8a956e938b3cc7adcb1f3 /contrib/tsearch2/dict_ex.c | |
| parent | a6053826703e288ccc7bd2a9a86a278cef6bc7ed (diff) | |
| download | postgresql-b88605337ea37ce1080a696937540cf8b48338d1.tar.gz | |
tsearch2 module
Diffstat (limited to 'contrib/tsearch2/dict_ex.c')
| -rw-r--r-- | contrib/tsearch2/dict_ex.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/contrib/tsearch2/dict_ex.c b/contrib/tsearch2/dict_ex.c new file mode 100644 index 0000000000..b8c4f59c90 --- /dev/null +++ b/contrib/tsearch2/dict_ex.c @@ -0,0 +1,59 @@ +/* + * example of dictionary + * Teodor Sigaev <teodor@sigaev.ru> + */ +#include <errno.h> +#include <stdlib.h> +#include <string.h> + +#include "postgres.h" + +#include "dict.h" +#include "common.h" + +typedef struct { + StopList stoplist; +} DictExample; + + +PG_FUNCTION_INFO_V1(dex_init); +Datum dex_init(PG_FUNCTION_ARGS); +PG_FUNCTION_INFO_V1(dex_lexize); +Datum dex_lexize(PG_FUNCTION_ARGS); + +Datum +dex_init(PG_FUNCTION_ARGS) { + DictExample *d = (DictExample*)malloc( sizeof(DictExample) ); + + if ( !d ) + elog(ERROR, "No memory"); + memset(d,0,sizeof(DictExample)); + + d->stoplist.wordop=lowerstr; + + if ( !PG_ARGISNULL(0) && PG_GETARG_POINTER(0)!=NULL ) { + text *in = PG_GETARG_TEXT_P(0); + readstoplist(in, &(d->stoplist)); + sortstoplist(&(d->stoplist)); + PG_FREE_IF_COPY(in, 0); + } + + PG_RETURN_POINTER(d); +} + +Datum +dex_lexize(PG_FUNCTION_ARGS) { + DictExample *d = (DictExample*)PG_GETARG_POINTER(0); + char *in = (char*)PG_GETARG_POINTER(1); + char *txt = pnstrdup(in, PG_GETARG_INT32(2)); + char **res=palloc(sizeof(char*)*2); + + if ( *txt=='\0' || searchstoplist(&(d->stoplist),txt) ) { + pfree(txt); + res[0]=NULL; + } else + res[0]=txt; + res[1]=NULL; + + PG_RETURN_POINTER(res); +} |
