Correction crash
[auf_roundup.git] / build / lib / roundup / backends / tsearch2_setup.py
CommitLineData
c638d827
CR
1#$Id: tsearch2_setup.py,v 1.2 2005-01-08 11:25:23 jlgijsbers Exp $
2
3# All the SQL in this module is taken from the tsearch2 module in the contrib
4# tree of PostgreSQL 7.4.6. PostgreSQL, and this code, has the following
5# license:
6#
7# PostgreSQL Data Base Management System
8# (formerly known as Postgres, then as Postgres95).
9#
10# Portions Copyright (c) 1996-2003, The PostgreSQL Global Development Group
11#
12# Portions Copyright (c) 1994, The Regents of the University of California
13#
14# Permission to use, copy, modify, and distribute this software and its
15# documentation for any purpose, without fee, and without a written agreement
16# is hereby granted, provided that the above copyright notice and this
17# paragraph and the following two paragraphs appear in all copies.
18#
19# IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
20# DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING
21# LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
22# DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE
23# POSSIBILITY OF SUCH DAMAGE.
24#
25# THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
26# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
27# AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
28# ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO
29# PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
30
31tsearch_sql = """ -- Adjust this setting to control where the objects get CREATEd.
32SET search_path = public;
33
34--dict conf
35CREATE TABLE pg_ts_dict (
36 dict_name text not null primary key,
37 dict_init oid,
38 dict_initoption text,
39 dict_lexize oid not null,
40 dict_comment text
41) with oids;
42
43--dict interface
44CREATE FUNCTION lexize(oid, text)
45 returns _text
46 as '$libdir/tsearch2'
47 language 'C'
48 with (isstrict);
49
50CREATE FUNCTION lexize(text, text)
51 returns _text
52 as '$libdir/tsearch2', 'lexize_byname'
53 language 'C'
54 with (isstrict);
55
56CREATE FUNCTION lexize(text)
57 returns _text
58 as '$libdir/tsearch2', 'lexize_bycurrent'
59 language 'C'
60 with (isstrict);
61
62CREATE FUNCTION set_curdict(int)
63 returns void
64 as '$libdir/tsearch2'
65 language 'C'
66 with (isstrict);
67
68CREATE FUNCTION set_curdict(text)
69 returns void
70 as '$libdir/tsearch2', 'set_curdict_byname'
71 language 'C'
72 with (isstrict);
73
74--built-in dictionaries
75CREATE FUNCTION dex_init(text)
76 returns internal
77 as '$libdir/tsearch2'
78 language 'C';
79
80CREATE FUNCTION dex_lexize(internal,internal,int4)
81 returns internal
82 as '$libdir/tsearch2'
83 language 'C'
84 with (isstrict);
85
86insert into pg_ts_dict select
87 'simple',
88 (select oid from pg_proc where proname='dex_init'),
89 null,
90 (select oid from pg_proc where proname='dex_lexize'),
91 'Simple example of dictionary.'
92;
93
94CREATE FUNCTION snb_en_init(text)
95 returns internal
96 as '$libdir/tsearch2'
97 language 'C';
98
99CREATE FUNCTION snb_lexize(internal,internal,int4)
100 returns internal
101 as '$libdir/tsearch2'
102 language 'C'
103 with (isstrict);
104
105insert into pg_ts_dict select
106 'en_stem',
107 (select oid from pg_proc where proname='snb_en_init'),
108 '/usr/share/postgresql/contrib/english.stop',
109 (select oid from pg_proc where proname='snb_lexize'),
110 'English Stemmer. Snowball.'
111;
112
113CREATE FUNCTION snb_ru_init(text)
114 returns internal
115 as '$libdir/tsearch2'
116 language 'C';
117
118insert into pg_ts_dict select
119 'ru_stem',
120 (select oid from pg_proc where proname='snb_ru_init'),
121 '/usr/share/postgresql/contrib/russian.stop',
122 (select oid from pg_proc where proname='snb_lexize'),
123 'Russian Stemmer. Snowball.'
124;
125
126CREATE FUNCTION spell_init(text)
127 returns internal
128 as '$libdir/tsearch2'
129 language 'C';
130
131CREATE FUNCTION spell_lexize(internal,internal,int4)
132 returns internal
133 as '$libdir/tsearch2'
134 language 'C'
135 with (isstrict);
136
137insert into pg_ts_dict select
138 'ispell_template',
139 (select oid from pg_proc where proname='spell_init'),
140 null,
141 (select oid from pg_proc where proname='spell_lexize'),
142 'ISpell interface. Must have .dict and .aff files'
143;
144
145CREATE FUNCTION syn_init(text)
146 returns internal
147 as '$libdir/tsearch2'
148 language 'C';
149
150CREATE FUNCTION syn_lexize(internal,internal,int4)
151 returns internal
152 as '$libdir/tsearch2'
153 language 'C'
154 with (isstrict);
155
156insert into pg_ts_dict select
157 'synonym',
158 (select oid from pg_proc where proname='syn_init'),
159 null,
160 (select oid from pg_proc where proname='syn_lexize'),
161 'Example of synonym dictionary'
162;
163
164--dict conf
165CREATE TABLE pg_ts_parser (
166 prs_name text not null primary key,
167 prs_start oid not null,
168 prs_nexttoken oid not null,
169 prs_end oid not null,
170 prs_headline oid not null,
171 prs_lextype oid not null,
172 prs_comment text
173) with oids;
174
175--sql-level interface
176CREATE TYPE tokentype
177 as (tokid int4, alias text, descr text);
178
179CREATE FUNCTION token_type(int4)
180 returns setof tokentype
181 as '$libdir/tsearch2'
182 language 'C'
183 with (isstrict);
184
185CREATE FUNCTION token_type(text)
186 returns setof tokentype
187 as '$libdir/tsearch2', 'token_type_byname'
188 language 'C'
189 with (isstrict);
190
191CREATE FUNCTION token_type()
192 returns setof tokentype
193 as '$libdir/tsearch2', 'token_type_current'
194 language 'C'
195 with (isstrict);
196
197CREATE FUNCTION set_curprs(int)
198 returns void
199 as '$libdir/tsearch2'
200 language 'C'
201 with (isstrict);
202
203CREATE FUNCTION set_curprs(text)
204 returns void
205 as '$libdir/tsearch2', 'set_curprs_byname'
206 language 'C'
207 with (isstrict);
208
209CREATE TYPE tokenout
210 as (tokid int4, token text);
211
212CREATE FUNCTION parse(oid,text)
213 returns setof tokenout
214 as '$libdir/tsearch2'
215 language 'C'
216 with (isstrict);
217
218CREATE FUNCTION parse(text,text)
219 returns setof tokenout
220 as '$libdir/tsearch2', 'parse_byname'
221 language 'C'
222 with (isstrict);
223
224CREATE FUNCTION parse(text)
225 returns setof tokenout
226 as '$libdir/tsearch2', 'parse_current'
227 language 'C'
228 with (isstrict);
229
230--default parser
231CREATE FUNCTION prsd_start(internal,int4)
232 returns internal
233 as '$libdir/tsearch2'
234 language 'C';
235
236CREATE FUNCTION prsd_getlexeme(internal,internal,internal)
237 returns int4
238 as '$libdir/tsearch2'
239 language 'C';
240
241CREATE FUNCTION prsd_end(internal)
242 returns void
243 as '$libdir/tsearch2'
244 language 'C';
245
246CREATE FUNCTION prsd_lextype(internal)
247 returns internal
248 as '$libdir/tsearch2'
249 language 'C';
250
251CREATE FUNCTION prsd_headline(internal,internal,internal)
252 returns internal
253 as '$libdir/tsearch2'
254 language 'C';
255
256insert into pg_ts_parser select
257 'default',
258 (select oid from pg_proc where proname='prsd_start'),
259 (select oid from pg_proc where proname='prsd_getlexeme'),
260 (select oid from pg_proc where proname='prsd_end'),
261 (select oid from pg_proc where proname='prsd_headline'),
262 (select oid from pg_proc where proname='prsd_lextype'),
263 'Parser from OpenFTS v0.34'
264;
265
266--tsearch config
267
268CREATE TABLE pg_ts_cfg (
269 ts_name text not null primary key,
270 prs_name text not null,
271 locale text
272) with oids;
273
274CREATE TABLE pg_ts_cfgmap (
275 ts_name text not null,
276 tok_alias text not null,
277 dict_name text[],
278 primary key (ts_name,tok_alias)
279) with oids;
280
281CREATE FUNCTION set_curcfg(int)
282 returns void
283 as '$libdir/tsearch2'
284 language 'C'
285 with (isstrict);
286
287CREATE FUNCTION set_curcfg(text)
288 returns void
289 as '$libdir/tsearch2', 'set_curcfg_byname'
290 language 'C'
291 with (isstrict);
292
293CREATE FUNCTION show_curcfg()
294 returns oid
295 as '$libdir/tsearch2'
296 language 'C'
297 with (isstrict);
298
299insert into pg_ts_cfg values ('default', 'default','C');
300insert into pg_ts_cfg values ('default_russian', 'default','ru_RU.KOI8-R');
301insert into pg_ts_cfg values ('simple', 'default');
302
303insert into pg_ts_cfgmap values ('default', 'lword', '{en_stem}');
304insert into pg_ts_cfgmap values ('default', 'nlword', '{simple}');
305insert into pg_ts_cfgmap values ('default', 'word', '{simple}');
306insert into pg_ts_cfgmap values ('default', 'email', '{simple}');
307insert into pg_ts_cfgmap values ('default', 'url', '{simple}');
308insert into pg_ts_cfgmap values ('default', 'host', '{simple}');
309insert into pg_ts_cfgmap values ('default', 'sfloat', '{simple}');
310insert into pg_ts_cfgmap values ('default', 'version', '{simple}');
311insert into pg_ts_cfgmap values ('default', 'part_hword', '{simple}');
312insert into pg_ts_cfgmap values ('default', 'nlpart_hword', '{simple}');
313insert into pg_ts_cfgmap values ('default', 'lpart_hword', '{en_stem}');
314insert into pg_ts_cfgmap values ('default', 'hword', '{simple}');
315insert into pg_ts_cfgmap values ('default', 'lhword', '{en_stem}');
316insert into pg_ts_cfgmap values ('default', 'nlhword', '{simple}');
317insert into pg_ts_cfgmap values ('default', 'uri', '{simple}');
318insert into pg_ts_cfgmap values ('default', 'file', '{simple}');
319insert into pg_ts_cfgmap values ('default', 'float', '{simple}');
320insert into pg_ts_cfgmap values ('default', 'int', '{simple}');
321insert into pg_ts_cfgmap values ('default', 'uint', '{simple}');
322insert into pg_ts_cfgmap values ('default_russian', 'lword', '{en_stem}');
323insert into pg_ts_cfgmap values ('default_russian', 'nlword', '{ru_stem}');
324insert into pg_ts_cfgmap values ('default_russian', 'word', '{ru_stem}');
325insert into pg_ts_cfgmap values ('default_russian', 'email', '{simple}');
326insert into pg_ts_cfgmap values ('default_russian', 'url', '{simple}');
327insert into pg_ts_cfgmap values ('default_russian', 'host', '{simple}');
328insert into pg_ts_cfgmap values ('default_russian', 'sfloat', '{simple}');
329insert into pg_ts_cfgmap values ('default_russian', 'version', '{simple}');
330insert into pg_ts_cfgmap values ('default_russian', 'part_hword', '{simple}');
331insert into pg_ts_cfgmap values ('default_russian', 'nlpart_hword', '{ru_stem}');
332insert into pg_ts_cfgmap values ('default_russian', 'lpart_hword', '{en_stem}');
333insert into pg_ts_cfgmap values ('default_russian', 'hword', '{ru_stem}');
334insert into pg_ts_cfgmap values ('default_russian', 'lhword', '{en_stem}');
335insert into pg_ts_cfgmap values ('default_russian', 'nlhword', '{ru_stem}');
336insert into pg_ts_cfgmap values ('default_russian', 'uri', '{simple}');
337insert into pg_ts_cfgmap values ('default_russian', 'file', '{simple}');
338insert into pg_ts_cfgmap values ('default_russian', 'float', '{simple}');
339insert into pg_ts_cfgmap values ('default_russian', 'int', '{simple}');
340insert into pg_ts_cfgmap values ('default_russian', 'uint', '{simple}');
341insert into pg_ts_cfgmap values ('simple', 'lword', '{simple}');
342insert into pg_ts_cfgmap values ('simple', 'nlword', '{simple}');
343insert into pg_ts_cfgmap values ('simple', 'word', '{simple}');
344insert into pg_ts_cfgmap values ('simple', 'email', '{simple}');
345insert into pg_ts_cfgmap values ('simple', 'url', '{simple}');
346insert into pg_ts_cfgmap values ('simple', 'host', '{simple}');
347insert into pg_ts_cfgmap values ('simple', 'sfloat', '{simple}');
348insert into pg_ts_cfgmap values ('simple', 'version', '{simple}');
349insert into pg_ts_cfgmap values ('simple', 'part_hword', '{simple}');
350insert into pg_ts_cfgmap values ('simple', 'nlpart_hword', '{simple}');
351insert into pg_ts_cfgmap values ('simple', 'lpart_hword', '{simple}');
352insert into pg_ts_cfgmap values ('simple', 'hword', '{simple}');
353insert into pg_ts_cfgmap values ('simple', 'lhword', '{simple}');
354insert into pg_ts_cfgmap values ('simple', 'nlhword', '{simple}');
355insert into pg_ts_cfgmap values ('simple', 'uri', '{simple}');
356insert into pg_ts_cfgmap values ('simple', 'file', '{simple}');
357insert into pg_ts_cfgmap values ('simple', 'float', '{simple}');
358insert into pg_ts_cfgmap values ('simple', 'int', '{simple}');
359insert into pg_ts_cfgmap values ('simple', 'uint', '{simple}');
360
361--tsvector type
362CREATE FUNCTION tsvector_in(cstring)
363RETURNS tsvector
364AS '$libdir/tsearch2'
365LANGUAGE 'C' with (isstrict);
366
367CREATE FUNCTION tsvector_out(tsvector)
368RETURNS cstring
369AS '$libdir/tsearch2'
370LANGUAGE 'C' with (isstrict);
371
372CREATE TYPE tsvector (
373 INTERNALLENGTH = -1,
374 INPUT = tsvector_in,
375 OUTPUT = tsvector_out,
376 STORAGE = extended
377);
378
379CREATE FUNCTION length(tsvector)
380RETURNS int4
381AS '$libdir/tsearch2', 'tsvector_length'
382LANGUAGE 'C' with (isstrict,iscachable);
383
384CREATE FUNCTION to_tsvector(oid, text)
385RETURNS tsvector
386AS '$libdir/tsearch2'
387LANGUAGE 'C' with (isstrict,iscachable);
388
389CREATE FUNCTION to_tsvector(text, text)
390RETURNS tsvector
391AS '$libdir/tsearch2', 'to_tsvector_name'
392LANGUAGE 'C' with (isstrict,iscachable);
393
394CREATE FUNCTION to_tsvector(text)
395RETURNS tsvector
396AS '$libdir/tsearch2', 'to_tsvector_current'
397LANGUAGE 'C' with (isstrict,iscachable);
398
399CREATE FUNCTION strip(tsvector)
400RETURNS tsvector
401AS '$libdir/tsearch2'
402LANGUAGE 'C' with (isstrict,iscachable);
403
404CREATE FUNCTION setweight(tsvector,"char")
405RETURNS tsvector
406AS '$libdir/tsearch2'
407LANGUAGE 'C' with (isstrict,iscachable);
408
409CREATE FUNCTION concat(tsvector,tsvector)
410RETURNS tsvector
411AS '$libdir/tsearch2'
412LANGUAGE 'C' with (isstrict,iscachable);
413
414CREATE OPERATOR || (
415 LEFTARG = tsvector,
416 RIGHTARG = tsvector,
417 PROCEDURE = concat
418);
419
420--query type
421CREATE FUNCTION tsquery_in(cstring)
422RETURNS tsquery
423AS '$libdir/tsearch2'
424LANGUAGE 'C' with (isstrict);
425
426CREATE FUNCTION tsquery_out(tsquery)
427RETURNS cstring
428AS '$libdir/tsearch2'
429LANGUAGE 'C' with (isstrict);
430
431CREATE TYPE tsquery (
432 INTERNALLENGTH = -1,
433 INPUT = tsquery_in,
434 OUTPUT = tsquery_out
435);
436
437CREATE FUNCTION querytree(tsquery)
438RETURNS text
439AS '$libdir/tsearch2', 'tsquerytree'
440LANGUAGE 'C' with (isstrict);
441
442CREATE FUNCTION to_tsquery(oid, text)
443RETURNS tsquery
444AS '$libdir/tsearch2'
445LANGUAGE 'c' with (isstrict,iscachable);
446
447CREATE FUNCTION to_tsquery(text, text)
448RETURNS tsquery
449AS '$libdir/tsearch2','to_tsquery_name'
450LANGUAGE 'c' with (isstrict,iscachable);
451
452CREATE FUNCTION to_tsquery(text)
453RETURNS tsquery
454AS '$libdir/tsearch2','to_tsquery_current'
455LANGUAGE 'c' with (isstrict,iscachable);
456
457--operations
458CREATE FUNCTION exectsq(tsvector, tsquery)
459RETURNS bool
460AS '$libdir/tsearch2'
461LANGUAGE 'C' with (isstrict, iscachable);
462
463COMMENT ON FUNCTION exectsq(tsvector, tsquery) IS 'boolean operation with text index';
464
465CREATE FUNCTION rexectsq(tsquery, tsvector)
466RETURNS bool
467AS '$libdir/tsearch2'
468LANGUAGE 'C' with (isstrict, iscachable);
469
470COMMENT ON FUNCTION rexectsq(tsquery, tsvector) IS 'boolean operation with text index';
471
472CREATE OPERATOR @@ (
473 LEFTARG = tsvector,
474 RIGHTARG = tsquery,
475 PROCEDURE = exectsq,
476 COMMUTATOR = '@@',
477 RESTRICT = contsel,
478 JOIN = contjoinsel
479);
480CREATE OPERATOR @@ (
481 LEFTARG = tsquery,
482 RIGHTARG = tsvector,
483 PROCEDURE = rexectsq,
484 COMMUTATOR = '@@',
485 RESTRICT = contsel,
486 JOIN = contjoinsel
487);
488
489--Trigger
490CREATE FUNCTION tsearch2()
491RETURNS trigger
492AS '$libdir/tsearch2'
493LANGUAGE 'C';
494
495--Relevation
496CREATE FUNCTION rank(float4[], tsvector, tsquery)
497RETURNS float4
498AS '$libdir/tsearch2'
499LANGUAGE 'C' WITH (isstrict, iscachable);
500
501CREATE FUNCTION rank(float4[], tsvector, tsquery, int4)
502RETURNS float4
503AS '$libdir/tsearch2'
504LANGUAGE 'C' WITH (isstrict, iscachable);
505
506CREATE FUNCTION rank(tsvector, tsquery)
507RETURNS float4
508AS '$libdir/tsearch2', 'rank_def'
509LANGUAGE 'C' WITH (isstrict, iscachable);
510
511CREATE FUNCTION rank(tsvector, tsquery, int4)
512RETURNS float4
513AS '$libdir/tsearch2', 'rank_def'
514LANGUAGE 'C' WITH (isstrict, iscachable);
515
516CREATE FUNCTION rank_cd(int4, tsvector, tsquery)
517RETURNS float4
518AS '$libdir/tsearch2'
519LANGUAGE 'C' WITH (isstrict, iscachable);
520
521CREATE FUNCTION rank_cd(int4, tsvector, tsquery, int4)
522RETURNS float4
523AS '$libdir/tsearch2'
524LANGUAGE 'C' WITH (isstrict, iscachable);
525
526CREATE FUNCTION rank_cd(tsvector, tsquery)
527RETURNS float4
528AS '$libdir/tsearch2', 'rank_cd_def'
529LANGUAGE 'C' WITH (isstrict, iscachable);
530
531CREATE FUNCTION rank_cd(tsvector, tsquery, int4)
532RETURNS float4
533AS '$libdir/tsearch2', 'rank_cd_def'
534LANGUAGE 'C' WITH (isstrict, iscachable);
535
536CREATE FUNCTION headline(oid, text, tsquery, text)
537RETURNS text
538AS '$libdir/tsearch2', 'headline'
539LANGUAGE 'C' WITH (isstrict, iscachable);
540
541CREATE FUNCTION headline(oid, text, tsquery)
542RETURNS text
543AS '$libdir/tsearch2', 'headline'
544LANGUAGE 'C' WITH (isstrict, iscachable);
545
546CREATE FUNCTION headline(text, text, tsquery, text)
547RETURNS text
548AS '$libdir/tsearch2', 'headline_byname'
549LANGUAGE 'C' WITH (isstrict, iscachable);
550
551CREATE FUNCTION headline(text, text, tsquery)
552RETURNS text
553AS '$libdir/tsearch2', 'headline_byname'
554LANGUAGE 'C' WITH (isstrict, iscachable);
555
556CREATE FUNCTION headline(text, tsquery, text)
557RETURNS text
558AS '$libdir/tsearch2', 'headline_current'
559LANGUAGE 'C' WITH (isstrict, iscachable);
560
561CREATE FUNCTION headline(text, tsquery)
562RETURNS text
563AS '$libdir/tsearch2', 'headline_current'
564LANGUAGE 'C' WITH (isstrict, iscachable);
565
566--GiST
567--GiST key type
568CREATE FUNCTION gtsvector_in(cstring)
569RETURNS gtsvector
570AS '$libdir/tsearch2'
571LANGUAGE 'C' with (isstrict);
572
573CREATE FUNCTION gtsvector_out(gtsvector)
574RETURNS cstring
575AS '$libdir/tsearch2'
576LANGUAGE 'C' with (isstrict);
577
578CREATE TYPE gtsvector (
579 INTERNALLENGTH = -1,
580 INPUT = gtsvector_in,
581 OUTPUT = gtsvector_out
582);
583
584-- support FUNCTIONs
585CREATE FUNCTION gtsvector_consistent(gtsvector,internal,int4)
586RETURNS bool
587AS '$libdir/tsearch2'
588LANGUAGE 'C';
589
590CREATE FUNCTION gtsvector_compress(internal)
591RETURNS internal
592AS '$libdir/tsearch2'
593LANGUAGE 'C';
594
595CREATE FUNCTION gtsvector_decompress(internal)
596RETURNS internal
597AS '$libdir/tsearch2'
598LANGUAGE 'C';
599
600CREATE FUNCTION gtsvector_penalty(internal,internal,internal)
601RETURNS internal
602AS '$libdir/tsearch2'
603LANGUAGE 'C' with (isstrict);
604
605CREATE FUNCTION gtsvector_picksplit(internal, internal)
606RETURNS internal
607AS '$libdir/tsearch2'
608LANGUAGE 'C';
609
610CREATE FUNCTION gtsvector_union(bytea, internal)
611RETURNS _int4
612AS '$libdir/tsearch2'
613LANGUAGE 'C';
614
615CREATE FUNCTION gtsvector_same(gtsvector, gtsvector, internal)
616RETURNS internal
617AS '$libdir/tsearch2'
618LANGUAGE 'C';
619
620-- CREATE the OPERATOR class
621CREATE OPERATOR CLASS gist_tsvector_ops
622DEFAULT FOR TYPE tsvector USING gist
623AS
624 OPERATOR 1 @@ (tsvector, tsquery) RECHECK ,
625 FUNCTION 1 gtsvector_consistent (gtsvector, internal, int4),
626 FUNCTION 2 gtsvector_union (bytea, internal),
627 FUNCTION 3 gtsvector_compress (internal),
628 FUNCTION 4 gtsvector_decompress (internal),
629 FUNCTION 5 gtsvector_penalty (internal, internal, internal),
630 FUNCTION 6 gtsvector_picksplit (internal, internal),
631 FUNCTION 7 gtsvector_same (gtsvector, gtsvector, internal),
632 STORAGE gtsvector;
633
634
635--stat info
636CREATE TYPE statinfo
637 as (word text, ndoc int4, nentry int4);
638
639--CREATE FUNCTION tsstat_in(cstring)
640--RETURNS tsstat
641--AS '$libdir/tsearch2'
642--LANGUAGE 'C' with (isstrict);
643--
644--CREATE FUNCTION tsstat_out(tsstat)
645--RETURNS cstring
646--AS '$libdir/tsearch2'
647--LANGUAGE 'C' with (isstrict);
648--
649--CREATE TYPE tsstat (
650-- INTERNALLENGTH = -1,
651-- INPUT = tsstat_in,
652-- OUTPUT = tsstat_out,
653-- STORAGE = plain
654--);
655--
656--CREATE FUNCTION ts_accum(tsstat,tsvector)
657--RETURNS tsstat
658--AS '$libdir/tsearch2'
659--LANGUAGE 'C' with (isstrict);
660--
661--CREATE FUNCTION ts_accum_finish(tsstat)
662-- returns setof statinfo
663-- as '$libdir/tsearch2'
664-- language 'C'
665-- with (isstrict);
666--
667--CREATE AGGREGATE stat (
668-- BASETYPE=tsvector,
669-- SFUNC=ts_accum,
670-- STYPE=tsstat,
671-- FINALFUNC = ts_accum_finish,
672-- initcond = ''
673--);
674
675CREATE FUNCTION stat(text)
676 returns setof statinfo
677 as '$libdir/tsearch2', 'ts_stat'
678 language 'C'
679 with (isstrict);
680
681--reset - just for debuging
682CREATE FUNCTION reset_tsearch()
683 returns void
684 as '$libdir/tsearch2'
685 language 'C'
686 with (isstrict);
687
688--get cover (debug for rank_cd)
689CREATE FUNCTION get_covers(tsvector,tsquery)
690 returns text
691 as '$libdir/tsearch2'
692 language 'C'
693 with (isstrict);
694
695--debug function
696create type tsdebug as (
697 ts_name text,
698 tok_type text,
699 description text,
700 token text,
701 dict_name text[],
702 "tsvector" tsvector
703);
704
705create function _get_parser_from_curcfg()
706returns text as
707' select prs_name from pg_ts_cfg where oid = show_curcfg() '
708language 'SQL' with(isstrict,iscachable);
709
710create function ts_debug(text)
711returns setof tsdebug as '
712select
713 m.ts_name,
714 t.alias as tok_type,
715 t.descr as description,
716 p.token,
717 m.dict_name,
718 strip(to_tsvector(p.token)) as tsvector
719from
720 parse( _get_parser_from_curcfg(), $1 ) as p,
721 token_type() as t,
722 pg_ts_cfgmap as m,
723 pg_ts_cfg as c
724where
725 t.tokid=p.tokid and
726 t.alias = m.tok_alias and
727 m.ts_name=c.ts_name and
728 c.oid=show_curcfg()
729' language 'SQL' with(isstrict);
730"""
731
732def setup(cursor):
733 sql = '\n'.join([line for line in tsearch_sql.split('\n')
734 if not line.startswith('--')])
735 for query in sql.split(';'):
736 if query.strip():
737 cursor.execute(query)