1 --Test text search dictionaries and configurations
2 -- Test ISpell dictionary with ispell affix file
3 CREATE TEXT SEARCH DICTIONARY ispell (
5 DictFile=ispell_sample,
8 SELECT ts_lexize('ispell', 'skies');
14 SELECT ts_lexize('ispell', 'bookings');
20 SELECT ts_lexize('ispell', 'booking');
26 SELECT ts_lexize('ispell', 'foot');
32 SELECT ts_lexize('ispell', 'foots');
38 SELECT ts_lexize('ispell', 'rebookings');
44 SELECT ts_lexize('ispell', 'rebooking');
50 SELECT ts_lexize('ispell', 'rebook');
56 SELECT ts_lexize('ispell', 'unbookings');
62 SELECT ts_lexize('ispell', 'unbooking');
68 SELECT ts_lexize('ispell', 'unbook');
74 SELECT ts_lexize('ispell', 'footklubber');
80 SELECT ts_lexize('ispell', 'footballklubber');
82 ------------------------------------------------------
83 {footballklubber,foot,ball,klubber,football,klubber}
86 SELECT ts_lexize('ispell', 'ballyklubber');
92 SELECT ts_lexize('ispell', 'footballyklubber');
98 -- Test ISpell dictionary with hunspell affix file
99 CREATE TEXT SEARCH DICTIONARY hunspell (
101 DictFile=ispell_sample,
102 AffFile=hunspell_sample
104 SELECT ts_lexize('hunspell', 'skies');
110 SELECT ts_lexize('hunspell', 'bookings');
116 SELECT ts_lexize('hunspell', 'booking');
122 SELECT ts_lexize('hunspell', 'foot');
128 SELECT ts_lexize('hunspell', 'foots');
134 SELECT ts_lexize('hunspell', 'rebookings');
140 SELECT ts_lexize('hunspell', 'rebooking');
146 SELECT ts_lexize('hunspell', 'rebook');
152 SELECT ts_lexize('hunspell', 'unbookings');
158 SELECT ts_lexize('hunspell', 'unbooking');
164 SELECT ts_lexize('hunspell', 'unbook');
170 SELECT ts_lexize('hunspell', 'footklubber');
176 SELECT ts_lexize('hunspell', 'footballklubber');
178 ------------------------------------------------------
179 {footballklubber,foot,ball,klubber,football,klubber}
182 SELECT ts_lexize('hunspell', 'ballyklubber');
188 SELECT ts_lexize('hunspell', 'footballyklubber');
190 ---------------------
194 -- Test ISpell dictionary with hunspell affix file with FLAG long parameter
195 CREATE TEXT SEARCH DICTIONARY hunspell_long (
197 DictFile=hunspell_sample_long,
198 AffFile=hunspell_sample_long
200 SELECT ts_lexize('hunspell_long', 'skies');
206 SELECT ts_lexize('hunspell_long', 'bookings');
212 SELECT ts_lexize('hunspell_long', 'booking');
218 SELECT ts_lexize('hunspell_long', 'foot');
224 SELECT ts_lexize('hunspell_long', 'foots');
230 SELECT ts_lexize('hunspell_long', 'rebookings');
236 SELECT ts_lexize('hunspell_long', 'rebooking');
242 SELECT ts_lexize('hunspell_long', 'rebook');
248 SELECT ts_lexize('hunspell_long', 'unbookings');
254 SELECT ts_lexize('hunspell_long', 'unbooking');
260 SELECT ts_lexize('hunspell_long', 'unbook');
266 SELECT ts_lexize('hunspell_long', 'booked');
272 SELECT ts_lexize('hunspell_long', 'footklubber');
278 SELECT ts_lexize('hunspell_long', 'footballklubber');
280 ------------------------------------------------------
281 {footballklubber,foot,ball,klubber,football,klubber}
284 SELECT ts_lexize('hunspell_long', 'ballyklubber');
290 SELECT ts_lexize('hunspell_long', 'ballsklubber');
296 SELECT ts_lexize('hunspell_long', 'footballyklubber');
298 ---------------------
302 SELECT ts_lexize('hunspell_long', 'ex-machina');
308 -- Test ISpell dictionary with hunspell affix file with FLAG num parameter
309 CREATE TEXT SEARCH DICTIONARY hunspell_num (
311 DictFile=hunspell_sample_num,
312 AffFile=hunspell_sample_num
314 SELECT ts_lexize('hunspell_num', 'skies');
320 SELECT ts_lexize('hunspell_num', 'sk');
326 SELECT ts_lexize('hunspell_num', 'bookings');
332 SELECT ts_lexize('hunspell_num', 'booking');
338 SELECT ts_lexize('hunspell_num', 'foot');
344 SELECT ts_lexize('hunspell_num', 'foots');
350 SELECT ts_lexize('hunspell_num', 'rebookings');
356 SELECT ts_lexize('hunspell_num', 'rebooking');
362 SELECT ts_lexize('hunspell_num', 'rebook');
368 SELECT ts_lexize('hunspell_num', 'unbookings');
374 SELECT ts_lexize('hunspell_num', 'unbooking');
380 SELECT ts_lexize('hunspell_num', 'unbook');
386 SELECT ts_lexize('hunspell_num', 'booked');
392 SELECT ts_lexize('hunspell_num', 'footklubber');
398 SELECT ts_lexize('hunspell_num', 'footballklubber');
400 ------------------------------------------------------
401 {footballklubber,foot,ball,klubber,football,klubber}
404 SELECT ts_lexize('hunspell_num', 'ballyklubber');
410 SELECT ts_lexize('hunspell_num', 'footballyklubber');
412 ---------------------
416 -- Test suitability of affix and dict files
417 CREATE TEXT SEARCH DICTIONARY hunspell_err (
419 DictFile=ispell_sample,
420 AffFile=hunspell_sample_long
422 ERROR: invalid affix alias "GJUS"
423 CREATE TEXT SEARCH DICTIONARY hunspell_err (
425 DictFile=ispell_sample,
426 AffFile=hunspell_sample_num
428 ERROR: invalid affix flag "SZ\"
429 CREATE TEXT SEARCH DICTIONARY hunspell_invalid_1 (
431 DictFile=hunspell_sample_long,
432 AffFile=ispell_sample
434 CREATE TEXT SEARCH DICTIONARY hunspell_invalid_2 (
436 DictFile=hunspell_sample_long,
437 AffFile=hunspell_sample_num
439 CREATE TEXT SEARCH DICTIONARY hunspell_invalid_3 (
441 DictFile=hunspell_sample_num,
442 AffFile=ispell_sample
444 CREATE TEXT SEARCH DICTIONARY hunspell_err (
446 DictFile=hunspell_sample_num,
447 AffFile=hunspell_sample_long
449 ERROR: invalid affix alias "302,301,202,303"
450 -- Synonym dictionary
451 CREATE TEXT SEARCH DICTIONARY synonym (
453 Synonyms=synonym_sample
455 SELECT ts_lexize('synonym', 'PoStGrEs');
461 SELECT ts_lexize('synonym', 'Gogle');
467 SELECT ts_lexize('synonym', 'indices');
473 -- test altering boolean parameters
474 SELECT dictinitoption FROM pg_ts_dict WHERE dictname = 'synonym';
476 -----------------------------
477 synonyms = 'synonym_sample'
480 ALTER TEXT SEARCH DICTIONARY synonym (CaseSensitive = 1);
481 SELECT ts_lexize('synonym', 'PoStGrEs');
487 SELECT dictinitoption FROM pg_ts_dict WHERE dictname = 'synonym';
489 ------------------------------------------------
490 synonyms = 'synonym_sample', casesensitive = 1
493 ALTER TEXT SEARCH DICTIONARY synonym (CaseSensitive = 2); -- fail
494 ERROR: casesensitive requires a Boolean value
495 ALTER TEXT SEARCH DICTIONARY synonym (CaseSensitive = off);
496 SELECT ts_lexize('synonym', 'PoStGrEs');
502 SELECT dictinitoption FROM pg_ts_dict WHERE dictname = 'synonym';
504 ----------------------------------------------------
505 synonyms = 'synonym_sample', casesensitive = 'off'
508 -- Create and simple test thesaurus dictionary
509 -- More tests in configuration checks because ts_lexize()
510 -- cannot pass more than one word to thesaurus.
511 CREATE TEXT SEARCH DICTIONARY thesaurus (
513 DictFile=thesaurus_sample,
514 Dictionary=english_stem
516 SELECT ts_lexize('thesaurus', 'one');
522 -- Test ispell dictionary in configuration
523 CREATE TEXT SEARCH CONFIGURATION ispell_tst (
526 ALTER TEXT SEARCH CONFIGURATION ispell_tst ALTER MAPPING FOR
527 word, numword, asciiword, hword, numhword, asciihword, hword_part, hword_numpart, hword_asciipart
528 WITH ispell, english_stem;
529 SELECT to_tsvector('ispell_tst', 'Booking the skies after rebookings for footballklubber from a foot');
531 ----------------------------------------------------------------------------------------------------
532 'ball':7 'book':1,5 'booking':1,5 'foot':7,10 'football':7 'footballklubber':7 'klubber':7 'sky':3
535 SELECT to_tsquery('ispell_tst', 'footballklubber');
537 --------------------------------------------------------------------------
538 'footballklubber' | 'foot' & 'ball' & 'klubber' | 'football' & 'klubber'
541 SELECT to_tsquery('ispell_tst', 'footballyklubber:b & rebookings:A & sky');
543 ------------------------------------------------------------------------
544 'foot':B & 'ball':B & 'klubber':B & ( 'booking':A | 'book':A ) & 'sky'
547 -- Test ispell dictionary with hunspell affix in configuration
548 CREATE TEXT SEARCH CONFIGURATION hunspell_tst (
551 ALTER TEXT SEARCH CONFIGURATION hunspell_tst ALTER MAPPING
552 REPLACE ispell WITH hunspell;
553 SELECT to_tsvector('hunspell_tst', 'Booking the skies after rebookings for footballklubber from a foot');
555 ----------------------------------------------------------------------------------------------------
556 'ball':7 'book':1,5 'booking':1,5 'foot':7,10 'football':7 'footballklubber':7 'klubber':7 'sky':3
559 SELECT to_tsquery('hunspell_tst', 'footballklubber');
561 --------------------------------------------------------------------------
562 'footballklubber' | 'foot' & 'ball' & 'klubber' | 'football' & 'klubber'
565 SELECT to_tsquery('hunspell_tst', 'footballyklubber:b & rebookings:A & sky');
567 ------------------------------------------------------------------------
568 'foot':B & 'ball':B & 'klubber':B & ( 'booking':A | 'book':A ) & 'sky'
571 SELECT to_tsquery('hunspell_tst', 'footballyklubber:b <-> sky');
573 -------------------------------------------------
574 ( 'foot':B & 'ball':B & 'klubber':B ) <-> 'sky'
577 SELECT phraseto_tsquery('hunspell_tst', 'footballyklubber sky');
579 -------------------------------------------
580 ( 'foot' & 'ball' & 'klubber' ) <-> 'sky'
583 -- Test ispell dictionary with hunspell affix with FLAG long in configuration
584 ALTER TEXT SEARCH CONFIGURATION hunspell_tst ALTER MAPPING
585 REPLACE hunspell WITH hunspell_long;
586 SELECT to_tsvector('hunspell_tst', 'Booking the skies after rebookings for footballklubber from a foot');
588 ----------------------------------------------------------------------------------------------------
589 'ball':7 'book':1,5 'booking':1,5 'foot':7,10 'football':7 'footballklubber':7 'klubber':7 'sky':3
592 SELECT to_tsquery('hunspell_tst', 'footballklubber');
594 --------------------------------------------------------------------------
595 'footballklubber' | 'foot' & 'ball' & 'klubber' | 'football' & 'klubber'
598 SELECT to_tsquery('hunspell_tst', 'footballyklubber:b & rebookings:A & sky');
600 ------------------------------------------------------------------------
601 'foot':B & 'ball':B & 'klubber':B & ( 'booking':A | 'book':A ) & 'sky'
604 -- Test ispell dictionary with hunspell affix with FLAG num in configuration
605 ALTER TEXT SEARCH CONFIGURATION hunspell_tst ALTER MAPPING
606 REPLACE hunspell_long WITH hunspell_num;
607 SELECT to_tsvector('hunspell_tst', 'Booking the skies after rebookings for footballklubber from a foot');
609 ----------------------------------------------------------------------------------------------------
610 'ball':7 'book':1,5 'booking':1,5 'foot':7,10 'football':7 'footballklubber':7 'klubber':7 'sky':3
613 SELECT to_tsquery('hunspell_tst', 'footballklubber');
615 --------------------------------------------------------------------------
616 'footballklubber' | 'foot' & 'ball' & 'klubber' | 'football' & 'klubber'
619 SELECT to_tsquery('hunspell_tst', 'footballyklubber:b & rebookings:A & sky');
621 ------------------------------------------------------------------------
622 'foot':B & 'ball':B & 'klubber':B & ( 'booking':A | 'book':A ) & 'sky'
625 -- Test synonym dictionary in configuration
626 CREATE TEXT SEARCH CONFIGURATION synonym_tst (
629 ALTER TEXT SEARCH CONFIGURATION synonym_tst ALTER MAPPING FOR
630 asciiword, hword_asciipart, asciihword
631 WITH synonym, english_stem;
632 SELECT to_tsvector('synonym_tst', 'Postgresql is often called as postgres or pgsql and pronounced as postgre');
634 ---------------------------------------------------
635 'call':4 'often':3 'pgsql':1,6,8,12 'pronounc':10
638 SELECT to_tsvector('synonym_tst', 'Most common mistake is to write Gogle instead of Google');
640 ----------------------------------------------------------
641 'common':2 'googl':7,10 'instead':8 'mistak':3 'write':6
644 SELECT to_tsvector('synonym_tst', 'Indexes or indices - Which is right plural form of index?');
646 ----------------------------------------------
647 'form':8 'index':1,3,10 'plural':7 'right':6
650 SELECT to_tsquery('synonym_tst', 'Index & indices');
652 ---------------------
656 -- test thesaurus in configuration
657 -- see thesaurus_sample.ths to understand 'odd' resulting tsvector
658 CREATE TEXT SEARCH CONFIGURATION thesaurus_tst (
661 ALTER TEXT SEARCH CONFIGURATION thesaurus_tst ALTER MAPPING FOR
662 asciiword, hword_asciipart, asciihword
663 WITH synonym, thesaurus, english_stem;
664 SELECT to_tsvector('thesaurus_tst', 'one postgres one two one two three one');
666 ----------------------------------
667 '1':1,5 '12':3 '123':4 'pgsql':2
670 SELECT to_tsvector('thesaurus_tst', 'Supernovae star is very new star and usually called supernovae (abbreviation SN)');
672 --------------------------------------------------------------
673 'abbrevi':10 'call':8 'new':4 'sn':1,9,11 'star':5 'usual':7
676 SELECT to_tsvector('thesaurus_tst', 'Booking tickets is looking like a booking a tickets');
678 -------------------------------------------------------
679 'card':3,10 'invit':2,9 'like':6 'look':5 'order':1,8
682 -- invalid: non-lowercase quoted identifiers
683 CREATE TEXT SEARCH DICTIONARY tsdict_case
686 "DictFile" = ispell_sample,
687 "AffFile" = ispell_sample
689 ERROR: unrecognized Ispell parameter: "DictFile"
690 -- Test grammar for configurations
691 CREATE TEXT SEARCH CONFIGURATION dummy_tst (COPY=english);
692 -- Overridden mapping change with duplicated tokens.
693 ALTER TEXT SEARCH CONFIGURATION dummy_tst
694 ALTER MAPPING FOR word, word WITH ispell;
695 -- Not a token supported by the configuration's parser, fails.
696 ALTER TEXT SEARCH CONFIGURATION dummy_tst
697 DROP MAPPING FOR not_a_token, not_a_token;
698 ERROR: token type "not_a_token" does not exist
699 -- Not a token supported by the configuration's parser, fails even
701 ALTER TEXT SEARCH CONFIGURATION dummy_tst
702 DROP MAPPING IF EXISTS FOR not_a_token, not_a_token;
703 ERROR: token type "not_a_token" does not exist
704 -- Token supported by the configuration's parser, succeeds.
705 ALTER TEXT SEARCH CONFIGURATION dummy_tst
706 DROP MAPPING FOR word, word;
707 -- No mapping for token supported by the configuration's parser, fails.
708 ALTER TEXT SEARCH CONFIGURATION dummy_tst
709 DROP MAPPING FOR word;
710 ERROR: mapping for token type "word" does not exist
711 -- Token supported by the configuration's parser, cannot be found,
712 -- succeeds with IF EXISTS.
713 ALTER TEXT SEARCH CONFIGURATION dummy_tst
714 DROP MAPPING IF EXISTS FOR word, word;
715 NOTICE: mapping for token type "word" does not exist, skipping
716 -- Re-add mapping, with duplicated tokens supported by the parser.
717 ALTER TEXT SEARCH CONFIGURATION dummy_tst
718 ADD MAPPING FOR word, word WITH ispell;
719 -- Not a token supported by the configuration's parser, fails.
720 ALTER TEXT SEARCH CONFIGURATION dummy_tst
721 ADD MAPPING FOR not_a_token WITH ispell;
722 ERROR: token type "not_a_token" does not exist
723 DROP TEXT SEARCH CONFIGURATION dummy_tst;