~vcs-imports/mammoth-replicator/trunk

« back to all changes in this revision

Viewing changes to contrib/tsearch2/sql/tsearch2.sql

  • Committer: alvherre
  • Date: 2005-12-16 21:24:52 UTC
  • Revision ID: svn-v4:db760fc0-0f08-0410-9d63-cc6633f64896:trunk:1
Initial import of the REL8_0_3 sources from the Pgsql CVS repository.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
--
 
2
-- first, define the datatype.  Turn off echoing so that expected file
 
3
-- does not depend on contents of seg.sql.
 
4
--
 
5
\set ECHO none
 
6
\i tsearch2.sql
 
7
\set ECHO all
 
8
 
 
9
--tsvector
 
10
SELECT '1'::tsvector;
 
11
SELECT '1 '::tsvector;
 
12
SELECT ' 1'::tsvector;
 
13
SELECT ' 1 '::tsvector;
 
14
SELECT '1 2'::tsvector;
 
15
SELECT '\'1 2\''::tsvector;
 
16
SELECT '\'1 \\\'2\''::tsvector;
 
17
SELECT '\'1 \\\'2\'3'::tsvector;
 
18
SELECT '\'1 \\\'2\' 3'::tsvector;
 
19
SELECT '\'1 \\\'2\' \' 3\' 4 '::tsvector;
 
20
select '\'w\':4A,3B,2C,1D,5 a:8';
 
21
select 'a:3A b:2a'::tsvector || 'ba:1234 a:1B';
 
22
select setweight('w:12B w:13* w:12,5,6 a:1,3* a:3 w asd:1dc asd zxc:81,567,222A'::tsvector, 'c');
 
23
select strip('w:12B w:13* w:12,5,6 a:1,3* a:3 w asd:1dc asd'::tsvector);
 
24
 
 
25
 
 
26
--tsquery
 
27
SELECT '1'::tsquery;
 
28
SELECT '1 '::tsquery;
 
29
SELECT ' 1'::tsquery;
 
30
SELECT ' 1 '::tsquery;
 
31
SELECT '\'1 2\''::tsquery;
 
32
SELECT '\'1 \\\'2\''::tsquery;
 
33
SELECT '!1'::tsquery;
 
34
SELECT '1|2'::tsquery;
 
35
SELECT '1|!2'::tsquery;
 
36
SELECT '!1|2'::tsquery;
 
37
SELECT '!1|!2'::tsquery;
 
38
SELECT '!(!1|!2)'::tsquery;
 
39
SELECT '!(!1|2)'::tsquery;
 
40
SELECT '!(1|!2)'::tsquery;
 
41
SELECT '!(1|2)'::tsquery;
 
42
SELECT '1&2'::tsquery;
 
43
SELECT '!1&2'::tsquery;
 
44
SELECT '1&!2'::tsquery;
 
45
SELECT '!1&!2'::tsquery;
 
46
SELECT '(1&2)'::tsquery;
 
47
SELECT '1&(2)'::tsquery;
 
48
SELECT '!(1)&2'::tsquery;
 
49
SELECT '!(1&2)'::tsquery;
 
50
SELECT '1|2&3'::tsquery;
 
51
SELECT '1|(2&3)'::tsquery;
 
52
SELECT '(1|2)&3'::tsquery;
 
53
SELECT '1|2&!3'::tsquery;
 
54
SELECT '1|!2&3'::tsquery;
 
55
SELECT '!1|2&3'::tsquery;
 
56
SELECT '!1|(2&3)'::tsquery;
 
57
SELECT '!(1|2)&3'::tsquery;
 
58
SELECT '(!1|2)&3'::tsquery;
 
59
SELECT '1|(2|(4|(5|6)))'::tsquery;
 
60
SELECT '1|2|4|5|6'::tsquery;
 
61
SELECT '1&(2&(4&(5&6)))'::tsquery;
 
62
SELECT '1&2&4&5&6'::tsquery;
 
63
SELECT '1&(2&(4&(5|6)))'::tsquery;
 
64
SELECT '1&(2&(4&(5|!6)))'::tsquery;
 
65
SELECT '1&(\'2\'&(\' 4\'&(\\|5 | \'6 \\\' !|&\')))'::tsquery;
 
66
SELECT '\'the wether\':dc & \' sKies \':BC & a:d b:a';
 
67
 
 
68
select lexize('simple', 'ASD56 hsdkf');
 
69
select lexize('en_stem', 'SKIES Problems identity');
 
70
 
 
71
select * from token_type('default');
 
72
select * from parse('default', '345 qwe@efd.r \' http://www.com/ http://aew.werc.ewr/?ad=qwe&dw 1aew.werc.ewr/?ad=qwe&dw 2aew.werc.ewr http://3aew.werc.ewr/?ad=qwe&dw http://4aew.werc.ewr http://5aew.werc.ewr:8100/?  ad=qwe&dw 6aew.werc.ewr:8100/?ad=qwe&dw 7aew.werc.ewr:8100/?ad=qwe&dw=%20%32 +4.0e-10 qwe qwe qwqwe 234.435 455 5.005 teodor@stack.net qwe-wer asdf <fr>qwer jf sdjk<we hjwer <werrwe> ewr1> ewri2 <a href="qwe<qwe>">
 
73
/usr/local/fff /awdf/dwqe/4325 rewt/ewr wefjn /wqe-324/ewr gist.h gist.h.c gist.c. readline 4.2 4.2. 4.2, readline-4.2 readline-4.2. 234 
 
74
<i <b> wow  < jqw <> qwerty');
 
75
 
 
76
SELECT to_tsvector('default', '345 qwe@efd.r \' http://www.com/ http://aew.werc.ewr/?ad=qwe&dw 1aew.werc.ewr/?ad=qwe&dw 2aew.werc.ewr http://3aew.werc.ewr/?ad=qwe&dw http://4aew.werc.ewr http://5aew.werc.ewr:8100/?  ad=qwe&dw 6aew.werc.ewr:8100/?ad=qwe&dw 7aew.werc.ewr:8100/?ad=qwe&dw=%20%32 +4.0e-10 qwe qwe qwqwe 234.435 455 5.005 teodor@stack.net qwe-wer asdf <fr>qwer jf sdjk<we hjwer <werrwe> ewr1> ewri2 <a href="qwe<qwe>">
 
77
/usr/local/fff /awdf/dwqe/4325 rewt/ewr wefjn /wqe-324/ewr gist.h gist.h.c gist.c. readline 4.2 4.2. 4.2, readline-4.2 readline-4.2. 234 
 
78
<i <b> wow  < jqw <> qwerty');
 
79
 
 
80
SELECT length(to_tsvector('default', '345 qw'));
 
81
 
 
82
SELECT length(to_tsvector('default', '345 qwe@efd.r \' http://www.com/ http://aew.werc.ewr/?ad=qwe&dw 1aew.werc.ewr/?ad=qwe&dw 2aew.werc.ewr http://3aew.werc.ewr/?ad=qwe&dw http://4aew.werc.ewr http://5aew.werc.ewr:8100/?  ad=qwe&dw 6aew.werc.ewr:8100/?ad=qwe&dw 7aew.werc.ewr:8100/?ad=qwe&dw=%20%32 +4.0e-10 qwe qwe qwqwe 234.435 455 5.005 teodor@stack.net qwe-wer asdf <fr>qwer jf sdjk<we hjwer <werrwe> ewr1> ewri2 <a href="qwe<qwe>">
 
83
/usr/local/fff /awdf/dwqe/4325 rewt/ewr wefjn /wqe-324/ewr gist.h gist.h.c gist.c. readline 4.2 4.2. 4.2, readline-4.2 readline-4.2. 234 
 
84
<i <b> wow  < jqw <> qwerty'));
 
85
 
 
86
 
 
87
select to_tsquery('default', 'qwe & sKies '); 
 
88
select to_tsquery('simple', 'qwe & sKies '); 
 
89
select to_tsquery('default', '\'the wether\':dc & \'           sKies \':BC ');
 
90
select to_tsquery('default', 'asd&(and|fghj)');
 
91
select to_tsquery('default', '(asd&and)|fghj');
 
92
select to_tsquery('default', '(asd&!and)|fghj');
 
93
select to_tsquery('default', '(the|and&(i&1))&fghj');
 
94
select 'a b:89  ca:23A,64b d:34c'::tsvector @@ 'd:AC & ca';
 
95
select 'a b:89  ca:23A,64b d:34c'::tsvector @@ 'd:AC & ca:B';
 
96
select 'a b:89  ca:23A,64b d:34c'::tsvector @@ 'd:AC & ca:A';
 
97
select 'a b:89  ca:23A,64b d:34c'::tsvector @@ 'd:AC & ca:C';
 
98
select 'a b:89  ca:23A,64b d:34c'::tsvector @@ 'd:AC & ca:CB';
 
99
 
 
100
CREATE TABLE test_tsvector( t text, a tsvector );
 
101
 
 
102
\copy test_tsvector from 'data/test_tsearch.data'
 
103
 
 
104
SELECT count(*) FROM test_tsvector WHERE a @@ 'wr|qh';
 
105
SELECT count(*) FROM test_tsvector WHERE a @@ 'wr&qh';
 
106
SELECT count(*) FROM test_tsvector WHERE a @@ 'eq&yt';
 
107
SELECT count(*) FROM test_tsvector WHERE a @@ 'eq|yt';
 
108
SELECT count(*) FROM test_tsvector WHERE a @@ '(eq&yt)|(wr&qh)';
 
109
SELECT count(*) FROM test_tsvector WHERE a @@ '(eq|yt)&(wr|qh)';
 
110
 
 
111
create index wowidx on test_tsvector using gist (a);
 
112
set enable_seqscan=off;
 
113
 
 
114
SELECT count(*) FROM test_tsvector WHERE a @@ 'wr|qh';
 
115
SELECT count(*) FROM test_tsvector WHERE a @@ 'wr&qh';
 
116
SELECT count(*) FROM test_tsvector WHERE a @@ 'eq&yt';
 
117
SELECT count(*) FROM test_tsvector WHERE a @@ 'eq|yt';
 
118
SELECT count(*) FROM test_tsvector WHERE a @@ '(eq&yt)|(wr&qh)';
 
119
SELECT count(*) FROM test_tsvector WHERE a @@ '(eq|yt)&(wr|qh)';
 
120
 
 
121
select set_curcfg('default');
 
122
 
 
123
CREATE TRIGGER tsvectorupdate
 
124
BEFORE UPDATE OR INSERT ON test_tsvector
 
125
FOR EACH ROW EXECUTE PROCEDURE tsearch2(a, t);
 
126
 
 
127
SELECT count(*) FROM test_tsvector WHERE a @@ to_tsquery('345&qwerty');
 
128
 
 
129
INSERT INTO test_tsvector (t) VALUES ('345 qwerty');
 
130
 
 
131
SELECT count(*) FROM test_tsvector WHERE a @@ to_tsquery('345&qwerty');
 
132
 
 
133
UPDATE test_tsvector SET t = null WHERE t = '345 qwerty';
 
134
 
 
135
SELECT count(*) FROM test_tsvector WHERE a @@ to_tsquery('345&qwerty');
 
136
 
 
137
drop trigger tsvectorupdate on test_tsvector;
 
138
create function wow(text) returns text as 'select $1 || \' copyright\'; ' language sql;
 
139
create trigger tsvectorupdate before update or insert on test_tsvector
 
140
for each row execute procedure tsearch2(a, wow, t);
 
141
insert into test_tsvector (t) values ('345 qwerty');
 
142
select count(*) FROM test_tsvector WHERE a @@ to_tsquery('345&qwerty');
 
143
select count(*) FROM test_tsvector WHERE a @@ to_tsquery('copyright');
 
144
 
 
145
select rank(' a:1 s:2C d g'::tsvector, 'a | s');
 
146
select rank(' a:1 s:2B d g'::tsvector, 'a | s');
 
147
select rank(' a:1 s:2 d g'::tsvector, 'a | s');
 
148
select rank(' a:1 s:2C d g'::tsvector, 'a & s');
 
149
select rank(' a:1 s:2B d g'::tsvector, 'a & s');
 
150
select rank(' a:1 s:2 d g'::tsvector, 'a & s');
 
151
 
 
152
insert into test_tsvector (t) values ('foo bar foo the over foo qq bar');
 
153
drop trigger tsvectorupdate on test_tsvector;
 
154
select * from stat('select a from test_tsvector') order by ndoc desc, nentry desc, word;
 
155
insert into test_tsvector values ('1', 'a:1a,2,3b b:5a,6a,7c,8');
 
156
insert into test_tsvector values ('1', 'a:1a,2,3c b:5a,6b,7c,8b');
 
157
select * from stat('select a from test_tsvector','a') order by ndoc desc, nentry desc, word;
 
158
select * from stat('select a from test_tsvector','b') order by ndoc desc, nentry desc, word;
 
159
select * from stat('select a from test_tsvector','c') order by ndoc desc, nentry desc, word;
 
160
select * from stat('select a from test_tsvector','d') order by ndoc desc, nentry desc, word;
 
161
select * from stat('select a from test_tsvector','ad') order by ndoc desc, nentry desc, word;
 
162
 
 
163
select reset_tsearch();
 
164
select to_tsquery('default', 'skies & books');
 
165
 
 
166
select rank_cd(to_tsvector('Erosion It took the sea a thousand years,
 
167
A thousand years to trace
 
168
The granite features of this cliff
 
169
In crag and scarp and base.
 
170
It took the sea an hour one night
 
171
An hour of storm to place
 
172
The sculpture of these granite seams,
 
173
Upon a woman s face. E.  J.  Pratt  (1882 1964)
 
174
'), to_tsquery('sea&thousand&years'));
 
175
 
 
176
select rank_cd(to_tsvector('Erosion It took the sea a thousand years,
 
177
A thousand years to trace
 
178
The granite features of this cliff
 
179
In crag and scarp and base.
 
180
It took the sea an hour one night
 
181
An hour of storm to place
 
182
The sculpture of these granite seams,
 
183
Upon a woman s face. E.  J.  Pratt  (1882 1964)
 
184
'), to_tsquery('granite&sea'));
 
185
 
 
186
select rank_cd(to_tsvector('Erosion It took the sea a thousand years,
 
187
A thousand years to trace
 
188
The granite features of this cliff
 
189
In crag and scarp and base.
 
190
It took the sea an hour one night
 
191
An hour of storm to place
 
192
The sculpture of these granite seams,
 
193
Upon a woman s face. E.  J.  Pratt  (1882 1964)
 
194
'), to_tsquery('sea'));
 
195
 
 
196
select get_covers(to_tsvector('Erosion It took the sea a thousand years,
 
197
A thousand years to trace
 
198
The granite features of this cliff
 
199
In crag and scarp and base.
 
200
It took the sea an hour one night
 
201
An hour of storm to place
 
202
The sculpture of these granite seams,
 
203
Upon a woman s face. E.  J.  Pratt  (1882 1964)
 
204
'), to_tsquery('sea&thousand&years'));
 
205
 
 
206
select get_covers(to_tsvector('Erosion It took the sea a thousand years,
 
207
A thousand years to trace
 
208
The granite features of this cliff
 
209
In crag and scarp and base.
 
210
It took the sea an hour one night
 
211
An hour of storm to place
 
212
The sculpture of these granite seams,
 
213
Upon a woman s face. E.  J.  Pratt  (1882 1964)
 
214
'), to_tsquery('granite&sea'));
 
215
 
 
216
select get_covers(to_tsvector('Erosion It took the sea a thousand years,
 
217
A thousand years to trace
 
218
The granite features of this cliff
 
219
In crag and scarp and base.
 
220
It took the sea an hour one night
 
221
An hour of storm to place
 
222
The sculpture of these granite seams,
 
223
Upon a woman s face. E.  J.  Pratt  (1882 1964)
 
224
'), to_tsquery('sea'));
 
225
 
 
226
select headline('Erosion It took the sea a thousand years,
 
227
A thousand years to trace
 
228
The granite features of this cliff
 
229
In crag and scarp and base.
 
230
It took the sea an hour one night
 
231
An hour of storm to place
 
232
The sculpture of these granite seams,
 
233
Upon a woman s face. E.  J.  Pratt  (1882 1964)
 
234
', to_tsquery('sea&thousand&years'));
 
235
 
 
236
select headline('Erosion It took the sea a thousand years,
 
237
A thousand years to trace
 
238
The granite features of this cliff
 
239
In crag and scarp and base.
 
240
It took the sea an hour one night
 
241
An hour of storm to place
 
242
The sculpture of these granite seams,
 
243
Upon a woman s face. E.  J.  Pratt  (1882 1964)
 
244
', to_tsquery('granite&sea'));
 
245
 
 
246
select headline('Erosion It took the sea a thousand years,
 
247
A thousand years to trace
 
248
The granite features of this cliff
 
249
In crag and scarp and base.
 
250
It took the sea an hour one night
 
251
An hour of storm to place
 
252
The sculpture of these granite seams,
 
253
Upon a woman s face. E.  J.  Pratt  (1882 1964)
 
254
', to_tsquery('sea'));
 
255
 
 
256
 
 
257
select headline('
 
258
<html>
 
259
<!-- some comment -->
 
260
<body>
 
261
Sea view wow <u>foo bar</u> <i>qq</i>
 
262
<a href="http://www.google.com/foo.bar.html" target="_blank">YES &nbsp;</a>
 
263
ff-bg
 
264
<script>
 
265
        document.write(15);
 
266
</script>
 
267
</body>
 
268
</html>', 
 
269
to_tsquery('sea&foo'), 'HighlightAll=true');
 
270
--check debug
 
271
select * from ts_debug('Tsearch module for PostgreSQL 7.3.3');
 
272
 
 
273
--check ordering
 
274
insert into test_tsvector values (null, null);
 
275
select a is null, a from test_tsvector order by a;
 
276