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 -- Synonim dictionary
195 CREATE TEXT SEARCH DICTIONARY synonym (
197 Synonyms=synonym_sample
199 SELECT ts_lexize('synonym', 'PoStGrEs');
205 SELECT ts_lexize('synonym', 'Gogle');
211 -- Create and simple test thesaurus dictionary
212 -- More tests in configuration checks because ts_lexize()
213 -- cannot pass more than one word to thesaurus.
214 CREATE TEXT SEARCH DICTIONARY thesaurus (
216 DictFile=thesaurus_sample,
217 Dictionary=english_stem
219 SELECT ts_lexize('thesaurus', 'one');
225 -- Test ispell dictionary in configuration
226 CREATE TEXT SEARCH CONFIGURATION ispell_tst (
229 ALTER TEXT SEARCH CONFIGURATION ispell_tst ALTER MAPPING FOR
230 word, numword, asciiword, hword, numhword, asciihword, hword_part, hword_numpart, hword_asciipart
231 WITH ispell, english_stem;
232 SELECT to_tsvector('ispell_tst', 'Booking the skies after rebookings for footballklubber from a foot');
234 ----------------------------------------------------------------------------------------------------
235 'ball':7 'book':1,5 'booking':1,5 'foot':7,10 'football':7 'footballklubber':7 'klubber':7 'sky':3
238 SELECT to_tsquery('ispell_tst', 'footballklubber');
240 ------------------------------------------------------------------------------
241 ( 'footballklubber' | 'foot' & 'ball' & 'klubber' ) | 'football' & 'klubber'
244 SELECT to_tsquery('ispell_tst', 'footballyklubber:b & rebookings:A & sky');
246 ------------------------------------------------------------------------
247 'foot':B & 'ball':B & 'klubber':B & ( 'booking':A | 'book':A ) & 'sky'
250 -- Test ispell dictionary with hunspell affix in configuration
251 CREATE TEXT SEARCH CONFIGURATION hunspell_tst (
254 ALTER TEXT SEARCH CONFIGURATION hunspell_tst ALTER MAPPING
255 REPLACE ispell WITH hunspell;
256 SELECT to_tsvector('hunspell_tst', 'Booking the skies after rebookings for footballklubber from a foot');
258 ----------------------------------------------------------------------------------------------------
259 'ball':7 'book':1,5 'booking':1,5 'foot':7,10 'football':7 'footballklubber':7 'klubber':7 'sky':3
262 SELECT to_tsquery('hunspell_tst', 'footballklubber');
264 ------------------------------------------------------------------------------
265 ( 'footballklubber' | 'foot' & 'ball' & 'klubber' ) | 'football' & 'klubber'
268 SELECT to_tsquery('hunspell_tst', 'footballyklubber:b & rebookings:A & sky');
270 ------------------------------------------------------------------------
271 'foot':B & 'ball':B & 'klubber':B & ( 'booking':A | 'book':A ) & 'sky'
274 -- Test synonym dictionary in configuration
275 CREATE TEXT SEARCH CONFIGURATION synonym_tst (
278 ALTER TEXT SEARCH CONFIGURATION synonym_tst ALTER MAPPING FOR
279 asciiword, hword_asciipart, asciihword
280 WITH synonym, english_stem;
281 SELECT to_tsvector('synonym_tst', 'Postgresql is often called as postgres or pgsql and pronounced as postgre');
283 ---------------------------------------------------
284 'call':4 'often':3 'pgsql':1,6,8,12 'pronounc':10
287 SELECT to_tsvector('synonym_tst', 'Most common mistake is to write Gogle instead of Google');
289 ----------------------------------------------------------
290 'common':2 'googl':7,10 'instead':8 'mistak':3 'write':6
293 -- test thesaurus in configuration
294 -- see thesaurus_sample.ths to understand 'odd' resulting tsvector
295 CREATE TEXT SEARCH CONFIGURATION thesaurus_tst (
298 ALTER TEXT SEARCH CONFIGURATION thesaurus_tst ALTER MAPPING FOR
299 asciiword, hword_asciipart, asciihword
300 WITH synonym, thesaurus, english_stem;
301 SELECT to_tsvector('thesaurus_tst', 'one postgres one two one two three one');
303 ----------------------------------
304 '1':1,5 '12':3 '123':4 'pgsql':2
307 SELECT to_tsvector('thesaurus_tst', 'Supernovae star is very new star and usually called supernovae (abbrevation SN)');
309 -------------------------------------------------------------
310 'abbrev':10 'call':8 'new':4 'sn':1,9,11 'star':5 'usual':7
313 SELECT to_tsvector('thesaurus_tst', 'Booking tickets is looking like a booking a tickets');
315 -------------------------------------------------------
316 'card':3,10 'invit':2,9 'like':6 'look':5 'order':1,8