aboutsummaryrefslogtreecommitdiff
path: root/contrib/tsearch2/gendict/dict_snowball.c.IN
blob: 7136ee19ddc7187a79d446379d1fe0cace0ae193 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* $PostgreSQL: pgsql/contrib/tsearch2/gendict/dict_snowball.c.IN,v 1.5 2006/07/14 05:28:27 tgl Exp $ */

/* 
 * example of Snowball dictionary
 * http://snowball.tartarus.org/ 
 * Teodor Sigaev <teodor@sigaev.ru>
 */
#include "postgres.h"

#include "dict.h"
#include "common.h"
#include "snowball/header.h"
#include "subinclude.h"
#include "ts_locale.h"

typedef struct {
	struct SN_env *z;
	StopList	stoplist;
	int	(*stem)(struct SN_env * z);
} DictSnowball;


PG_FUNCTION_INFO_V1(dinit_CFG_MODNAME);
Datum dinit_CFG_MODNAME(PG_FUNCTION_ARGS);

Datum 
dinit_CFG_MODNAME(PG_FUNCTION_ARGS) {
	DictSnowball	*d = (DictSnowball*)malloc( sizeof(DictSnowball) );

	if ( !d )
		ereport(ERROR,
				(errcode(ERRCODE_OUT_OF_MEMORY),
				 errmsg("out of memory")));
	memset(d,0,sizeof(DictSnowball));
	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);
	}

	d->z = CFG_PREFIX_create_env();
	if (!d->z) {
		freestoplist(&(d->stoplist));
		ereport(ERROR,
				(errcode(ERRCODE_OUT_OF_MEMORY),
				 errmsg("out of memory")));
	}
	d->stem=CFG_PREFIX_stem;

	PG_RETURN_POINTER(d);
}