diff -Naur postgresql-8.2.4-orig/contrib/tsearch2/dict_stop.c postgresql-8.2.4/contrib/tsearch2/dict_stop.c --- postgresql-8.2.4-orig/contrib/tsearch2/dict_stop.c 1970-01-01 01:00:00.000000000 +0100 +++ postgresql-8.2.4/contrib/tsearch2/dict_stop.c 2007-09-14 19:34:12.000000000 +0200 @@ -0,0 +1,69 @@ +/* + * A dictionary that only recognizes stopwords (and discards them) + * Jan Urbanski + */ +#include "postgres.h" +#include "common.h" +#include "dict.h" +#include "ts_locale.h" + + +PG_FUNCTION_INFO_V1(stop_init); +Datum stop_init(PG_FUNCTION_ARGS); + +PG_FUNCTION_INFO_V1(stop_lexize); +Datum stop_lexize(PG_FUNCTION_ARGS); + +Datum +stop_init(PG_FUNCTION_ARGS) +{ + StopList *l = (StopList *) malloc(sizeof(StopList)); + + if (!l) + ereport(ERROR, + (errcode(ERRCODE_OUT_OF_MEMORY), + errmsg("out of memory"))); + memset(l, 0, sizeof(StopList)); + l->wordop = lowerstr; + + if (!PG_ARGISNULL(0) && PG_GETARG_POINTER(0) != NULL) + { + text *in = PG_GETARG_TEXT_P(0); + + readstoplist(in, l); + sortstoplist(l); + PG_FREE_IF_COPY(in, 0); + } + + PG_RETURN_POINTER(l); +} + +Datum +stop_lexize(PG_FUNCTION_ARGS) +{ + StopList *l = (StopList *) PG_GETARG_POINTER(0); + char *in = (char *) PG_GETARG_POINTER(1); + char *utxt = pnstrdup(in, PG_GETARG_INT32(2)); + TSLexeme *res = palloc(sizeof(TSLexeme) * 2); + char *txt = lowerstr(utxt); + + int found = 0; + + pfree(utxt); + memset(res, 0, sizeof(TSLexeme) * 2); + if (*txt == '\0' || searchstoplist(l, txt)) + { + found = 1; + } + pfree(txt); + + if (found) + { + PG_RETURN_POINTER(res); + } + else + { + pfree(res); + PG_RETURN_POINTER(NULL); + } +} diff -Naur postgresql-8.2.4-orig/contrib/tsearch2/Makefile postgresql-8.2.4/contrib/tsearch2/Makefile --- postgresql-8.2.4-orig/contrib/tsearch2/Makefile 2007-09-14 19:28:48.000000000 +0200 +++ postgresql-8.2.4/contrib/tsearch2/Makefile 2007-09-14 19:30:52.000000000 +0200 @@ -2,7 +2,7 @@ MODULE_big = tsearch2 OBJS = dict_ex.o dict.o snmap.o stopword.o common.o prs_dcfg.o \ - dict_snowball.o dict_ispell.o dict_syn.o dict_thesaurus.o \ + dict_snowball.o dict_ispell.o dict_syn.o dict_thesaurus.o dict_stop.o \ wparser.o wparser_def.o \ ts_cfg.o tsvector.o query_cleanup.o crc32.o query.o gistidx.o \ tsvector_op.o rank.o ts_stat.o \ diff -Naur postgresql-8.2.4-orig/contrib/tsearch2/tsearch.sql.in postgresql-8.2.4/contrib/tsearch2/tsearch.sql.in --- postgresql-8.2.4-orig/contrib/tsearch2/tsearch.sql.in 2007-09-14 19:28:48.000000000 +0200 +++ postgresql-8.2.4/contrib/tsearch2/tsearch.sql.in 2007-09-14 19:30:52.000000000 +0200 @@ -82,6 +82,25 @@ 'English Stemmer. Snowball.' ; +CREATE FUNCTION stop_init(internal) + RETURNS internal + as 'MODULE_PATHNAME' + LANGUAGE C; + +CREATE FUNCTION stop_lexize(internal,internal,int4) + RETURNS internal + as 'MODULE_PATHNAME' + LANGUAGE C + RETURNS NULL ON NULL INPUT; + +insert into pg_ts_dict select + 'stop', + 'stop_init(internal)', + 'contrib/english.stop', + 'stop_lexize(internal,internal,int4)', + 'Stopwords sieve. Must have stopwords file.' +; + CREATE FUNCTION snb_ru_init_koi8(internal) RETURNS internal as 'MODULE_PATHNAME'