1 | DROP SCHEMA tsearch2 CASCADE; |
---|
2 | |
---|
3 | CREATE SCHEMA tsearch2; |
---|
4 | GRANT ALL ON SCHEMA tsearch2 TO public; |
---|
5 | COMMENT ON SCHEMA tsearch2 IS 'TSearch2 objects'; |
---|
6 | |
---|
7 | -- Adjust this setting to control where the objects get CREATEd. |
---|
8 | SET search_path = tsearch2; |
---|
9 | |
---|
10 | BEGIN; |
---|
11 | |
---|
12 | --dict conf |
---|
13 | CREATE TABLE pg_ts_dict ( |
---|
14 | dict_name text not null primary key, |
---|
15 | dict_init regprocedure, |
---|
16 | dict_initoption text, |
---|
17 | dict_lexize regprocedure not null, |
---|
18 | dict_comment text |
---|
19 | ) with oids; |
---|
20 | GRANT ALL ON pg_ts_dict TO public; |
---|
21 | |
---|
22 | --dict interface |
---|
23 | CREATE FUNCTION lexize(oid, text) |
---|
24 | returns _text |
---|
25 | as '$libdir/tsearch2' |
---|
26 | language 'C' |
---|
27 | with (isstrict); |
---|
28 | |
---|
29 | CREATE FUNCTION lexize(text, text) |
---|
30 | returns _text |
---|
31 | as '$libdir/tsearch2', 'lexize_byname' |
---|
32 | language 'C' |
---|
33 | with (isstrict); |
---|
34 | |
---|
35 | CREATE FUNCTION lexize(text) |
---|
36 | returns _text |
---|
37 | as '$libdir/tsearch2', 'lexize_bycurrent' |
---|
38 | language 'C' |
---|
39 | with (isstrict); |
---|
40 | |
---|
41 | CREATE FUNCTION set_curdict(int) |
---|
42 | returns void |
---|
43 | as '$libdir/tsearch2' |
---|
44 | language 'C' |
---|
45 | with (isstrict); |
---|
46 | |
---|
47 | CREATE FUNCTION set_curdict(text) |
---|
48 | returns void |
---|
49 | as '$libdir/tsearch2', 'set_curdict_byname' |
---|
50 | language 'C' |
---|
51 | with (isstrict); |
---|
52 | |
---|
53 | --built-in dictionaries |
---|
54 | CREATE FUNCTION dex_init(internal) |
---|
55 | returns internal |
---|
56 | as '$libdir/tsearch2' |
---|
57 | language 'C'; |
---|
58 | |
---|
59 | CREATE FUNCTION dex_lexize(internal,internal,int4) |
---|
60 | returns internal |
---|
61 | as '$libdir/tsearch2' |
---|
62 | language 'C' |
---|
63 | with (isstrict); |
---|
64 | |
---|
65 | insert into pg_ts_dict select |
---|
66 | 'simple', |
---|
67 | 'dex_init(internal)', |
---|
68 | null, |
---|
69 | 'dex_lexize(internal,internal,int4)', |
---|
70 | 'Simple example of dictionary.' |
---|
71 | ; |
---|
72 | |
---|
73 | CREATE FUNCTION snb_en_init(internal) |
---|
74 | returns internal |
---|
75 | as '$libdir/tsearch2' |
---|
76 | language 'C'; |
---|
77 | |
---|
78 | CREATE FUNCTION snb_lexize(internal,internal,int4) |
---|
79 | returns internal |
---|
80 | as '$libdir/tsearch2' |
---|
81 | language 'C' |
---|
82 | with (isstrict); |
---|
83 | |
---|
84 | insert into pg_ts_dict select |
---|
85 | 'en_stem', |
---|
86 | 'snb_en_init(internal)', |
---|
87 | 'contrib/english.stop', |
---|
88 | 'snb_lexize(internal,internal,int4)', |
---|
89 | 'English Stemmer. Snowball.' |
---|
90 | ; |
---|
91 | |
---|
92 | CREATE FUNCTION spell_init(internal) |
---|
93 | returns internal |
---|
94 | as '$libdir/tsearch2' |
---|
95 | language 'C'; |
---|
96 | |
---|
97 | CREATE FUNCTION spell_lexize(internal,internal,int4) |
---|
98 | returns internal |
---|
99 | as '$libdir/tsearch2' |
---|
100 | language 'C' |
---|
101 | with (isstrict); |
---|
102 | |
---|
103 | insert into pg_ts_dict select |
---|
104 | 'ispell_template', |
---|
105 | 'spell_init(internal)', |
---|
106 | null, |
---|
107 | 'spell_lexize(internal,internal,int4)', |
---|
108 | 'ISpell interface. Must have .dict and .aff files' |
---|
109 | ; |
---|
110 | |
---|
111 | CREATE FUNCTION syn_init(internal) |
---|
112 | returns internal |
---|
113 | as '$libdir/tsearch2' |
---|
114 | language 'C'; |
---|
115 | |
---|
116 | CREATE FUNCTION syn_lexize(internal,internal,int4) |
---|
117 | returns internal |
---|
118 | as '$libdir/tsearch2' |
---|
119 | language 'C' |
---|
120 | with (isstrict); |
---|
121 | |
---|
122 | insert into pg_ts_dict select |
---|
123 | 'synonym', |
---|
124 | 'syn_init(internal)', |
---|
125 | null, |
---|
126 | 'syn_lexize(internal,internal,int4)', |
---|
127 | 'Example of synonym dictionary' |
---|
128 | ; |
---|
129 | |
---|
130 | --dict conf |
---|
131 | CREATE TABLE pg_ts_parser ( |
---|
132 | prs_name text not null primary key, |
---|
133 | prs_start regprocedure not null, |
---|
134 | prs_nexttoken regprocedure not null, |
---|
135 | prs_end regprocedure not null, |
---|
136 | prs_headline regprocedure not null, |
---|
137 | prs_lextype regprocedure not null, |
---|
138 | prs_comment text |
---|
139 | ) with oids; |
---|
140 | GRANT ALL ON pg_ts_parser TO public; |
---|
141 | |
---|
142 | --sql-level interface |
---|
143 | CREATE TYPE tokentype |
---|
144 | as (tokid int4, alias text, descr text); |
---|
145 | |
---|
146 | CREATE FUNCTION token_type(int4) |
---|
147 | returns setof tokentype |
---|
148 | as '$libdir/tsearch2' |
---|
149 | language 'C' |
---|
150 | with (isstrict); |
---|
151 | |
---|
152 | CREATE FUNCTION token_type(text) |
---|
153 | returns setof tokentype |
---|
154 | as '$libdir/tsearch2', 'token_type_byname' |
---|
155 | language 'C' |
---|
156 | with (isstrict); |
---|
157 | |
---|
158 | CREATE FUNCTION token_type() |
---|
159 | returns setof tokentype |
---|
160 | as '$libdir/tsearch2', 'token_type_current' |
---|
161 | language 'C' |
---|
162 | with (isstrict); |
---|
163 | |
---|
164 | CREATE FUNCTION set_curprs(int) |
---|
165 | returns void |
---|
166 | as '$libdir/tsearch2' |
---|
167 | language 'C' |
---|
168 | with (isstrict); |
---|
169 | |
---|
170 | CREATE FUNCTION set_curprs(text) |
---|
171 | returns void |
---|
172 | as '$libdir/tsearch2', 'set_curprs_byname' |
---|
173 | language 'C' |
---|
174 | with (isstrict); |
---|
175 | |
---|
176 | CREATE TYPE tokenout |
---|
177 | as (tokid int4, token text); |
---|
178 | |
---|
179 | CREATE FUNCTION parse(oid,text) |
---|
180 | returns setof tokenout |
---|
181 | as '$libdir/tsearch2' |
---|
182 | language 'C' |
---|
183 | with (isstrict); |
---|
184 | |
---|
185 | CREATE FUNCTION parse(text,text) |
---|
186 | returns setof tokenout |
---|
187 | as '$libdir/tsearch2', 'parse_byname' |
---|
188 | language 'C' |
---|
189 | with (isstrict); |
---|
190 | |
---|
191 | CREATE FUNCTION parse(text) |
---|
192 | returns setof tokenout |
---|
193 | as '$libdir/tsearch2', 'parse_current' |
---|
194 | language 'C' |
---|
195 | with (isstrict); |
---|
196 | |
---|
197 | --default parser |
---|
198 | CREATE FUNCTION prsd_start(internal,int4) |
---|
199 | returns internal |
---|
200 | as '$libdir/tsearch2' |
---|
201 | language 'C'; |
---|
202 | |
---|
203 | CREATE FUNCTION prsd_getlexeme(internal,internal,internal) |
---|
204 | returns int4 |
---|
205 | as '$libdir/tsearch2' |
---|
206 | language 'C'; |
---|
207 | |
---|
208 | CREATE FUNCTION prsd_end(internal) |
---|
209 | returns void |
---|
210 | as '$libdir/tsearch2' |
---|
211 | language 'C'; |
---|
212 | |
---|
213 | CREATE FUNCTION prsd_lextype(internal) |
---|
214 | returns internal |
---|
215 | as '$libdir/tsearch2' |
---|
216 | language 'C'; |
---|
217 | |
---|
218 | CREATE FUNCTION prsd_headline(internal,internal,internal) |
---|
219 | returns internal |
---|
220 | as '$libdir/tsearch2' |
---|
221 | language 'C'; |
---|
222 | |
---|
223 | insert into pg_ts_parser select |
---|
224 | 'default', |
---|
225 | 'prsd_start(internal,int4)', |
---|
226 | 'prsd_getlexeme(internal,internal,internal)', |
---|
227 | 'prsd_end(internal)', |
---|
228 | 'prsd_headline(internal,internal,internal)', |
---|
229 | 'prsd_lextype(internal)', |
---|
230 | 'Parser from OpenFTS v0.34' |
---|
231 | ; |
---|
232 | |
---|
233 | --tsearch config |
---|
234 | |
---|
235 | CREATE TABLE pg_ts_cfg ( |
---|
236 | ts_name text not null primary key, |
---|
237 | prs_name text not null, |
---|
238 | locale text |
---|
239 | ) with oids; |
---|
240 | GRANT ALL ON pg_ts_cfg TO public; |
---|
241 | |
---|
242 | CREATE TABLE pg_ts_cfgmap ( |
---|
243 | ts_name text not null, |
---|
244 | tok_alias text not null, |
---|
245 | dict_name text[], |
---|
246 | primary key (ts_name,tok_alias) |
---|
247 | ) with oids; |
---|
248 | GRANT ALL ON pg_ts_cfgmap TO public; |
---|
249 | |
---|
250 | CREATE FUNCTION set_curcfg(int) |
---|
251 | returns void |
---|
252 | as '$libdir/tsearch2' |
---|
253 | language 'C' |
---|
254 | with (isstrict); |
---|
255 | |
---|
256 | CREATE FUNCTION set_curcfg(text) |
---|
257 | returns void |
---|
258 | as '$libdir/tsearch2', 'set_curcfg_byname' |
---|
259 | language 'C' |
---|
260 | with (isstrict); |
---|
261 | |
---|
262 | CREATE FUNCTION show_curcfg() |
---|
263 | returns oid |
---|
264 | as '$libdir/tsearch2' |
---|
265 | language 'C' |
---|
266 | with (isstrict); |
---|
267 | |
---|
268 | insert into pg_ts_cfg values ('default', 'default','C'); |
---|
269 | insert into pg_ts_cfg values ('simple', 'default'); |
---|
270 | |
---|
271 | insert into pg_ts_cfgmap values ('default', 'lword', '{en_stem}'); |
---|
272 | insert into pg_ts_cfgmap values ('default', 'nlword', '{simple}'); |
---|
273 | insert into pg_ts_cfgmap values ('default', 'word', '{simple}'); |
---|
274 | insert into pg_ts_cfgmap values ('default', 'email', '{simple}'); |
---|
275 | insert into pg_ts_cfgmap values ('default', 'url', '{simple}'); |
---|
276 | insert into pg_ts_cfgmap values ('default', 'host', '{simple}'); |
---|
277 | insert into pg_ts_cfgmap values ('default', 'sfloat', '{simple}'); |
---|
278 | insert into pg_ts_cfgmap values ('default', 'version', '{simple}'); |
---|
279 | insert into pg_ts_cfgmap values ('default', 'part_hword', '{simple}'); |
---|
280 | insert into pg_ts_cfgmap values ('default', 'nlpart_hword', '{simple}'); |
---|
281 | insert into pg_ts_cfgmap values ('default', 'lpart_hword', '{en_stem}'); |
---|
282 | insert into pg_ts_cfgmap values ('default', 'hword', '{simple}'); |
---|
283 | insert into pg_ts_cfgmap values ('default', 'lhword', '{en_stem}'); |
---|
284 | insert into pg_ts_cfgmap values ('default', 'nlhword', '{simple}'); |
---|
285 | insert into pg_ts_cfgmap values ('default', 'uri', '{simple}'); |
---|
286 | insert into pg_ts_cfgmap values ('default', 'file', '{simple}'); |
---|
287 | insert into pg_ts_cfgmap values ('default', 'float', '{simple}'); |
---|
288 | insert into pg_ts_cfgmap values ('default', 'int', '{simple}'); |
---|
289 | insert into pg_ts_cfgmap values ('default', 'uint', '{simple}'); |
---|
290 | insert into pg_ts_cfgmap values ('simple', 'lword', '{simple}'); |
---|
291 | insert into pg_ts_cfgmap values ('simple', 'nlword', '{simple}'); |
---|
292 | insert into pg_ts_cfgmap values ('simple', 'word', '{simple}'); |
---|
293 | insert into pg_ts_cfgmap values ('simple', 'email', '{simple}'); |
---|
294 | insert into pg_ts_cfgmap values ('simple', 'url', '{simple}'); |
---|
295 | insert into pg_ts_cfgmap values ('simple', 'host', '{simple}'); |
---|
296 | insert into pg_ts_cfgmap values ('simple', 'sfloat', '{simple}'); |
---|
297 | insert into pg_ts_cfgmap values ('simple', 'version', '{simple}'); |
---|
298 | insert into pg_ts_cfgmap values ('simple', 'part_hword', '{simple}'); |
---|
299 | insert into pg_ts_cfgmap values ('simple', 'nlpart_hword', '{simple}'); |
---|
300 | insert into pg_ts_cfgmap values ('simple', 'lpart_hword', '{simple}'); |
---|
301 | insert into pg_ts_cfgmap values ('simple', 'hword', '{simple}'); |
---|
302 | insert into pg_ts_cfgmap values ('simple', 'lhword', '{simple}'); |
---|
303 | insert into pg_ts_cfgmap values ('simple', 'nlhword', '{simple}'); |
---|
304 | insert into pg_ts_cfgmap values ('simple', 'uri', '{simple}'); |
---|
305 | insert into pg_ts_cfgmap values ('simple', 'file', '{simple}'); |
---|
306 | insert into pg_ts_cfgmap values ('simple', 'float', '{simple}'); |
---|
307 | insert into pg_ts_cfgmap values ('simple', 'int', '{simple}'); |
---|
308 | insert into pg_ts_cfgmap values ('simple', 'uint', '{simple}'); |
---|
309 | |
---|
310 | --tsvector type |
---|
311 | CREATE FUNCTION tsvector_in(cstring) |
---|
312 | RETURNS tsvector |
---|
313 | AS '$libdir/tsearch2' |
---|
314 | LANGUAGE 'C' with (isstrict); |
---|
315 | |
---|
316 | CREATE FUNCTION tsvector_out(tsvector) |
---|
317 | RETURNS cstring |
---|
318 | AS '$libdir/tsearch2' |
---|
319 | LANGUAGE 'C' with (isstrict); |
---|
320 | |
---|
321 | CREATE TYPE tsvector ( |
---|
322 | INTERNALLENGTH = -1, |
---|
323 | INPUT = tsvector_in, |
---|
324 | OUTPUT = tsvector_out, |
---|
325 | STORAGE = extended |
---|
326 | ); |
---|
327 | |
---|
328 | CREATE FUNCTION length(tsvector) |
---|
329 | RETURNS int4 |
---|
330 | AS '$libdir/tsearch2', 'tsvector_length' |
---|
331 | LANGUAGE 'C' with (isstrict,iscachable); |
---|
332 | |
---|
333 | CREATE FUNCTION to_tsvector(oid, text) |
---|
334 | RETURNS tsvector |
---|
335 | AS '$libdir/tsearch2' |
---|
336 | LANGUAGE 'C' with (isstrict,iscachable); |
---|
337 | |
---|
338 | CREATE FUNCTION to_tsvector(text, text) |
---|
339 | RETURNS tsvector |
---|
340 | AS '$libdir/tsearch2', 'to_tsvector_name' |
---|
341 | LANGUAGE 'C' with (isstrict,iscachable); |
---|
342 | |
---|
343 | CREATE FUNCTION to_tsvector(text) |
---|
344 | RETURNS tsvector |
---|
345 | AS '$libdir/tsearch2', 'to_tsvector_current' |
---|
346 | LANGUAGE 'C' with (isstrict,iscachable); |
---|
347 | |
---|
348 | CREATE FUNCTION strip(tsvector) |
---|
349 | RETURNS tsvector |
---|
350 | AS '$libdir/tsearch2' |
---|
351 | LANGUAGE 'C' with (isstrict,iscachable); |
---|
352 | |
---|
353 | CREATE FUNCTION setweight(tsvector,"char") |
---|
354 | RETURNS tsvector |
---|
355 | AS '$libdir/tsearch2' |
---|
356 | LANGUAGE 'C' with (isstrict,iscachable); |
---|
357 | |
---|
358 | CREATE FUNCTION concat(tsvector,tsvector) |
---|
359 | RETURNS tsvector |
---|
360 | AS '$libdir/tsearch2' |
---|
361 | LANGUAGE 'C' with (isstrict,iscachable); |
---|
362 | |
---|
363 | CREATE OPERATOR || ( |
---|
364 | LEFTARG = tsvector, |
---|
365 | RIGHTARG = tsvector, |
---|
366 | PROCEDURE = concat |
---|
367 | ); |
---|
368 | |
---|
369 | --query type |
---|
370 | CREATE FUNCTION tsquery_in(cstring) |
---|
371 | RETURNS tsquery |
---|
372 | AS '$libdir/tsearch2' |
---|
373 | LANGUAGE 'C' with (isstrict); |
---|
374 | |
---|
375 | CREATE FUNCTION tsquery_out(tsquery) |
---|
376 | RETURNS cstring |
---|
377 | AS '$libdir/tsearch2' |
---|
378 | LANGUAGE 'C' with (isstrict); |
---|
379 | |
---|
380 | CREATE TYPE tsquery ( |
---|
381 | INTERNALLENGTH = -1, |
---|
382 | INPUT = tsquery_in, |
---|
383 | OUTPUT = tsquery_out |
---|
384 | ); |
---|
385 | |
---|
386 | CREATE FUNCTION querytree(tsquery) |
---|
387 | RETURNS text |
---|
388 | AS '$libdir/tsearch2', 'tsquerytree' |
---|
389 | LANGUAGE 'C' with (isstrict); |
---|
390 | |
---|
391 | CREATE FUNCTION to_tsquery(oid, text) |
---|
392 | RETURNS tsquery |
---|
393 | AS '$libdir/tsearch2' |
---|
394 | LANGUAGE 'c' with (isstrict,iscachable); |
---|
395 | |
---|
396 | CREATE FUNCTION to_tsquery(text, text) |
---|
397 | RETURNS tsquery |
---|
398 | AS '$libdir/tsearch2','to_tsquery_name' |
---|
399 | LANGUAGE 'c' with (isstrict,iscachable); |
---|
400 | |
---|
401 | CREATE FUNCTION to_tsquery(text) |
---|
402 | RETURNS tsquery |
---|
403 | AS '$libdir/tsearch2','to_tsquery_current' |
---|
404 | LANGUAGE 'c' with (isstrict,iscachable); |
---|
405 | |
---|
406 | --operations |
---|
407 | CREATE FUNCTION exectsq(tsvector, tsquery) |
---|
408 | RETURNS bool |
---|
409 | AS '$libdir/tsearch2' |
---|
410 | LANGUAGE 'C' with (isstrict, iscachable); |
---|
411 | |
---|
412 | COMMENT ON FUNCTION exectsq(tsvector, tsquery) IS 'boolean operation with text index'; |
---|
413 | |
---|
414 | CREATE FUNCTION rexectsq(tsquery, tsvector) |
---|
415 | RETURNS bool |
---|
416 | AS '$libdir/tsearch2' |
---|
417 | LANGUAGE 'C' with (isstrict, iscachable); |
---|
418 | |
---|
419 | COMMENT ON FUNCTION rexectsq(tsquery, tsvector) IS 'boolean operation with text index'; |
---|
420 | |
---|
421 | CREATE OPERATOR @@ ( |
---|
422 | LEFTARG = tsvector, |
---|
423 | RIGHTARG = tsquery, |
---|
424 | PROCEDURE = exectsq, |
---|
425 | COMMUTATOR = '@@', |
---|
426 | RESTRICT = contsel, |
---|
427 | JOIN = contjoinsel |
---|
428 | ); |
---|
429 | CREATE OPERATOR @@ ( |
---|
430 | LEFTARG = tsquery, |
---|
431 | RIGHTARG = tsvector, |
---|
432 | PROCEDURE = rexectsq, |
---|
433 | COMMUTATOR = '@@', |
---|
434 | RESTRICT = contsel, |
---|
435 | JOIN = contjoinsel |
---|
436 | ); |
---|
437 | |
---|
438 | --Trigger |
---|
439 | CREATE FUNCTION tsearch2() |
---|
440 | RETURNS trigger |
---|
441 | AS '$libdir/tsearch2' |
---|
442 | LANGUAGE 'C'; |
---|
443 | |
---|
444 | --Relevation |
---|
445 | CREATE FUNCTION rank(float4[], tsvector, tsquery) |
---|
446 | RETURNS float4 |
---|
447 | AS '$libdir/tsearch2' |
---|
448 | LANGUAGE 'C' WITH (isstrict, iscachable); |
---|
449 | |
---|
450 | CREATE FUNCTION rank(float4[], tsvector, tsquery, int4) |
---|
451 | RETURNS float4 |
---|
452 | AS '$libdir/tsearch2' |
---|
453 | LANGUAGE 'C' WITH (isstrict, iscachable); |
---|
454 | |
---|
455 | CREATE FUNCTION rank(tsvector, tsquery) |
---|
456 | RETURNS float4 |
---|
457 | AS '$libdir/tsearch2', 'rank_def' |
---|
458 | LANGUAGE 'C' WITH (isstrict, iscachable); |
---|
459 | |
---|
460 | CREATE FUNCTION rank(tsvector, tsquery, int4) |
---|
461 | RETURNS float4 |
---|
462 | AS '$libdir/tsearch2', 'rank_def' |
---|
463 | LANGUAGE 'C' WITH (isstrict, iscachable); |
---|
464 | |
---|
465 | CREATE FUNCTION rank_cd(int4, tsvector, tsquery) |
---|
466 | RETURNS float4 |
---|
467 | AS '$libdir/tsearch2' |
---|
468 | LANGUAGE 'C' WITH (isstrict, iscachable); |
---|
469 | |
---|
470 | CREATE FUNCTION rank_cd(int4, tsvector, tsquery, int4) |
---|
471 | RETURNS float4 |
---|
472 | AS '$libdir/tsearch2' |
---|
473 | LANGUAGE 'C' WITH (isstrict, iscachable); |
---|
474 | |
---|
475 | CREATE FUNCTION rank_cd(tsvector, tsquery) |
---|
476 | RETURNS float4 |
---|
477 | AS '$libdir/tsearch2', 'rank_cd_def' |
---|
478 | LANGUAGE 'C' WITH (isstrict, iscachable); |
---|
479 | |
---|
480 | CREATE FUNCTION rank_cd(tsvector, tsquery, int4) |
---|
481 | RETURNS float4 |
---|
482 | AS '$libdir/tsearch2', 'rank_cd_def' |
---|
483 | LANGUAGE 'C' WITH (isstrict, iscachable); |
---|
484 | |
---|
485 | CREATE FUNCTION headline(oid, text, tsquery, text) |
---|
486 | RETURNS text |
---|
487 | AS '$libdir/tsearch2', 'headline' |
---|
488 | LANGUAGE 'C' WITH (isstrict, iscachable); |
---|
489 | |
---|
490 | CREATE FUNCTION headline(oid, text, tsquery) |
---|
491 | RETURNS text |
---|
492 | AS '$libdir/tsearch2', 'headline' |
---|
493 | LANGUAGE 'C' WITH (isstrict, iscachable); |
---|
494 | |
---|
495 | CREATE FUNCTION headline(text, text, tsquery, text) |
---|
496 | RETURNS text |
---|
497 | AS '$libdir/tsearch2', 'headline_byname' |
---|
498 | LANGUAGE 'C' WITH (isstrict, iscachable); |
---|
499 | |
---|
500 | CREATE FUNCTION headline(text, text, tsquery) |
---|
501 | RETURNS text |
---|
502 | AS '$libdir/tsearch2', 'headline_byname' |
---|
503 | LANGUAGE 'C' WITH (isstrict, iscachable); |
---|
504 | |
---|
505 | CREATE FUNCTION headline(text, tsquery, text) |
---|
506 | RETURNS text |
---|
507 | AS '$libdir/tsearch2', 'headline_current' |
---|
508 | LANGUAGE 'C' WITH (isstrict, iscachable); |
---|
509 | |
---|
510 | CREATE FUNCTION headline(text, tsquery) |
---|
511 | RETURNS text |
---|
512 | AS '$libdir/tsearch2', 'headline_current' |
---|
513 | LANGUAGE 'C' WITH (isstrict, iscachable); |
---|
514 | |
---|
515 | --GiST |
---|
516 | --GiST key type |
---|
517 | CREATE FUNCTION gtsvector_in(cstring) |
---|
518 | RETURNS gtsvector |
---|
519 | AS '$libdir/tsearch2' |
---|
520 | LANGUAGE 'C' with (isstrict); |
---|
521 | |
---|
522 | CREATE FUNCTION gtsvector_out(gtsvector) |
---|
523 | RETURNS cstring |
---|
524 | AS '$libdir/tsearch2' |
---|
525 | LANGUAGE 'C' with (isstrict); |
---|
526 | |
---|
527 | CREATE TYPE gtsvector ( |
---|
528 | INTERNALLENGTH = -1, |
---|
529 | INPUT = gtsvector_in, |
---|
530 | OUTPUT = gtsvector_out |
---|
531 | ); |
---|
532 | |
---|
533 | -- support FUNCTIONs |
---|
534 | CREATE FUNCTION gtsvector_consistent(gtsvector,internal,int4) |
---|
535 | RETURNS bool |
---|
536 | AS '$libdir/tsearch2' |
---|
537 | LANGUAGE 'C'; |
---|
538 | |
---|
539 | CREATE FUNCTION gtsvector_compress(internal) |
---|
540 | RETURNS internal |
---|
541 | AS '$libdir/tsearch2' |
---|
542 | LANGUAGE 'C'; |
---|
543 | |
---|
544 | CREATE FUNCTION gtsvector_decompress(internal) |
---|
545 | RETURNS internal |
---|
546 | AS '$libdir/tsearch2' |
---|
547 | LANGUAGE 'C'; |
---|
548 | |
---|
549 | CREATE FUNCTION gtsvector_penalty(internal,internal,internal) |
---|
550 | RETURNS internal |
---|
551 | AS '$libdir/tsearch2' |
---|
552 | LANGUAGE 'C' with (isstrict); |
---|
553 | |
---|
554 | CREATE FUNCTION gtsvector_picksplit(internal, internal) |
---|
555 | RETURNS internal |
---|
556 | AS '$libdir/tsearch2' |
---|
557 | LANGUAGE 'C'; |
---|
558 | |
---|
559 | CREATE FUNCTION gtsvector_union(internal, internal) |
---|
560 | RETURNS _int4 |
---|
561 | AS '$libdir/tsearch2' |
---|
562 | LANGUAGE 'C'; |
---|
563 | |
---|
564 | CREATE FUNCTION gtsvector_same(gtsvector, gtsvector, internal) |
---|
565 | RETURNS internal |
---|
566 | AS '$libdir/tsearch2' |
---|
567 | LANGUAGE 'C'; |
---|
568 | |
---|
569 | -- CREATE the OPERATOR class |
---|
570 | CREATE OPERATOR CLASS gist_tsvector_ops |
---|
571 | DEFAULT FOR TYPE tsvector USING gist |
---|
572 | AS |
---|
573 | OPERATOR 1 @@ (tsvector, tsquery) RECHECK , |
---|
574 | FUNCTION 1 gtsvector_consistent (gtsvector, internal, int4), |
---|
575 | FUNCTION 2 gtsvector_union (internal, internal), |
---|
576 | FUNCTION 3 gtsvector_compress (internal), |
---|
577 | FUNCTION 4 gtsvector_decompress (internal), |
---|
578 | FUNCTION 5 gtsvector_penalty (internal, internal, internal), |
---|
579 | FUNCTION 6 gtsvector_picksplit (internal, internal), |
---|
580 | FUNCTION 7 gtsvector_same (gtsvector, gtsvector, internal), |
---|
581 | STORAGE gtsvector; |
---|
582 | |
---|
583 | |
---|
584 | --stat info |
---|
585 | CREATE TYPE statinfo |
---|
586 | as (word text, ndoc int4, nentry int4); |
---|
587 | |
---|
588 | --CREATE FUNCTION tsstat_in(cstring) |
---|
589 | --RETURNS tsstat |
---|
590 | --AS '$libdir/tsearch2' |
---|
591 | --LANGUAGE 'C' with (isstrict); |
---|
592 | -- |
---|
593 | --CREATE FUNCTION tsstat_out(tsstat) |
---|
594 | --RETURNS cstring |
---|
595 | --AS '$libdir/tsearch2' |
---|
596 | --LANGUAGE 'C' with (isstrict); |
---|
597 | -- |
---|
598 | --CREATE TYPE tsstat ( |
---|
599 | -- INTERNALLENGTH = -1, |
---|
600 | -- INPUT = tsstat_in, |
---|
601 | -- OUTPUT = tsstat_out, |
---|
602 | -- STORAGE = plain |
---|
603 | --); |
---|
604 | -- |
---|
605 | --CREATE FUNCTION ts_accum(tsstat,tsvector) |
---|
606 | --RETURNS tsstat |
---|
607 | --AS '$libdir/tsearch2' |
---|
608 | --LANGUAGE 'C' with (isstrict); |
---|
609 | -- |
---|
610 | --CREATE FUNCTION ts_accum_finish(tsstat) |
---|
611 | -- returns setof statinfo |
---|
612 | -- as '$libdir/tsearch2' |
---|
613 | -- language 'C' |
---|
614 | -- with (isstrict); |
---|
615 | -- |
---|
616 | --CREATE AGGREGATE stat ( |
---|
617 | -- BASETYPE=tsvector, |
---|
618 | -- SFUNC=ts_accum, |
---|
619 | -- STYPE=tsstat, |
---|
620 | -- FINALFUNC = ts_accum_finish, |
---|
621 | -- initcond = '' |
---|
622 | --); |
---|
623 | |
---|
624 | CREATE FUNCTION stat(text) |
---|
625 | returns setof statinfo |
---|
626 | as '$libdir/tsearch2', 'ts_stat' |
---|
627 | language 'C' |
---|
628 | with (isstrict); |
---|
629 | |
---|
630 | CREATE FUNCTION stat(text,text) |
---|
631 | returns setof statinfo |
---|
632 | as '$libdir/tsearch2', 'ts_stat' |
---|
633 | language 'C' |
---|
634 | with (isstrict); |
---|
635 | |
---|
636 | --reset - just for debuging |
---|
637 | CREATE FUNCTION reset_tsearch() |
---|
638 | returns void |
---|
639 | as '$libdir/tsearch2' |
---|
640 | language 'C' |
---|
641 | with (isstrict); |
---|
642 | |
---|
643 | --get cover (debug for rank_cd) |
---|
644 | CREATE FUNCTION get_covers(tsvector,tsquery) |
---|
645 | returns text |
---|
646 | as '$libdir/tsearch2' |
---|
647 | language 'C' |
---|
648 | with (isstrict); |
---|
649 | |
---|
650 | --debug function |
---|
651 | create type tsdebug as ( |
---|
652 | ts_name text, |
---|
653 | tok_type text, |
---|
654 | description text, |
---|
655 | token text, |
---|
656 | dict_name text[], |
---|
657 | "tsvector" tsvector |
---|
658 | ); |
---|
659 | |
---|
660 | create function _get_parser_from_curcfg() |
---|
661 | returns text as |
---|
662 | ' select prs_name from pg_ts_cfg where oid = show_curcfg() ' |
---|
663 | language 'SQL' with(isstrict,iscachable); |
---|
664 | |
---|
665 | create function ts_debug(text) |
---|
666 | returns setof tsdebug as ' |
---|
667 | select |
---|
668 | m.ts_name, |
---|
669 | t.alias as tok_type, |
---|
670 | t.descr as description, |
---|
671 | p.token, |
---|
672 | m.dict_name, |
---|
673 | strip(to_tsvector(p.token)) as tsvector |
---|
674 | from |
---|
675 | parse( _get_parser_from_curcfg(), $1 ) as p, |
---|
676 | token_type() as t, |
---|
677 | pg_ts_cfgmap as m, |
---|
678 | pg_ts_cfg as c |
---|
679 | where |
---|
680 | t.tokid=p.tokid and |
---|
681 | t.alias = m.tok_alias and |
---|
682 | m.ts_name=c.ts_name and |
---|
683 | c.oid=show_curcfg() |
---|
684 | ' language 'SQL' with(isstrict); |
---|
685 | |
---|
686 | --compare functions |
---|
687 | CREATE FUNCTION tsvector_cmp(tsvector,tsvector) |
---|
688 | RETURNS int4 |
---|
689 | AS '$libdir/tsearch2' |
---|
690 | LANGUAGE 'C' WITH (isstrict,iscachable); |
---|
691 | |
---|
692 | CREATE FUNCTION tsvector_lt(tsvector,tsvector) |
---|
693 | RETURNS bool |
---|
694 | AS '$libdir/tsearch2' |
---|
695 | LANGUAGE 'C' WITH (isstrict,iscachable); |
---|
696 | |
---|
697 | CREATE FUNCTION tsvector_le(tsvector,tsvector) |
---|
698 | RETURNS bool |
---|
699 | AS '$libdir/tsearch2' |
---|
700 | LANGUAGE 'C' WITH (isstrict,iscachable); |
---|
701 | |
---|
702 | CREATE FUNCTION tsvector_eq(tsvector,tsvector) |
---|
703 | RETURNS bool |
---|
704 | AS '$libdir/tsearch2' |
---|
705 | LANGUAGE 'C' WITH (isstrict,iscachable); |
---|
706 | |
---|
707 | CREATE FUNCTION tsvector_ge(tsvector,tsvector) |
---|
708 | RETURNS bool |
---|
709 | AS '$libdir/tsearch2' |
---|
710 | LANGUAGE 'C' WITH (isstrict,iscachable); |
---|
711 | |
---|
712 | CREATE FUNCTION tsvector_gt(tsvector,tsvector) |
---|
713 | RETURNS bool |
---|
714 | AS '$libdir/tsearch2' |
---|
715 | LANGUAGE 'C' WITH (isstrict,iscachable); |
---|
716 | |
---|
717 | CREATE FUNCTION tsvector_ne(tsvector,tsvector) |
---|
718 | RETURNS bool |
---|
719 | AS '$libdir/tsearch2' |
---|
720 | LANGUAGE 'C' WITH (isstrict,iscachable); |
---|
721 | |
---|
722 | CREATE OPERATOR < ( |
---|
723 | LEFTARG = tsvector, |
---|
724 | RIGHTARG = tsvector, |
---|
725 | PROCEDURE = tsvector_lt, |
---|
726 | COMMUTATOR = '>', |
---|
727 | NEGATOR = '>=', |
---|
728 | RESTRICT = contsel, |
---|
729 | JOIN = contjoinsel |
---|
730 | ); |
---|
731 | |
---|
732 | CREATE OPERATOR <= ( |
---|
733 | LEFTARG = tsvector, |
---|
734 | RIGHTARG = tsvector, |
---|
735 | PROCEDURE = tsvector_le, |
---|
736 | COMMUTATOR = '>=', |
---|
737 | NEGATOR = '>', |
---|
738 | RESTRICT = contsel, |
---|
739 | JOIN = contjoinsel |
---|
740 | ); |
---|
741 | |
---|
742 | CREATE OPERATOR >= ( |
---|
743 | LEFTARG = tsvector, |
---|
744 | RIGHTARG = tsvector, |
---|
745 | PROCEDURE = tsvector_ge, |
---|
746 | COMMUTATOR = '<=', |
---|
747 | NEGATOR = '<', |
---|
748 | RESTRICT = contsel, |
---|
749 | JOIN = contjoinsel |
---|
750 | ); |
---|
751 | |
---|
752 | CREATE OPERATOR > ( |
---|
753 | LEFTARG = tsvector, |
---|
754 | RIGHTARG = tsvector, |
---|
755 | PROCEDURE = tsvector_gt, |
---|
756 | COMMUTATOR = '<', |
---|
757 | NEGATOR = '<=', |
---|
758 | RESTRICT = contsel, |
---|
759 | JOIN = contjoinsel |
---|
760 | ); |
---|
761 | |
---|
762 | CREATE OPERATOR = ( |
---|
763 | LEFTARG = tsvector, |
---|
764 | RIGHTARG = tsvector, |
---|
765 | PROCEDURE = tsvector_eq, |
---|
766 | COMMUTATOR = '=', |
---|
767 | NEGATOR = '<>', |
---|
768 | RESTRICT = eqsel, |
---|
769 | JOIN = eqjoinsel, |
---|
770 | SORT1 = '<', |
---|
771 | SORT2 = '<' |
---|
772 | ); |
---|
773 | |
---|
774 | CREATE OPERATOR <> ( |
---|
775 | LEFTARG = tsvector, |
---|
776 | RIGHTARG = tsvector, |
---|
777 | PROCEDURE = tsvector_ne, |
---|
778 | COMMUTATOR = '<>', |
---|
779 | NEGATOR = '=', |
---|
780 | RESTRICT = neqsel, |
---|
781 | JOIN = neqjoinsel |
---|
782 | ); |
---|
783 | |
---|
784 | CREATE OPERATOR CLASS tsvector_ops |
---|
785 | DEFAULT FOR TYPE tsvector USING btree AS |
---|
786 | OPERATOR 1 < , |
---|
787 | OPERATOR 2 <= , |
---|
788 | OPERATOR 3 = , |
---|
789 | OPERATOR 4 >= , |
---|
790 | OPERATOR 5 > , |
---|
791 | FUNCTION 1 tsvector_cmp(tsvector, tsvector); |
---|
792 | |
---|
793 | --example of ISpell dictionary |
---|
794 | --update pg_ts_dict set dict_initoption='DictFile="/usr/local/share/ispell/russian.dict" ,AffFile ="/usr/local/share/ispell/russian.aff", StopFile="/usr/local/share/ispell/russian.stop"' where dict_name='ispell_template'; |
---|
795 | --example of synonym dict |
---|
796 | --update pg_ts_dict set dict_initoption='/usr/local/share/ispell/english.syn' where dict_id=5; |
---|
797 | END; |
---|