Fix xslt_process() to ensure that it inserts a NULL terminator after the
[PostgreSQL.git] / contrib / tsearch2 / tsearch2.sql.in
blob41f5434e3b9b32b49aa33fac8aac8bcd599efd48
1 /* $PostgreSQL$ */
3 -- Adjust this setting to control where the objects get created.
4 SET search_path = public;
6 -- These domains are just to catch schema-qualified references to the
7 -- old data types.
8 CREATE DOMAIN tsvector AS pg_catalog.tsvector;
9 CREATE DOMAIN tsquery AS pg_catalog.tsquery;
10 CREATE DOMAIN gtsvector AS pg_catalog.gtsvector;
11 CREATE DOMAIN gtsq AS pg_catalog.text;
13 --dict interface
14 CREATE FUNCTION lexize(oid, text)
15 RETURNS _text
16 as 'ts_lexize'
17 LANGUAGE INTERNAL
18 RETURNS NULL ON NULL INPUT;
20 CREATE FUNCTION lexize(text, text)
21 RETURNS _text
22 as 'MODULE_PATHNAME', 'tsa_lexize_byname'
23 LANGUAGE C
24 RETURNS NULL ON NULL INPUT;
26 CREATE FUNCTION lexize(text)
27 RETURNS _text
28 as 'MODULE_PATHNAME', 'tsa_lexize_bycurrent'
29 LANGUAGE C
30 RETURNS NULL ON NULL INPUT;
32 CREATE FUNCTION set_curdict(int)
33 RETURNS void
34 as 'MODULE_PATHNAME', 'tsa_set_curdict'
35 LANGUAGE C
36 RETURNS NULL ON NULL INPUT;
38 CREATE FUNCTION set_curdict(text)
39 RETURNS void
40 as 'MODULE_PATHNAME', 'tsa_set_curdict_byname'
41 LANGUAGE C
42 RETURNS NULL ON NULL INPUT;
44 --built-in dictionaries
45 CREATE FUNCTION dex_init(internal)
46 RETURNS internal
47 as 'MODULE_PATHNAME', 'tsa_dex_init'
48 LANGUAGE C;
50 CREATE FUNCTION dex_lexize(internal,internal,int4)
51 RETURNS internal
52 as 'MODULE_PATHNAME', 'tsa_dex_lexize'
53 LANGUAGE C
54 RETURNS NULL ON NULL INPUT;
56 CREATE FUNCTION snb_en_init(internal)
57 RETURNS internal
58 as 'MODULE_PATHNAME', 'tsa_snb_en_init'
59 LANGUAGE C;
61 CREATE FUNCTION snb_lexize(internal,internal,int4)
62 RETURNS internal
63 as 'MODULE_PATHNAME', 'tsa_snb_lexize'
64 LANGUAGE C
65 RETURNS NULL ON NULL INPUT;
67 CREATE FUNCTION snb_ru_init_koi8(internal)
68 RETURNS internal
69 as 'MODULE_PATHNAME', 'tsa_snb_ru_init_koi8'
70 LANGUAGE C;
72 CREATE FUNCTION snb_ru_init_utf8(internal)
73 RETURNS internal
74 as 'MODULE_PATHNAME', 'tsa_snb_ru_init_utf8'
75 LANGUAGE C;
77 CREATE FUNCTION snb_ru_init(internal)
78 RETURNS internal
79 as 'MODULE_PATHNAME', 'tsa_snb_ru_init'
80 LANGUAGE C;
82 CREATE FUNCTION spell_init(internal)
83 RETURNS internal
84 as 'MODULE_PATHNAME', 'tsa_spell_init'
85 LANGUAGE C;
87 CREATE FUNCTION spell_lexize(internal,internal,int4)
88 RETURNS internal
89 as 'MODULE_PATHNAME', 'tsa_spell_lexize'
90 LANGUAGE C
91 RETURNS NULL ON NULL INPUT;
93 CREATE FUNCTION syn_init(internal)
94 RETURNS internal
95 as 'MODULE_PATHNAME', 'tsa_syn_init'
96 LANGUAGE C;
98 CREATE FUNCTION syn_lexize(internal,internal,int4)
99 RETURNS internal
100 as 'MODULE_PATHNAME', 'tsa_syn_lexize'
101 LANGUAGE C
102 RETURNS NULL ON NULL INPUT;
104 CREATE FUNCTION thesaurus_init(internal)
105 RETURNS internal
106 as 'MODULE_PATHNAME', 'tsa_thesaurus_init'
107 LANGUAGE C;
109 CREATE FUNCTION thesaurus_lexize(internal,internal,int4,internal)
110 RETURNS internal
111 as 'MODULE_PATHNAME', 'tsa_thesaurus_lexize'
112 LANGUAGE C
113 RETURNS NULL ON NULL INPUT;
115 --sql-level interface
116 CREATE TYPE tokentype
117 as (tokid int4, alias text, descr text);
119 CREATE FUNCTION token_type(int4)
120 RETURNS setof tokentype
121 as 'ts_token_type_byid'
122 LANGUAGE INTERNAL
123 RETURNS NULL ON NULL INPUT
124 ROWS 16;
126 CREATE FUNCTION token_type(text)
127 RETURNS setof tokentype
128 as 'ts_token_type_byname'
129 LANGUAGE INTERNAL
130 RETURNS NULL ON NULL INPUT
131 ROWS 16;
133 CREATE FUNCTION token_type()
134 RETURNS setof tokentype
135 as 'MODULE_PATHNAME', 'tsa_token_type_current'
136 LANGUAGE C
137 RETURNS NULL ON NULL INPUT
138 ROWS 16;
140 CREATE FUNCTION set_curprs(int)
141 RETURNS void
142 as 'MODULE_PATHNAME', 'tsa_set_curprs'
143 LANGUAGE C
144 RETURNS NULL ON NULL INPUT;
146 CREATE FUNCTION set_curprs(text)
147 RETURNS void
148 as 'MODULE_PATHNAME', 'tsa_set_curprs_byname'
149 LANGUAGE C
150 RETURNS NULL ON NULL INPUT;
152 CREATE TYPE tokenout
153 as (tokid int4, token text);
155 CREATE FUNCTION parse(oid,text)
156 RETURNS setof tokenout
157 as 'ts_parse_byid'
158 LANGUAGE INTERNAL
159 RETURNS NULL ON NULL INPUT;
161 CREATE FUNCTION parse(text,text)
162 RETURNS setof tokenout
163 as 'ts_parse_byname'
164 LANGUAGE INTERNAL
165 RETURNS NULL ON NULL INPUT;
167 CREATE FUNCTION parse(text)
168 RETURNS setof tokenout
169 as 'MODULE_PATHNAME', 'tsa_parse_current'
170 LANGUAGE C
171 RETURNS NULL ON NULL INPUT;
173 --default parser
174 CREATE FUNCTION prsd_start(internal,int4)
175 RETURNS internal
176 as 'MODULE_PATHNAME', 'tsa_prsd_start'
177 LANGUAGE C;
179 CREATE FUNCTION prsd_getlexeme(internal,internal,internal)
180 RETURNS int4
181 as 'MODULE_PATHNAME', 'tsa_prsd_getlexeme'
182 LANGUAGE C;
184 CREATE FUNCTION prsd_end(internal)
185 RETURNS void
186 as 'MODULE_PATHNAME', 'tsa_prsd_end'
187 LANGUAGE C;
189 CREATE FUNCTION prsd_lextype(internal)
190 RETURNS internal
191 as 'MODULE_PATHNAME', 'tsa_prsd_lextype'
192 LANGUAGE C;
194 CREATE FUNCTION prsd_headline(internal,internal,internal)
195 RETURNS internal
196 as 'MODULE_PATHNAME', 'tsa_prsd_headline'
197 LANGUAGE C;
199 --tsearch config
200 CREATE FUNCTION set_curcfg(int)
201 RETURNS void
202 as 'MODULE_PATHNAME', 'tsa_set_curcfg'
203 LANGUAGE C
204 RETURNS NULL ON NULL INPUT;
206 CREATE FUNCTION set_curcfg(text)
207 RETURNS void
208 as 'MODULE_PATHNAME', 'tsa_set_curcfg_byname'
209 LANGUAGE C
210 RETURNS NULL ON NULL INPUT;
212 CREATE FUNCTION show_curcfg()
213 RETURNS oid
214 AS 'get_current_ts_config'
215 LANGUAGE INTERNAL
216 RETURNS NULL ON NULL INPUT STABLE;
218 CREATE FUNCTION length(tsvector)
219 RETURNS int4
220 AS 'tsvector_length'
221 LANGUAGE INTERNAL
222 RETURNS NULL ON NULL INPUT IMMUTABLE;
224 CREATE FUNCTION to_tsvector(oid, text)
225 RETURNS tsvector
226 AS 'to_tsvector_byid'
227 LANGUAGE INTERNAL
228 RETURNS NULL ON NULL INPUT IMMUTABLE;
230 CREATE FUNCTION to_tsvector(text, text)
231 RETURNS tsvector
232 AS 'MODULE_PATHNAME', 'tsa_to_tsvector_name'
233 LANGUAGE C RETURNS NULL ON NULL INPUT IMMUTABLE;
235 CREATE FUNCTION to_tsvector(text)
236 RETURNS tsvector
237 AS 'to_tsvector'
238 LANGUAGE INTERNAL
239 RETURNS NULL ON NULL INPUT IMMUTABLE;
241 CREATE FUNCTION strip(tsvector)
242 RETURNS tsvector
243 AS 'tsvector_strip'
244 LANGUAGE INTERNAL
245 RETURNS NULL ON NULL INPUT IMMUTABLE;
247 CREATE FUNCTION setweight(tsvector,"char")
248 RETURNS tsvector
249 AS 'tsvector_setweight'
250 LANGUAGE INTERNAL
251 RETURNS NULL ON NULL INPUT IMMUTABLE;
253 CREATE FUNCTION concat(tsvector,tsvector)
254 RETURNS tsvector
255 AS 'tsvector_concat'
256 LANGUAGE INTERNAL
257 RETURNS NULL ON NULL INPUT IMMUTABLE;
259 CREATE FUNCTION querytree(tsquery)
260 RETURNS text
261 AS 'tsquerytree'
262 LANGUAGE INTERNAL RETURNS NULL ON NULL INPUT;
264 CREATE FUNCTION to_tsquery(oid, text)
265 RETURNS tsquery
266 AS 'to_tsquery_byid'
267 LANGUAGE INTERNAL
268 RETURNS NULL ON NULL INPUT IMMUTABLE;
270 CREATE FUNCTION to_tsquery(text, text)
271 RETURNS tsquery
272 AS 'MODULE_PATHNAME','tsa_to_tsquery_name'
273 LANGUAGE C RETURNS NULL ON NULL INPUT IMMUTABLE;
275 CREATE FUNCTION to_tsquery(text)
276 RETURNS tsquery
277 AS 'to_tsquery'
278 LANGUAGE INTERNAL
279 RETURNS NULL ON NULL INPUT IMMUTABLE;
281 CREATE FUNCTION plainto_tsquery(oid, text)
282 RETURNS tsquery
283 AS 'plainto_tsquery_byid'
284 LANGUAGE INTERNAL
285 RETURNS NULL ON NULL INPUT IMMUTABLE;
287 CREATE FUNCTION plainto_tsquery(text, text)
288 RETURNS tsquery
289 AS 'MODULE_PATHNAME','tsa_plainto_tsquery_name'
290 LANGUAGE C RETURNS NULL ON NULL INPUT IMMUTABLE;
292 CREATE FUNCTION plainto_tsquery(text)
293 RETURNS tsquery
294 AS 'plainto_tsquery'
295 LANGUAGE INTERNAL
296 RETURNS NULL ON NULL INPUT IMMUTABLE;
298 --Trigger
299 CREATE FUNCTION tsearch2()
300 RETURNS trigger
301 AS 'MODULE_PATHNAME', 'tsa_tsearch2'
302 LANGUAGE C;
304 --Relevation
305 CREATE FUNCTION rank(float4[], tsvector, tsquery)
306 RETURNS float4
307 AS 'ts_rank_wtt'
308 LANGUAGE INTERNAL
309 RETURNS NULL ON NULL INPUT IMMUTABLE;
311 CREATE FUNCTION rank(float4[], tsvector, tsquery, int4)
312 RETURNS float4
313 AS 'ts_rank_wttf'
314 LANGUAGE INTERNAL
315 RETURNS NULL ON NULL INPUT IMMUTABLE;
317 CREATE FUNCTION rank(tsvector, tsquery)
318 RETURNS float4
319 AS 'ts_rank_tt'
320 LANGUAGE INTERNAL
321 RETURNS NULL ON NULL INPUT IMMUTABLE;
323 CREATE FUNCTION rank(tsvector, tsquery, int4)
324 RETURNS float4
325 AS 'ts_rank_ttf'
326 LANGUAGE INTERNAL
327 RETURNS NULL ON NULL INPUT IMMUTABLE;
329 CREATE FUNCTION rank_cd(float4[], tsvector, tsquery)
330 RETURNS float4
331 AS 'ts_rankcd_wtt'
332 LANGUAGE INTERNAL
333 RETURNS NULL ON NULL INPUT IMMUTABLE;
335 CREATE FUNCTION rank_cd(float4[], tsvector, tsquery, int4)
336 RETURNS float4
337 AS 'ts_rankcd_wttf'
338 LANGUAGE INTERNAL
339 RETURNS NULL ON NULL INPUT IMMUTABLE;
341 CREATE FUNCTION rank_cd(tsvector, tsquery)
342 RETURNS float4
343 AS 'ts_rankcd_tt'
344 LANGUAGE INTERNAL
345 RETURNS NULL ON NULL INPUT IMMUTABLE;
347 CREATE FUNCTION rank_cd(tsvector, tsquery, int4)
348 RETURNS float4
349 AS 'ts_rankcd_ttf'
350 LANGUAGE INTERNAL
351 RETURNS NULL ON NULL INPUT IMMUTABLE;
353 CREATE FUNCTION headline(oid, text, tsquery, text)
354 RETURNS text
355 AS 'ts_headline_byid_opt'
356 LANGUAGE INTERNAL
357 RETURNS NULL ON NULL INPUT IMMUTABLE;
359 CREATE FUNCTION headline(oid, text, tsquery)
360 RETURNS text
361 AS 'ts_headline_byid'
362 LANGUAGE INTERNAL
363 RETURNS NULL ON NULL INPUT IMMUTABLE;
365 CREATE FUNCTION headline(text, text, tsquery, text)
366 RETURNS text
367 AS 'MODULE_PATHNAME', 'tsa_headline_byname'
368 LANGUAGE C RETURNS NULL ON NULL INPUT IMMUTABLE;
370 CREATE FUNCTION headline(text, text, tsquery)
371 RETURNS text
372 AS 'MODULE_PATHNAME', 'tsa_headline_byname'
373 LANGUAGE C RETURNS NULL ON NULL INPUT IMMUTABLE;
375 CREATE FUNCTION headline(text, tsquery, text)
376 RETURNS text
377 AS 'ts_headline_opt'
378 LANGUAGE INTERNAL
379 RETURNS NULL ON NULL INPUT IMMUTABLE;
381 CREATE FUNCTION headline(text, tsquery)
382 RETURNS text
383 AS 'ts_headline'
384 LANGUAGE INTERNAL
385 RETURNS NULL ON NULL INPUT IMMUTABLE;
387 -- CREATE the OPERATOR class
388 CREATE OPERATOR CLASS gist_tsvector_ops
389 FOR TYPE tsvector USING gist
391 OPERATOR 1 @@ (tsvector, tsquery),
392 FUNCTION 1 gtsvector_consistent (internal, gtsvector, int, oid, internal),
393 FUNCTION 2 gtsvector_union (internal, internal),
394 FUNCTION 3 gtsvector_compress (internal),
395 FUNCTION 4 gtsvector_decompress (internal),
396 FUNCTION 5 gtsvector_penalty (internal, internal, internal),
397 FUNCTION 6 gtsvector_picksplit (internal, internal),
398 FUNCTION 7 gtsvector_same (gtsvector, gtsvector, internal),
399 STORAGE gtsvector;
401 --stat info
402 CREATE TYPE statinfo
403 as (word text, ndoc int4, nentry int4);
405 CREATE FUNCTION stat(text)
406 RETURNS setof statinfo
407 as 'ts_stat1'
408 LANGUAGE INTERNAL
409 RETURNS NULL ON NULL INPUT;
411 CREATE FUNCTION stat(text,text)
412 RETURNS setof statinfo
413 as 'ts_stat2'
414 LANGUAGE INTERNAL
415 RETURNS NULL ON NULL INPUT;
417 --reset - just for debuging
418 CREATE FUNCTION reset_tsearch()
419 RETURNS void
420 as 'MODULE_PATHNAME', 'tsa_reset_tsearch'
421 LANGUAGE C
422 RETURNS NULL ON NULL INPUT;
424 --get cover (debug for rank_cd)
425 CREATE FUNCTION get_covers(tsvector,tsquery)
426 RETURNS text
427 as 'MODULE_PATHNAME', 'tsa_get_covers'
428 LANGUAGE C
429 RETURNS NULL ON NULL INPUT;
431 --debug function
432 create type tsdebug as (
433 ts_name text,
434 tok_type text,
435 description text,
436 token text,
437 dict_name text[],
438 "tsvector" tsvector
441 CREATE or replace FUNCTION _get_parser_from_curcfg()
442 RETURNS text as
443 $$select prsname::text from pg_catalog.pg_ts_parser p join pg_ts_config c on cfgparser = p.oid where c.oid = show_curcfg();$$
444 LANGUAGE SQL RETURNS NULL ON NULL INPUT IMMUTABLE;
446 CREATE FUNCTION ts_debug(text)
447 RETURNS setof tsdebug as $$
448 select
449 (select c.cfgname::text from pg_catalog.pg_ts_config as c
450 where c.oid = show_curcfg()),
451 t.alias as tok_type,
452 t.descr as description,
453 p.token,
454 ARRAY ( SELECT m.mapdict::pg_catalog.regdictionary::pg_catalog.text
455 FROM pg_catalog.pg_ts_config_map AS m
456 WHERE m.mapcfg = show_curcfg() AND m.maptokentype = p.tokid
457 ORDER BY m.mapseqno )
458 AS dict_name,
459 strip(to_tsvector(p.token)) as tsvector
460 from
461 parse( _get_parser_from_curcfg(), $1 ) as p,
462 token_type() as t
463 where
464 t.tokid = p.tokid
465 $$ LANGUAGE SQL RETURNS NULL ON NULL INPUT;
467 CREATE OR REPLACE FUNCTION numnode(tsquery)
468 RETURNS int4
469 as 'tsquery_numnode'
470 LANGUAGE INTERNAL
471 RETURNS NULL ON NULL INPUT IMMUTABLE;
473 CREATE OR REPLACE FUNCTION tsquery_and(tsquery,tsquery)
474 RETURNS tsquery
475 as 'tsquery_and'
476 LANGUAGE INTERNAL
477 RETURNS NULL ON NULL INPUT IMMUTABLE;
479 CREATE OR REPLACE FUNCTION tsquery_or(tsquery,tsquery)
480 RETURNS tsquery
481 as 'tsquery_or'
482 LANGUAGE INTERNAL
483 RETURNS NULL ON NULL INPUT IMMUTABLE;
485 CREATE OR REPLACE FUNCTION tsquery_not(tsquery)
486 RETURNS tsquery
487 as 'tsquery_not'
488 LANGUAGE INTERNAL
489 RETURNS NULL ON NULL INPUT IMMUTABLE;
491 --------------rewrite subsystem
493 CREATE OR REPLACE FUNCTION rewrite(tsquery, text)
494 RETURNS tsquery
495 as 'tsquery_rewrite_query'
496 LANGUAGE INTERNAL
497 RETURNS NULL ON NULL INPUT IMMUTABLE;
499 CREATE OR REPLACE FUNCTION rewrite(tsquery, tsquery, tsquery)
500 RETURNS tsquery
501 as 'tsquery_rewrite'
502 LANGUAGE INTERNAL
503 RETURNS NULL ON NULL INPUT IMMUTABLE;
505 CREATE OR REPLACE FUNCTION rewrite_accum(tsquery,tsquery[])
506 RETURNS tsquery
507 AS 'MODULE_PATHNAME', 'tsa_rewrite_accum'
508 LANGUAGE C;
510 CREATE OR REPLACE FUNCTION rewrite_finish(tsquery)
511 RETURNS tsquery
512 as 'MODULE_PATHNAME', 'tsa_rewrite_finish'
513 LANGUAGE C;
515 CREATE AGGREGATE rewrite (
516 BASETYPE = tsquery[],
517 SFUNC = rewrite_accum,
518 STYPE = tsquery,
519 FINALFUNC = rewrite_finish
522 CREATE OR REPLACE FUNCTION tsq_mcontains(tsquery, tsquery)
523 RETURNS bool
524 as 'tsq_mcontains'
525 LANGUAGE INTERNAL
526 RETURNS NULL ON NULL INPUT IMMUTABLE;
528 CREATE OR REPLACE FUNCTION tsq_mcontained(tsquery, tsquery)
529 RETURNS bool
530 as 'tsq_mcontained'
531 LANGUAGE INTERNAL
532 RETURNS NULL ON NULL INPUT IMMUTABLE;
534 CREATE OPERATOR CLASS gist_tp_tsquery_ops
535 FOR TYPE tsquery USING gist
537 OPERATOR 7 @> (tsquery, tsquery),
538 OPERATOR 8 <@ (tsquery, tsquery),
539 FUNCTION 1 gtsquery_consistent (internal, internal, int, oid, internal),
540 FUNCTION 2 gtsquery_union (internal, internal),
541 FUNCTION 3 gtsquery_compress (internal),
542 FUNCTION 4 gtsquery_decompress (internal),
543 FUNCTION 5 gtsquery_penalty (internal, internal, internal),
544 FUNCTION 6 gtsquery_picksplit (internal, internal),
545 FUNCTION 7 gtsquery_same (bigint, bigint, internal),
546 STORAGE bigint;
548 CREATE OPERATOR CLASS gin_tsvector_ops
549 FOR TYPE tsvector USING gin
551 OPERATOR 1 @@ (tsvector, tsquery),
552 OPERATOR 2 @@@ (tsvector, tsquery),
553 FUNCTION 1 bttextcmp(text, text),
554 FUNCTION 2 gin_extract_tsvector(tsvector,internal),
555 FUNCTION 3 gin_extract_tsquery(tsquery,internal,smallint,internal,internal),
556 FUNCTION 4 gin_tsquery_consistent(internal,smallint,tsquery,int,internal,internal),
557 FUNCTION 5 gin_cmp_prefix(text,text,smallint,internal),
558 STORAGE text;
560 CREATE OPERATOR CLASS tsvector_ops
561 FOR TYPE tsvector USING btree AS
562 OPERATOR 1 < ,
563 OPERATOR 2 <= ,
564 OPERATOR 3 = ,
565 OPERATOR 4 >= ,
566 OPERATOR 5 > ,
567 FUNCTION 1 tsvector_cmp(tsvector, tsvector);
569 CREATE OPERATOR CLASS tsquery_ops
570 FOR TYPE tsquery USING btree AS
571 OPERATOR 1 < ,
572 OPERATOR 2 <= ,
573 OPERATOR 3 = ,
574 OPERATOR 4 >= ,
575 OPERATOR 5 > ,
576 FUNCTION 1 tsquery_cmp(tsquery, tsquery);