diff options
author | Tom Lane | 2007-08-21 01:11:32 +0000 |
---|---|---|
committer | Tom Lane | 2007-08-21 01:11:32 +0000 |
commit | 140d4ebcb46e17cdb1be43892ed797e5e060c8ef (patch) | |
tree | f99d209dbe5e40dcb434c3841e0c8b4ff383f453 /src/backend/tsearch/dict_simple.c | |
parent | 4e94d1f952c3ce5670ceae3c12b55e344503a701 (diff) |
Tsearch2 functionality migrates to core. The bulk of this work is by
Oleg Bartunov and Teodor Sigaev, but I did a lot of editorializing,
so anything that's broken is probably my fault.
Documentation is nonexistent as yet, but let's land the patch so we can
get some portability testing done.
Diffstat (limited to 'src/backend/tsearch/dict_simple.c')
-rw-r--r-- | src/backend/tsearch/dict_simple.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/backend/tsearch/dict_simple.c b/src/backend/tsearch/dict_simple.c new file mode 100644 index 00000000000..2c1bc3d017e --- /dev/null +++ b/src/backend/tsearch/dict_simple.c @@ -0,0 +1,65 @@ +/*------------------------------------------------------------------------- + * + * dict_simple.c + * Simple dictionary: just lowercase and check for stopword + * + * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group + * + * + * IDENTIFICATION + * $PostgreSQL: pgsql/src/backend/tsearch/dict_simple.c,v 1.1 2007/08/21 01:11:18 tgl Exp $ + * + *------------------------------------------------------------------------- + */ +#include "postgres.h" + +#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) +{ + DictExample *d = (DictExample *) palloc0(sizeof(DictExample)); + + d->stoplist.wordop = recode_and_lowerstr; + + if (!PG_ARGISNULL(0) && PG_GETARG_POINTER(0) != NULL) + { + text *in = PG_GETARG_TEXT_P(0); + char *filename = TextPGetCString(in); + + readstoplist(filename, &d->stoplist); + sortstoplist(&d->stoplist); + pfree(filename); + } + + 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); +} |