]> granicus.if.org Git - postgresql/blob - src/test/regress/expected/tsearch.out
eb004020758e8b826acbc598078b5b6ca4f42254
[postgresql] / src / test / regress / expected / tsearch.out
1 --
2 -- Sanity checks for text search catalogs
3 --
4 -- NB: we assume the oidjoins test will have caught any dangling links,
5 -- that is OID or REGPROC fields that are not zero and do not match some
6 -- row in the linked-to table.  However, if we want to enforce that a link
7 -- field can't be 0, we have to check it here.
8 -- Find unexpected zero link entries
9 SELECT oid, prsname
10 FROM pg_ts_parser
11 WHERE prsnamespace = 0 OR prsstart = 0 OR prstoken = 0 OR prsend = 0 OR
12       -- prsheadline is optional
13       prslextype = 0;
14  oid | prsname 
15 -----+---------
16 (0 rows)
17
18 SELECT oid, dictname
19 FROM pg_ts_dict
20 WHERE dictnamespace = 0 OR dictowner = 0 OR dicttemplate = 0;
21  oid | dictname 
22 -----+----------
23 (0 rows)
24
25 SELECT oid, tmplname
26 FROM pg_ts_template
27 WHERE tmplnamespace = 0 OR tmpllexize = 0;  -- tmplinit is optional
28  oid | tmplname 
29 -----+----------
30 (0 rows)
31
32 SELECT oid, cfgname
33 FROM pg_ts_config
34 WHERE cfgnamespace = 0 OR cfgowner = 0 OR cfgparser = 0;
35  oid | cfgname 
36 -----+---------
37 (0 rows)
38
39 SELECT mapcfg, maptokentype, mapseqno
40 FROM pg_ts_config_map
41 WHERE mapcfg = 0 OR mapdict = 0;
42  mapcfg | maptokentype | mapseqno 
43 --------+--------------+----------
44 (0 rows)
45
46 -- Look for pg_ts_config_map entries that aren't one of parser's token types
47 SELECT * FROM
48   ( SELECT oid AS cfgid, (ts_token_type(cfgparser)).tokid AS tokid
49     FROM pg_ts_config ) AS tt 
50 RIGHT JOIN pg_ts_config_map AS m
51     ON (tt.cfgid=m.mapcfg AND tt.tokid=m.maptokentype)
52 WHERE
53     tt.cfgid IS NULL OR tt.tokid IS NULL;
54  cfgid | tokid | mapcfg | maptokentype | mapseqno | mapdict 
55 -------+-------+--------+--------------+----------+---------
56 (0 rows)
57
58 -- test basic text search behavior without indexes, then with
59 SELECT count(*) FROM test_tsvector WHERE a @@ 'wr|qh';
60  count 
61 -------
62    158
63 (1 row)
64
65 SELECT count(*) FROM test_tsvector WHERE a @@ 'wr&qh';
66  count 
67 -------
68     17
69 (1 row)
70
71 SELECT count(*) FROM test_tsvector WHERE a @@ 'eq&yt';
72  count 
73 -------
74      6
75 (1 row)
76
77 SELECT count(*) FROM test_tsvector WHERE a @@ 'eq|yt';
78  count 
79 -------
80     98
81 (1 row)
82
83 SELECT count(*) FROM test_tsvector WHERE a @@ '(eq&yt)|(wr&qh)';
84  count 
85 -------
86     23
87 (1 row)
88
89 SELECT count(*) FROM test_tsvector WHERE a @@ '(eq|yt)&(wr|qh)';
90  count 
91 -------
92     39
93 (1 row)
94
95 create index wowidx on test_tsvector using gist (a);
96 SET enable_seqscan=OFF;
97 SELECT count(*) FROM test_tsvector WHERE a @@ 'wr|qh';
98  count 
99 -------
100    158
101 (1 row)
102
103 SELECT count(*) FROM test_tsvector WHERE a @@ 'wr&qh';
104  count 
105 -------
106     17
107 (1 row)
108
109 SELECT count(*) FROM test_tsvector WHERE a @@ 'eq&yt';
110  count 
111 -------
112      6
113 (1 row)
114
115 SELECT count(*) FROM test_tsvector WHERE a @@ 'eq|yt';
116  count 
117 -------
118     98
119 (1 row)
120
121 SELECT count(*) FROM test_tsvector WHERE a @@ '(eq&yt)|(wr&qh)';
122  count 
123 -------
124     23
125 (1 row)
126
127 SELECT count(*) FROM test_tsvector WHERE a @@ '(eq|yt)&(wr|qh)';
128  count 
129 -------
130     39
131 (1 row)
132
133 RESET enable_seqscan;
134 DROP INDEX wowidx;
135 CREATE INDEX wowidx ON test_tsvector USING gin (a);
136 SET enable_seqscan=OFF;
137 SELECT count(*) FROM test_tsvector WHERE a @@ 'wr|qh';
138  count 
139 -------
140    158
141 (1 row)
142
143 SELECT count(*) FROM test_tsvector WHERE a @@ 'wr&qh';
144  count 
145 -------
146     17
147 (1 row)
148
149 SELECT count(*) FROM test_tsvector WHERE a @@ 'eq&yt';
150  count 
151 -------
152      6
153 (1 row)
154
155 SELECT count(*) FROM test_tsvector WHERE a @@ 'eq|yt';
156  count 
157 -------
158     98
159 (1 row)
160
161 SELECT count(*) FROM test_tsvector WHERE a @@ '(eq&yt)|(wr&qh)';
162  count 
163 -------
164     23
165 (1 row)
166
167 SELECT count(*) FROM test_tsvector WHERE a @@ '(eq|yt)&(wr|qh)';
168  count 
169 -------
170     39
171 (1 row)
172
173   
174 RESET enable_seqscan;
175 INSERT INTO test_tsvector VALUES ('???', 'DFG:1A,2B,6C,10 FGH');
176 SELECT * FROM ts_stat('SELECT a FROM test_tsvector') ORDER BY ndoc DESC, nentry DESC, word LIMIT 10;
177  word | ndoc | nentry 
178 ------+------+--------
179  qq   |  108 |    108
180  qt   |  102 |    102
181  qe   |  100 |    100
182  qh   |   98 |     98
183  qw   |   98 |     98
184  qa   |   97 |     97
185  ql   |   94 |     94
186  qs   |   94 |     94
187  qi   |   92 |     92
188  qr   |   92 |     92
189 (10 rows)
190
191 SELECT * FROM ts_stat('SELECT a FROM test_tsvector', 'AB') ORDER BY ndoc DESC, nentry DESC, word;
192  word | ndoc | nentry 
193 ------+------+--------
194  DFG  |    1 |      2
195 (1 row)
196
197 --dictionaries and to_tsvector
198 SELECT ts_lexize('english_stem', 'skies');
199  ts_lexize 
200 -----------
201  {sky}
202 (1 row)
203
204 SELECT ts_lexize('english_stem', 'identity');
205  ts_lexize 
206 -----------
207  {ident}
208 (1 row)
209
210 SELECT * FROM ts_token_type('default');
211  tokid |      alias      |               description                
212 -------+-----------------+------------------------------------------
213      1 | asciiword       | Word, all ASCII
214      2 | word            | Word, all letters
215      3 | numword         | Word, letters and digits
216      4 | email           | Email address
217      5 | url             | URL
218      6 | host            | Host
219      7 | sfloat          | Scientific notation
220      8 | version         | Version number
221      9 | hword_numpart   | Hyphenated word part, letters and digits
222     10 | hword_part      | Hyphenated word part, all letters
223     11 | hword_asciipart | Hyphenated word part, all ASCII
224     12 | blank           | Space symbols
225     13 | tag             | XML tag
226     14 | protocol        | Protocol head
227     15 | numhword        | Hyphenated word, letters and digits
228     16 | asciihword      | Hyphenated word, all ASCII
229     17 | hword           | Hyphenated word, all letters
230     18 | url_path        | URL path
231     19 | file            | File or path name
232     20 | float           | Decimal notation
233     21 | int             | Signed integer
234     22 | uint            | Unsigned integer
235     23 | entity          | XML entity
236 (23 rows)
237
238 SELECT * FROM ts_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>">
239 /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
240 <i <b> wow  < jqw <> qwerty');
241  tokid |                token                 
242 -------+--------------------------------------
243     22 | 345
244     12 |  
245      1 | qwe
246     12 | @
247     19 | efd.r
248     12 |  ' 
249     14 | http://
250      6 | www.com
251     12 | / 
252     14 | http://
253      5 | aew.werc.ewr/?ad=qwe&dw
254      6 | aew.werc.ewr
255     18 | /?ad=qwe&dw
256     12 |  
257      5 | 1aew.werc.ewr/?ad=qwe&dw
258      6 | 1aew.werc.ewr
259     18 | /?ad=qwe&dw
260     12 |  
261      6 | 2aew.werc.ewr
262     12 |  
263     14 | http://
264      5 | 3aew.werc.ewr/?ad=qwe&dw
265      6 | 3aew.werc.ewr
266     18 | /?ad=qwe&dw
267     12 |  
268     14 | http://
269      6 | 4aew.werc.ewr
270     12 |  
271     14 | http://
272      6 | 5aew.werc.ewr:8100
273     12 | /?  
274      1 | ad
275     12 | =
276      1 | qwe
277     12 | &
278      1 | dw
279     12 |  
280      5 | 6aew.werc.ewr:8100/?ad=qwe&dw
281      6 | 6aew.werc.ewr:8100
282     18 | /?ad=qwe&dw
283     12 |  
284      5 | 7aew.werc.ewr:8100/?ad=qwe&dw=%20%32
285      6 | 7aew.werc.ewr:8100
286     18 | /?ad=qwe&dw=%20%32
287     12 |  
288      7 | +4.0e-10
289     12 |  
290      1 | qwe
291     12 |  
292      1 | qwe
293     12 |  
294      1 | qwqwe
295     12 |  
296     20 | 234.435
297     12 |  
298     22 | 455
299     12 |  
300     20 | 5.005
301     12 |  
302      4 | teodor@stack.net
303     12 |  
304     16 | qwe-wer
305     11 | qwe
306     12 | -
307     11 | wer
308     12 |  
309      1 | asdf
310     12 |  
311     13 | <fr>
312      1 | qwer
313     12 |  
314      1 | jf
315     12 |  
316      1 | sdjk
317     12 | <
318      1 | we
319     12 |  
320      1 | hjwer
321     12 |  
322     13 | <werrwe>
323     12 |  
324      3 | ewr1
325     12 | > 
326      3 | ewri2
327     12 |  
328     13 | <a href="qwe<qwe>">
329     12 | 
330        : 
331     19 | /usr/local/fff
332     12 |  
333     19 | /awdf/dwqe/4325
334     12 |  
335     19 | rewt/ewr
336     12 |  
337      1 | wefjn
338     12 |  
339     19 | /wqe-324/ewr
340     12 |  
341     19 | gist.h
342     12 |  
343     19 | gist.h.c
344     12 |  
345     19 | gist.c
346     12 | . 
347      1 | readline
348     12 |  
349     20 | 4.2
350     12 |  
351     20 | 4.2
352     12 | . 
353     20 | 4.2
354     12 | , 
355      1 | readline
356     20 | -4.2
357     12 |  
358      1 | readline
359     20 | -4.2
360     12 | . 
361     22 | 234
362     12 | 
363        : 
364     12 | <
365      1 | i
366     12 |  
367     13 | <b>
368     12 |  
369      1 | wow
370     12 |   
371     12 | < 
372      1 | jqw
373     12 |  
374     12 | <> 
375      1 | qwerty
376 (131 rows)
377
378 SELECT to_tsvector('english', '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>">
379 /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
380 <i <b> wow  < jqw <> qwerty');
381                                                                                                                                                                                                                                                                                                                                                                                                                       to_tsvector                                                                                                                                                                                                                                                                                                                                                                                                                       
382 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
383  'ad':17 'dw':19 'jf':39 '234':61 '345':1 '4.2':54,55,56 '455':31 'jqw':64 'qwe':2,18,27,28,35 'wer':36 'wow':63 '-4.2':58,60 'asdf':37 'ewr1':43 'qwer':38 'sdjk':40 '5.005':32 'efd.r':3 'ewri2':44 'hjwer':42 'qwqwe':29 'wefjn':48 'gist.c':52 'gist.h':50 'qwerti':65 '234.435':30 'qwe-wer':34 'readlin':53,57,59 'www.com':4 '+4.0e-10':26 'gist.h.c':51 'rewt/ewr':47 '/?ad=qwe&dw':7,10,14,22 '/wqe-324/ewr':49 'aew.werc.ewr':6 '1aew.werc.ewr':9 '2aew.werc.ewr':11 '3aew.werc.ewr':13 '4aew.werc.ewr':15 '/usr/local/fff':45 '/awdf/dwqe/4325':46 'teodor@stack.net':33 '/?ad=qwe&dw=%20%32':25 '5aew.werc.ewr:8100':16 '6aew.werc.ewr:8100':21 '7aew.werc.ewr:8100':24 'aew.werc.ewr/?ad=qwe&dw':5 '1aew.werc.ewr/?ad=qwe&dw':8 '3aew.werc.ewr/?ad=qwe&dw':12 '6aew.werc.ewr:8100/?ad=qwe&dw':20 '7aew.werc.ewr:8100/?ad=qwe&dw=%20%32':23
384 (1 row)
385
386 SELECT length(to_tsvector('english', '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>">
387 /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
388 <i <b> wow  < jqw <> qwerty'));
389  length 
390 --------
391      51
392 (1 row)
393
394 -- to_tsquery
395 SELECT to_tsquery('english', 'qwe & sKies ');
396   to_tsquery   
397 ---------------
398  'qwe' & 'sky'
399 (1 row)
400
401 SELECT to_tsquery('simple', 'qwe & sKies ');
402    to_tsquery    
403 -----------------
404  'qwe' & 'skies'
405 (1 row)
406
407 SELECT to_tsquery('english', '''the wether'':dc & ''           sKies '':BC ');
408        to_tsquery       
409 ------------------------
410  'wether':CD & 'sky':BC
411 (1 row)
412
413 SELECT to_tsquery('english', 'asd&(and|fghj)');
414    to_tsquery   
415 ----------------
416  'asd' & 'fghj'
417 (1 row)
418
419 SELECT to_tsquery('english', '(asd&and)|fghj');
420    to_tsquery   
421 ----------------
422  'asd' | 'fghj'
423 (1 row)
424
425 SELECT to_tsquery('english', '(asd&!and)|fghj');
426    to_tsquery   
427 ----------------
428  'asd' | 'fghj'
429 (1 row)
430
431 SELECT to_tsquery('english', '(the|and&(i&1))&fghj');
432   to_tsquery  
433 --------------
434  '1' & 'fghj'
435 (1 row)
436
437 SELECT plainto_tsquery('english', 'the and z 1))& fghj');
438   plainto_tsquery   
439 --------------------
440  'z' & '1' & 'fghj'
441 (1 row)
442
443 SELECT plainto_tsquery('english', 'foo bar') && plainto_tsquery('english', 'asd');
444        ?column?        
445 -----------------------
446  'foo' & 'bar' & 'asd'
447 (1 row)
448
449 SELECT plainto_tsquery('english', 'foo bar') || plainto_tsquery('english', 'asd fg');
450            ?column?           
451 ------------------------------
452  'foo' & 'bar' | 'asd' & 'fg'
453 (1 row)
454
455 SELECT plainto_tsquery('english', 'foo bar') || !!plainto_tsquery('english', 'asd fg');
456              ?column?              
457 -----------------------------------
458  'foo' & 'bar' | !( 'asd' & 'fg' )
459 (1 row)
460
461 SELECT plainto_tsquery('english', 'foo bar') && 'asd | fg';
462              ?column?             
463 ----------------------------------
464  'foo' & 'bar' & ( 'asd' | 'fg' )
465 (1 row)
466
467 SELECT ts_rank_cd(to_tsvector('english', 'Erosion It took the sea a thousand years,
468 A thousand years to trace
469 The granite features of this cliff
470 In crag and scarp and base.
471 It took the sea an hour one night
472 An hour of storm to place
473 The sculpture of these granite seams,
474 Upon a woman s face. E.  J.  Pratt  (1882 1964)
475 '), to_tsquery('english', 'sea&thousand&years'));
476  ts_rank_cd 
477 ------------
478   0.0555556
479 (1 row)
480
481 SELECT ts_rank_cd(to_tsvector('english', 'Erosion It took the sea a thousand years,
482 A thousand years to trace
483 The granite features of this cliff
484 In crag and scarp and base.
485 It took the sea an hour one night
486 An hour of storm to place
487 The sculpture of these granite seams,
488 Upon a woman s face. E.  J.  Pratt  (1882 1964)
489 '), to_tsquery('english', 'granite&sea'));
490  ts_rank_cd 
491 ------------
492   0.0238095
493 (1 row)
494
495 SELECT ts_rank_cd(to_tsvector('english', 'Erosion It took the sea a thousand years,
496 A thousand years to trace
497 The granite features of this cliff
498 In crag and scarp and base.
499 It took the sea an hour one night
500 An hour of storm to place
501 The sculpture of these granite seams,
502 Upon a woman s face. E.  J.  Pratt  (1882 1964)
503 '), to_tsquery('english', 'sea'));
504  ts_rank_cd 
505 ------------
506         0.2
507 (1 row)
508
509 --headline tests
510 SELECT ts_headline('english', 'Erosion It took the sea a thousand years,
511 A thousand years to trace
512 The granite features of this cliff
513 In crag and scarp and base.
514 It took the sea an hour one night
515 An hour of storm to place
516 The sculpture of these granite seams,
517 Upon a woman s face. E.  J.  Pratt  (1882 1964)
518 ', to_tsquery('english', 'sea&thousand&years'));
519                 ts_headline                 
520 --------------------------------------------
521  <b>sea</b> a <b>thousand</b> <b>years</b>,
522  A <b>thousand</b> <b>years</b> to trace
523  The granite features of this cliff
524 (1 row)
525
526 SELECT ts_headline('english', 'Erosion It took the sea a thousand years,
527 A thousand years to trace
528 The granite features of this cliff
529 In crag and scarp and base.
530 It took the sea an hour one night
531 An hour of storm to place
532 The sculpture of these granite seams,
533 Upon a woman s face. E.  J.  Pratt  (1882 1964)
534 ', to_tsquery('english', 'granite&sea'));
535                 ts_headline                
536 -------------------------------------------
537  <b>sea</b> a thousand years,
538  A thousand years to trace
539  The <b>granite</b> features of this cliff
540 (1 row)
541
542 SELECT ts_headline('english', 'Erosion It took the sea a thousand years,
543 A thousand years to trace
544 The granite features of this cliff
545 In crag and scarp and base.
546 It took the sea an hour one night
547 An hour of storm to place
548 The sculpture of these granite seams,
549 Upon a woman s face. E.  J.  Pratt  (1882 1964)
550 ', to_tsquery('english', 'sea'));
551             ts_headline             
552 ------------------------------------
553  <b>sea</b> a thousand years,
554  A thousand years to trace
555  The granite features of this cliff
556 (1 row)
557
558 SELECT ts_headline('english', '
559 <html>
560 <!-- some comment -->
561 <body>
562 Sea view wow <u>foo bar</u> <i>qq</i>
563 <a href="http://www.google.com/foo.bar.html" target="_blank">YES &nbsp;</a>
564 ff-bg
565 <script>
566        document.write(15);
567 </script>
568 </body>
569 </html>',
570 to_tsquery('english', 'sea&foo'), 'HighlightAll=true');
571                                  ts_headline                                 
572 -----------------------------------------------------------------------------
573  
574  <html>
575  <!-- some comment -->
576  <body>
577  <b>Sea</b> view wow <u><b>foo</b> bar</u> <i>qq</i>
578  <a href="http://www.google.com/foo.bar.html" target="_blank">YES &nbsp;</a>
579   ff-bg
580  <script>
581         document.write(15);
582  </script>
583  </body>
584  </html>
585 (1 row)
586
587 --Rewrite sub system
588 CREATE TABLE test_tsquery (txtkeyword TEXT, txtsample TEXT);
589 \set ECHO none
590 ALTER TABLE test_tsquery ADD COLUMN keyword tsquery;
591 UPDATE test_tsquery SET keyword = to_tsquery('english', txtkeyword);
592 ALTER TABLE test_tsquery ADD COLUMN sample tsquery;
593 UPDATE test_tsquery SET sample = to_tsquery('english', txtsample::text);
594 SELECT COUNT(*) FROM test_tsquery WHERE keyword <  'new & york';
595  count 
596 -------
597      1
598 (1 row)
599
600 SELECT COUNT(*) FROM test_tsquery WHERE keyword <= 'new & york';
601  count 
602 -------
603      2
604 (1 row)
605
606 SELECT COUNT(*) FROM test_tsquery WHERE keyword = 'new & york';
607  count 
608 -------
609      1
610 (1 row)
611
612 SELECT COUNT(*) FROM test_tsquery WHERE keyword >= 'new & york';
613  count 
614 -------
615      3
616 (1 row)
617
618 SELECT COUNT(*) FROM test_tsquery WHERE keyword >  'new & york';
619  count 
620 -------
621      2
622 (1 row)
623
624 CREATE UNIQUE INDEX bt_tsq ON test_tsquery (keyword);
625 SET enable_seqscan=OFF;
626 SELECT COUNT(*) FROM test_tsquery WHERE keyword <  'new & york';
627  count 
628 -------
629      1
630 (1 row)
631
632 SELECT COUNT(*) FROM test_tsquery WHERE keyword <= 'new & york';
633  count 
634 -------
635      2
636 (1 row)
637
638 SELECT COUNT(*) FROM test_tsquery WHERE keyword = 'new & york';
639  count 
640 -------
641      1
642 (1 row)
643
644 SELECT COUNT(*) FROM test_tsquery WHERE keyword >= 'new & york';
645  count 
646 -------
647      3
648 (1 row)
649
650 SELECT COUNT(*) FROM test_tsquery WHERE keyword >  'new & york';
651  count 
652 -------
653      2
654 (1 row)
655
656 RESET enable_seqscan;
657 SELECT ts_rewrite('foo & bar & qq & new & york',  'new & york'::tsquery, 'big & apple | nyc | new & york & city');
658                                     ts_rewrite                                    
659 ----------------------------------------------------------------------------------
660  'foo' & 'bar' & 'qq' & ( 'city' & 'new' & 'york' | ( 'nyc' | 'big' & 'apple' ) )
661 (1 row)
662
663 SELECT ts_rewrite('moscow', 'SELECT keyword, sample FROM test_tsquery'::text );
664      ts_rewrite      
665 ---------------------
666  'moskva' | 'moscow'
667 (1 row)
668
669 SELECT ts_rewrite('moscow & hotel', 'SELECT keyword, sample FROM test_tsquery'::text );
670             ts_rewrite             
671 -----------------------------------
672  'hotel' & ( 'moskva' | 'moscow' )
673 (1 row)
674
675 SELECT ts_rewrite('bar & new & qq & foo & york', 'SELECT keyword, sample FROM test_tsquery'::text );
676                                      ts_rewrite                                      
677 -------------------------------------------------------------------------------------
678  'citi' & 'foo' & ( 'bar' | 'qq' ) & ( 'nyc' | ( 'big' & 'appl' | 'new' & 'york' ) )
679 (1 row)
680
681 SELECT ts_rewrite( 'moscow', 'SELECT keyword, sample FROM test_tsquery');
682      ts_rewrite      
683 ---------------------
684  'moskva' | 'moscow'
685 (1 row)
686
687 SELECT ts_rewrite( 'moscow & hotel', 'SELECT keyword, sample FROM test_tsquery');
688             ts_rewrite             
689 -----------------------------------
690  'hotel' & ( 'moskva' | 'moscow' )
691 (1 row)
692
693 SELECT ts_rewrite( 'bar & new & qq & foo & york', 'SELECT keyword, sample FROM test_tsquery');
694                                      ts_rewrite                                      
695 -------------------------------------------------------------------------------------
696  'citi' & 'foo' & ( 'bar' | 'qq' ) & ( 'nyc' | ( 'big' & 'appl' | 'new' & 'york' ) )
697 (1 row)
698
699 SELECT keyword FROM test_tsquery WHERE keyword @> 'new';
700     keyword     
701 ----------------
702  'new' & 'york'
703 (1 row)
704
705 SELECT keyword FROM test_tsquery WHERE keyword @> 'moscow';
706  keyword  
707 ----------
708  'moscow'
709 (1 row)
710
711 SELECT keyword FROM test_tsquery WHERE keyword <@ 'new';
712  keyword 
713 ---------
714 (0 rows)
715
716 SELECT keyword FROM test_tsquery WHERE keyword <@ 'moscow';
717  keyword  
718 ----------
719  'moscow'
720 (1 row)
721
722 SELECT ts_rewrite( query, 'SELECT keyword, sample FROM test_tsquery' ) FROM to_tsquery('english', 'moscow') AS query;
723      ts_rewrite      
724 ---------------------
725  'moskva' | 'moscow'
726 (1 row)
727
728 SELECT ts_rewrite( query, 'SELECT keyword, sample FROM test_tsquery' ) FROM to_tsquery('english', 'moscow & hotel') AS query;
729             ts_rewrite             
730 -----------------------------------
731  'hotel' & ( 'moskva' | 'moscow' )
732 (1 row)
733
734 SELECT ts_rewrite( query, 'SELECT keyword, sample FROM test_tsquery' ) FROM to_tsquery('english', 'bar &  new & qq & foo & york') AS query;
735                                      ts_rewrite                                      
736 -------------------------------------------------------------------------------------
737  'citi' & 'foo' & ( 'bar' | 'qq' ) & ( 'nyc' | ( 'big' & 'appl' | 'new' & 'york' ) )
738 (1 row)
739
740 SELECT ts_rewrite( query, 'SELECT keyword, sample FROM test_tsquery' ) FROM to_tsquery('english', 'moscow') AS query;
741      ts_rewrite      
742 ---------------------
743  'moskva' | 'moscow'
744 (1 row)
745
746 SELECT ts_rewrite( query, 'SELECT keyword, sample FROM test_tsquery' ) FROM to_tsquery('english', 'moscow & hotel') AS query;
747             ts_rewrite             
748 -----------------------------------
749  'hotel' & ( 'moskva' | 'moscow' )
750 (1 row)
751
752 SELECT ts_rewrite( query, 'SELECT keyword, sample FROM test_tsquery' ) FROM to_tsquery('english', 'bar & new & qq & foo & york') AS query;
753                                      ts_rewrite                                      
754 -------------------------------------------------------------------------------------
755  'citi' & 'foo' & ( 'bar' | 'qq' ) & ( 'nyc' | ( 'big' & 'appl' | 'new' & 'york' ) )
756 (1 row)
757
758 CREATE INDEX qq ON test_tsquery USING gist (keyword tsquery_ops);
759 SET enable_seqscan=OFF;
760 SELECT keyword FROM test_tsquery WHERE keyword @> 'new';
761     keyword     
762 ----------------
763  'new' & 'york'
764 (1 row)
765
766 SELECT keyword FROM test_tsquery WHERE keyword @> 'moscow';
767  keyword  
768 ----------
769  'moscow'
770 (1 row)
771
772 SELECT keyword FROM test_tsquery WHERE keyword <@ 'new';
773  keyword 
774 ---------
775 (0 rows)
776
777 SELECT keyword FROM test_tsquery WHERE keyword <@ 'moscow';
778  keyword  
779 ----------
780  'moscow'
781 (1 row)
782
783 SELECT ts_rewrite( query, 'SELECT keyword, sample FROM test_tsquery' ) FROM to_tsquery('english', 'moscow') AS query;
784      ts_rewrite      
785 ---------------------
786  'moskva' | 'moscow'
787 (1 row)
788
789 SELECT ts_rewrite( query, 'SELECT keyword, sample FROM test_tsquery' ) FROM to_tsquery('english', 'moscow & hotel') AS query;
790             ts_rewrite             
791 -----------------------------------
792  'hotel' & ( 'moskva' | 'moscow' )
793 (1 row)
794
795 SELECT ts_rewrite( query, 'SELECT keyword, sample FROM test_tsquery' ) FROM to_tsquery('english', 'bar & new & qq & foo & york') AS query;
796                                      ts_rewrite                                      
797 -------------------------------------------------------------------------------------
798  'citi' & 'foo' & ( 'bar' | 'qq' ) & ( 'nyc' | ( 'big' & 'appl' | 'new' & 'york' ) )
799 (1 row)
800
801 SELECT ts_rewrite( query, 'SELECT keyword, sample FROM test_tsquery' ) FROM to_tsquery('english', 'moscow') AS query;
802      ts_rewrite      
803 ---------------------
804  'moskva' | 'moscow'
805 (1 row)
806
807 SELECT ts_rewrite( query, 'SELECT keyword, sample FROM test_tsquery' ) FROM to_tsquery('english', 'moscow & hotel') AS query;
808             ts_rewrite             
809 -----------------------------------
810  'hotel' & ( 'moskva' | 'moscow' )
811 (1 row)
812
813 SELECT ts_rewrite( query, 'SELECT keyword, sample FROM test_tsquery' ) FROM to_tsquery('english', 'bar &  new & qq & foo & york') AS query;
814                                      ts_rewrite                                      
815 -------------------------------------------------------------------------------------
816  'citi' & 'foo' & ( 'bar' | 'qq' ) & ( 'nyc' | ( 'big' & 'appl' | 'new' & 'york' ) )
817 (1 row)
818
819 RESET enable_seqscan;
820 --test GUC
821 SET default_text_search_config=simple;
822 SELECT to_tsvector('SKIES My booKs');
823         to_tsvector         
824 ----------------------------
825  'my':2 'books':3 'skies':1
826 (1 row)
827
828 SELECT plainto_tsquery('SKIES My booKs');
829      plainto_tsquery      
830 --------------------------
831  'skies' & 'my' & 'books'
832 (1 row)
833
834 SELECT to_tsquery('SKIES & My | booKs');
835         to_tsquery        
836 --------------------------
837  'skies' & 'my' | 'books'
838 (1 row)
839
840 SET default_text_search_config=english;
841 SELECT to_tsvector('SKIES My booKs');
842    to_tsvector    
843 ------------------
844  'sky':1 'book':3
845 (1 row)
846
847 SELECT plainto_tsquery('SKIES My booKs');
848  plainto_tsquery 
849 -----------------
850  'sky' & 'book'
851 (1 row)
852
853 SELECT to_tsquery('SKIES & My | booKs');
854    to_tsquery   
855 ----------------
856  'sky' | 'book'
857 (1 row)
858
859 --trigger
860 CREATE TRIGGER tsvectorupdate
861 BEFORE UPDATE OR INSERT ON test_tsvector
862 FOR EACH ROW EXECUTE PROCEDURE tsvector_update_trigger(a, 'pg_catalog.english', t);
863 SELECT count(*) FROM test_tsvector WHERE a @@ to_tsquery('345&qwerty');
864  count 
865 -------
866      0
867 (1 row)
868
869 INSERT INTO test_tsvector (t) VALUES ('345 qwerty');
870 SELECT count(*) FROM test_tsvector WHERE a @@ to_tsquery('345&qwerty');
871  count 
872 -------
873      1
874 (1 row)
875
876 UPDATE test_tsvector SET t = null WHERE t = '345 qwerty';
877 SELECT count(*) FROM test_tsvector WHERE a @@ to_tsquery('345&qwerty');
878  count 
879 -------
880      0
881 (1 row)
882
883 INSERT INTO test_tsvector (t) VALUES ('345 qwerty');
884 SELECT count(*) FROM test_tsvector WHERE a @@ to_tsquery('345&qwerty');
885  count 
886 -------
887      1
888 (1 row)
889