Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Side by Side Diff: third_party/sqlite/src/ext/fts5/test/fts5synonym.test

Issue 2751253002: [sql] Import SQLite 3.17.0. (Closed)
Patch Set: also clang on Linux i386 Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # 2014 Dec 20 1 # 2014 Dec 20
2 # 2 #
3 # The author disclaims copyright to this source code. In place of 3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing: 4 # a legal notice, here is a blessing:
5 # 5 #
6 # May you do good and not evil. 6 # May you do good and not evil.
7 # May you find forgiveness for yourself and forgive others. 7 # May you find forgiveness for yourself and forgive others.
8 # May you share freely, never taking more than you give. 8 # May you share freely, never taking more than you give.
9 # 9 #
10 #*********************************************************************** 10 #***********************************************************************
11 # 11 #
12 # Tests focusing on custom tokenizers that support synonyms. 12 # Tests focusing on custom tokenizers that support synonyms.
13 # 13 #
14 14
15 source [file join [file dirname [info script]] fts5_common.tcl] 15 source [file join [file dirname [info script]] fts5_common.tcl]
16 set testprefix fts5synonym 16 set testprefix fts5synonym
17 17
18 # If SQLITE_ENABLE_FTS5 is defined, omit this file. 18 # If SQLITE_ENABLE_FTS5 is defined, omit this file.
19 ifcapable !fts5 { 19 ifcapable !fts5 {
20 finish_test 20 finish_test
21 return 21 return
22 } 22 }
23 23
24 foreach S { 24 proc tcl_create {args} { return "tcl_tokenize" }
25 {zero 0}
26 {one 1 i}
27 {two 2 ii}
28 {three 3 iii}
29 {four 4 iv}
30 {five 5 v}
31 {six 6 vi}
32 {seven 7 vii}
33 {eight 8 viii}
34 {nine 9 ix}
35 } {
36 foreach s $S {
37 set o [list]
38 foreach x $S {if {$x!=$s} {lappend o $x}}
39 set ::syn($s) $o
40 }
41 }
42 25
43 proc tcl_tokenize {tflags text} { 26 foreach_detail_mode $testprefix {
44 foreach {w iStart iEnd} [fts5_tokenize_split $text] {
45 sqlite3_fts5_token $w $iStart $iEnd
46 }
47 }
48
49 proc tcl_create {args} {
50 return "tcl_tokenize"
51 }
52
53 sqlite3_fts5_create_tokenizer db tcl tcl_create
54 27
55 #------------------------------------------------------------------------- 28 #-------------------------------------------------------------------------
56 # Warm body test for the code in fts5_tcl.c. 29 # Warm body test for the code in fts5_tcl.c.
57 # 30 #
31 fts5_tclnum_register db
58 do_execsql_test 1.0 { 32 do_execsql_test 1.0 {
59 CREATE VIRTUAL TABLE ft USING fts5(x, tokenize = tcl); 33 CREATE VIRTUAL TABLE ft USING fts5(x, tokenize = "tclnum document", detail=%DE TAIL%);
60 INSERT INTO ft VALUES('abc def ghi'); 34 INSERT INTO ft VALUES('abc def ghi');
61 INSERT INTO ft VALUES('jkl mno pqr'); 35 INSERT INTO ft VALUES('jkl mno pqr');
62 SELECT rowid, x FROM ft WHERE ft MATCH 'def'; 36 SELECT rowid, x FROM ft WHERE ft MATCH 'def';
63 SELECT x, rowid FROM ft WHERE ft MATCH 'pqr'; 37 SELECT x, rowid FROM ft WHERE ft MATCH 'pqr';
64 } {1 {abc def ghi} {jkl mno pqr} 2} 38 } {1 {abc def ghi} {jkl mno pqr} 2}
65 39
66 #------------------------------------------------------------------------- 40 #-------------------------------------------------------------------------
67 # Test a tokenizer that supports synonyms by adding extra entries to the 41 # Test a tokenizer that supports synonyms by adding extra entries to the
68 # FTS index. 42 # FTS index.
69 # 43 #
70
71 proc tcl_tokenize {tflags text} {
72 foreach {w iStart iEnd} [fts5_tokenize_split $text] {
73 sqlite3_fts5_token $w $iStart $iEnd
74 if {$tflags=="document" && [info exists ::syn($w)]} {
75 foreach s $::syn($w) {
76 sqlite3_fts5_token -colo $s $iStart $iEnd
77 }
78 }
79 }
80 }
81 reset_db 44 reset_db
82 sqlite3_fts5_create_tokenizer db tcl tcl_create 45 fts5_tclnum_register db
83 46
84 do_execsql_test 2.0 { 47 do_execsql_test 2.0 {
85 CREATE VIRTUAL TABLE ft USING fts5(x, tokenize = tcl); 48 CREATE VIRTUAL TABLE ft USING fts5(
49 x, tokenize = "tclnum document", detail=%DETAIL%
50 );
86 INSERT INTO ft VALUES('one two three'); 51 INSERT INTO ft VALUES('one two three');
87 INSERT INTO ft VALUES('four five six'); 52 INSERT INTO ft VALUES('four five six');
88 INSERT INTO ft VALUES('eight nine ten'); 53 INSERT INTO ft VALUES('eight nine ten');
89 } {} 54 } {}
90 55
91 foreach {tn expr res} { 56 foreach {tn expr res} {
92 1 "3" 1 57 1 "3" 1
93 2 "eight OR 8 OR 5" {2 3} 58 2 "eight OR 8 OR 5" {2 3}
94 3 "10" {} 59 3 "10" {}
95 4 "1*" {1} 60 4 "1*" {1}
96 5 "1 + 2" {1} 61 5 "1 + 2" {1}
97 } { 62 } {
63 if {![fts5_expr_ok $expr ft]} continue
98 do_execsql_test 2.1.$tn { 64 do_execsql_test 2.1.$tn {
99 SELECT rowid FROM ft WHERE ft MATCH $expr 65 SELECT rowid FROM ft WHERE ft MATCH $expr
100 } $res 66 } $res
101 } 67 }
102 68
103 #------------------------------------------------------------------------- 69 #-------------------------------------------------------------------------
104 # Test some broken tokenizers: 70 # Test some broken tokenizers:
105 # 71 #
106 # 3.1.*: A tokenizer that declares the very first token to be colocated. 72 # 3.1.*: A tokenizer that declares the very first token to be colocated.
107 # 73 #
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 SELECT rowid FROM ft WHERE ft MATCH 'one two two three'; 139 SELECT rowid FROM ft WHERE ft MATCH 'one two two three';
174 } {1} 140 } {1}
175 do_execsql_test 3.2.5 { 141 do_execsql_test 3.2.5 {
176 SELECT rowid FROM ft WHERE ft MATCH 'one + two + two + three'; 142 SELECT rowid FROM ft WHERE ft MATCH 'one + two + two + three';
177 } {} 143 } {}
178 144
179 #------------------------------------------------------------------------- 145 #-------------------------------------------------------------------------
180 # Check that expressions with synonyms can be parsed and executed. 146 # Check that expressions with synonyms can be parsed and executed.
181 # 147 #
182 reset_db 148 reset_db
183 sqlite3_fts5_create_tokenizer db tcl tcl_create 149 fts5_tclnum_register db
184 proc tcl_tokenize {tflags text} {
185 foreach {w iStart iEnd} [fts5_tokenize_split $text] {
186 sqlite3_fts5_token $w $iStart $iEnd
187 if {$tflags=="query" && [info exists ::syn($w)]} {
188 foreach s $::syn($w) {
189 sqlite3_fts5_token -colo $s $iStart $iEnd
190 }
191 }
192 }
193 }
194 150
195 foreach {tn expr res} { 151 foreach {tn expr res} {
196 1 {abc} {"abc"} 152 1 {abc} {"abc"}
197 2 {one} {"one"|"i"|"1"} 153 2 {one} {"one"|"i"|"1"}
198 3 {3} {"3"|"iii"|"three"} 154 3 {3} {"3"|"iii"|"three"}
199 4 {3*} {"3"|"iii"|"three" *} 155 4 {3*} {"3" *}
200 } { 156 } {
201 do_execsql_test 4.1.$tn {SELECT fts5_expr($expr, 'tokenize=tcl')} [list $res] 157 do_execsql_test 4.1.$tn {
158 SELECT fts5_expr($expr, 'tokenize=tclnum')
159 } [list $res]
202 } 160 }
203 161
204 do_execsql_test 4.2.1 { 162 do_execsql_test 4.2.1 {
205 CREATE VIRTUAL TABLE xx USING fts5(x, tokenize=tcl); 163 CREATE VIRTUAL TABLE xx USING fts5(x, tokenize=tclnum, detail=%DETAIL%);
206 INSERT INTO xx VALUES('one two'); 164 INSERT INTO xx VALUES('one two');
207 INSERT INTO xx VALUES('three four'); 165 INSERT INTO xx VALUES('three four');
208 } 166 }
209 167
210 do_execsql_test 4.2.2 { 168 do_execsql_test 4.2.2 {
211 SELECT rowid FROM xx WHERE xx MATCH '2' 169 SELECT rowid FROM xx WHERE xx MATCH '2'
212 } {1} 170 } {1}
213 171
214 do_execsql_test 4.2.3 { 172 do_execsql_test 4.2.3 {
215 SELECT rowid FROM xx WHERE xx MATCH '3' 173 SELECT rowid FROM xx WHERE xx MATCH '3'
216 } {2} 174 } {2}
217 175
218 do_test 5.0 { 176 do_test 5.0 {
219 execsql { 177 execsql {
220 CREATE VIRTUAL TABLE t1 USING fts5(a, b, tokenize=tcl) 178 CREATE VIRTUAL TABLE t1 USING fts5(a, b, tokenize=tclnum, detail=%DETAIL%)
221 } 179 }
222 foreach {rowid a b} { 180 foreach {rowid a b} {
223 1 {four v 4 i three} {1 3 five five 4 one} 181 1 {four v 4 i three} {1 3 five five 4 one}
224 2 {5 1 3 4 i} {2 2 v two 4} 182 2 {5 1 3 4 i} {2 2 v two 4}
225 3 {5 i 5 2 four 4 1} {iii ii five two 1} 183 3 {5 i 5 2 four 4 1} {iii ii five two 1}
226 4 {ii four 4 one 5 three five} {one 5 1 iii 4 3} 184 4 {ii four 4 one 5 three five} {one 5 1 iii 4 3}
227 5 {three i v i four 4 1} {ii five five five iii} 185 5 {three i v i four 4 1} {ii five five five iii}
228 6 {4 2 ii two 2 iii} {three 1 four 4 iv 1 iv} 186 6 {4 2 ii two 2 iii} {three 1 four 4 iv 1 iv}
229 7 {ii ii two three 2 5} {iii i ii iii iii one one} 187 7 {ii ii two three 2 5} {iii i ii iii iii one one}
230 8 {2 ii i two 3 three 2} {two iv v iii 3 five} 188 8 {2 ii i two 3 three 2} {two iv v iii 3 five}
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 5 {one + two + three} { 236 5 {one + two + three} {
279 7 {ii ii two three 2 5} {iii [i ii iii] iii one one} 237 7 {ii ii two three 2 5} {iii [i ii iii] iii one one}
280 8 {2 ii [i two 3] three 2} {two iv v iii 3 five} 238 8 {2 ii [i two 3] three 2} {two iv v iii 3 five}
281 } 239 }
282 240
283 6 {"v v"} { 241 6 {"v v"} {
284 1 {four v 4 i three} {1 3 [five five] 4 one} 242 1 {four v 4 i three} {1 3 [five five] 4 one}
285 5 {three i v i four 4 1} {ii [five five five] iii} 243 5 {three i v i four 4 1} {ii [five five five] iii}
286 } 244 }
287 } { 245 } {
246 if {![fts5_expr_ok $q t1]} continue
288 do_execsql_test 5.1.$tn { 247 do_execsql_test 5.1.$tn {
289 SELECT rowid, highlight(t1, 0, '[', ']'), highlight(t1, 1, '[', ']') 248 SELECT rowid, highlight(t1, 0, '[', ']'), highlight(t1, 1, '[', ']')
290 FROM t1 WHERE t1 MATCH $q 249 FROM t1 WHERE t1 MATCH $q
291 } $res 250 } $res
292 } 251 }
293 252
294 # Test that the xQueryPhrase() API works with synonyms. 253 # Test that the xQueryPhrase() API works with synonyms.
295 # 254 #
296 proc mit {blob} { 255 proc mit {blob} {
297 set scan(littleEndian) i* 256 set scan(littleEndian) i*
(...skipping 11 matching lines...) Expand all
309 5 {3 11 7 0 12 6} 6 {0 11 7 2 12 6} 268 5 {3 11 7 0 12 6} 6 {0 11 7 2 12 6}
310 7 {0 11 7 3 12 6} 8 {1 11 7 0 12 6} 269 7 {0 11 7 3 12 6} 8 {1 11 7 0 12 6}
311 9 {1 11 7 2 12 6} 270 9 {1 11 7 2 12 6}
312 } 271 }
313 } { 272 } {
314 do_execsql_test 5.2.$tn { 273 do_execsql_test 5.2.$tn {
315 SELECT rowid, mit(matchinfo(t1, 'x')) FROM t1 WHERE t1 MATCH $q 274 SELECT rowid, mit(matchinfo(t1, 'x')) FROM t1 WHERE t1 MATCH $q
316 } $res 275 } $res
317 } 276 }
318 277
319
320 #------------------------------------------------------------------------- 278 #-------------------------------------------------------------------------
321 # Test terms with more than 4 synonyms. 279 # Test terms with more than 4 synonyms.
322 # 280 #
323 reset_db 281 reset_db
324 sqlite3_fts5_create_tokenizer db tcl tcl_create 282 sqlite3_fts5_create_tokenizer db tcl tcl_create
325 proc tcl_tokenize {tflags text} { 283 proc tcl_tokenize {tflags text} {
326 foreach {w iStart iEnd} [fts5_tokenize_split $text] { 284 foreach {w iStart iEnd} [fts5_tokenize_split $text] {
327 sqlite3_fts5_token $w $iStart $iEnd 285 sqlite3_fts5_token $w $iStart $iEnd
328 if {$tflags=="query" && [string length $w]==1} { 286 if {$tflags=="query" && [string length $w]==1} {
329 for {set i 2} {$i<=10} {incr i} { 287 for {set i 2} {$i<=10} {incr i} {
330 sqlite3_fts5_token -colo [string repeat $w $i] $iStart $iEnd 288 sqlite3_fts5_token -colo [string repeat $w $i] $iStart $iEnd
331 } 289 }
332 } 290 }
333 } 291 }
334 } 292 }
335 293
336 do_execsql_test 6.0.1 { 294 do_execsql_test 6.0.1 {
337 CREATE VIRTUAL TABLE t1 USING fts5(x, tokenize=tcl); 295 CREATE VIRTUAL TABLE t1 USING fts5(x, tokenize=tcl, detail=%DETAIL%);
338 INSERT INTO t1 VALUES('yy xx qq'); 296 INSERT INTO t1 VALUES('yy xx qq');
339 INSERT INTO t1 VALUES('yy xx xx'); 297 INSERT INTO t1 VALUES('yy xx xx');
340 } 298 }
341 do_execsql_test 6.0.2 { 299 if {[fts5_expr_ok "NEAR(y q)" t1]} {
342 SELECT * FROM t1 WHERE t1 MATCH 'NEAR(y q)'; 300 do_execsql_test 6.0.2 {
343 } {{yy xx qq}} 301 SELECT * FROM t1 WHERE t1 MATCH 'NEAR(y q)';
302 } {{yy xx qq}}
303 }
344 304
345 do_test 6.0.3 { 305 do_test 6.0.3 {
346 execsql { 306 execsql {
347 CREATE VIRTUAL TABLE t2 USING fts5(a, b, tokenize=tcl) 307 CREATE VIRTUAL TABLE t2 USING fts5(a, b, tokenize=tcl, detail=%DETAIL%)
348 } 308 }
349 foreach {rowid a b} { 309 foreach {rowid a b} {
350 1 {yyyy vvvvv qq oo yyyyyy vvvv eee} {ffff uu r qq aaaa} 310 1 {yyyy vvvvv qq oo yyyyyy vvvv eee} {ffff uu r qq aaaa}
351 2 {ww oooooo bbbbb ssssss mm} {ffffff yy iiii rr s ccc qqqqq} 311 2 {ww oooooo bbbbb ssssss mm} {ffffff yy iiii rr s ccc qqqqq}
352 3 {zzzz llll gggggg cccc uu} {hhhhhh aaaa ppppp rr ee jjjj} 312 3 {zzzz llll gggggg cccc uu} {hhhhhh aaaa ppppp rr ee jjjj}
353 4 {r f i rrrrrr ww hhh} {aa yyy t x aaaaa ii} 313 4 {r f i rrrrrr ww hhh} {aa yyy t x aaaaa ii}
354 5 {fffff mm vvvv ooo ffffff kkkk tttt} {cccccc bb e zzz d n} 314 5 {fffff mm vvvv ooo ffffff kkkk tttt} {cccccc bb e zzz d n}
355 6 {iii dddd hh qqqq ddd ooo} {ttt d c b aaaaaa qqqq} 315 6 {iii dddd hh qqqq ddd ooo} {ttt d c b aaaaaa qqqq}
356 7 {jjjj rrrr v zzzzz u tt t} {ppppp pp dddd mm hhh uuu} 316 7 {jjjj rrrr v zzzzz u tt t} {ppppp pp dddd mm hhh uuu}
357 8 {gggg rrrrrr kkkk vvvv gggg jjjjjj b} {dddddd jj r w cccc wwwwww ss} 317 8 {gggg rrrrrr kkkk vvvv gggg jjjjjj b} {dddddd jj r w cccc wwwwww ss}
(...skipping 22 matching lines...) Expand all
380 5 {fffff mm vvvv [ooo] ffffff kkkk tttt} {cccccc bb e zzz d n} 340 5 {fffff mm vvvv [ooo] ffffff kkkk tttt} {cccccc bb e zzz d n}
381 6 {iii dddd hh [qqqq] ddd [ooo]} {ttt d c b [aaaaaa] [qqqq]} 341 6 {iii dddd hh [qqqq] ddd [ooo]} {ttt d c b [aaaaaa] [qqqq]}
382 9 {kkkkk qqq [oooo] e tttttt mmm} {e ss qqqqqq hhhh llllll gg} 342 9 {kkkkk qqq [oooo] e tttttt mmm} {e ss qqqqqq hhhh llllll gg}
383 } 343 }
384 344
385 4 {NEAR(q y, 20)} { 345 4 {NEAR(q y, 20)} {
386 1 {[yyyy] vvvvv [qq] oo [yyyyyy] vvvv eee} {ffff uu r qq aaaa} 346 1 {[yyyy] vvvvv [qq] oo [yyyyyy] vvvv eee} {ffff uu r qq aaaa}
387 2 {ww oooooo bbbbb ssssss mm} {ffffff [yy] iiii rr s ccc [qqqqq]} 347 2 {ww oooooo bbbbb ssssss mm} {ffffff [yy] iiii rr s ccc [qqqqq]}
388 } 348 }
389 } { 349 } {
350 if {![fts5_expr_ok $q t2]} continue
351
390 do_execsql_test 6.1.$tn.asc { 352 do_execsql_test 6.1.$tn.asc {
391 SELECT rowid, highlight(t2, 0, '[', ']'), highlight(t2, 1, '[', ']') 353 SELECT rowid, highlight(t2, 0, '[', ']'), highlight(t2, 1, '[', ']')
392 FROM t2 WHERE t2 MATCH $q 354 FROM t2 WHERE t2 MATCH $q
393 } $res 355 } $res
394 356
395 set res2 [list] 357 set res2 [list]
396 foreach {rowid a b} $res { 358 foreach {rowid a b} $res {
397 set res2 [concat [list $rowid $a $b] $res2] 359 set res2 [concat [list $rowid $a $b] $res2]
398 } 360 }
399 361
(...skipping 28 matching lines...) Expand all
428 sqlite3_fts5_token $w $iStart $iEnd 390 sqlite3_fts5_token $w $iStart $iEnd
429 if {[string length $w]==1} { 391 if {[string length $w]==1} {
430 for {set i 2} {$i<=10} {incr i} { 392 for {set i 2} {$i<=10} {incr i} {
431 sqlite3_fts5_token -colo [string repeat $w $i] $iStart $iEnd 393 sqlite3_fts5_token -colo [string repeat $w $i] $iStart $iEnd
432 } 394 }
433 } 395 }
434 } 396 }
435 } 397 }
436 398
437 do_execsql_test 7.0.1 { 399 do_execsql_test 7.0.1 {
438 CREATE VIRTUAL TABLE t1 USING fts5(a, b, columnsize=1, tokenize=tcl); 400 CREATE VIRTUAL TABLE t1 USING fts5(a, b, columnsize=1, tokenize=tcl, detail=%D ETAIL%);
439 INSERT INTO t1 VALUES('0 2 3', '4 5 6 7'); 401 INSERT INTO t1 VALUES('0 2 3', '4 5 6 7');
440 INSERT INTO t1 VALUES('8 9', '0 0 0 0 0 0 0 0 0 0'); 402 INSERT INTO t1 VALUES('8 9', '0 0 0 0 0 0 0 0 0 0');
441 SELECT fts5_test_columnsize(t1) FROM t1 WHERE t1 MATCH '000 AND 00 AND 0'; 403 SELECT fts5_test_columnsize(t1) FROM t1 WHERE t1 MATCH '000 AND 00 AND 0';
442 } {{3 4} {2 10}} 404 } {{3 4} {2 10}}
443 405
444 do_execsql_test 7.0.2 { 406 do_execsql_test 7.0.2 {
445 INSERT INTO t1(t1) VALUES('integrity-check'); 407 INSERT INTO t1(t1) VALUES('integrity-check');
446 } 408 }
447 409
448 do_execsql_test 7.1.1 { 410 do_execsql_test 7.1.1 {
449 CREATE VIRTUAL TABLE t2 USING fts5(a, b, columnsize=0, tokenize=tcl); 411 CREATE VIRTUAL TABLE t2 USING fts5(a, b, columnsize=0, tokenize=tcl, detail=%D ETAIL%);
450 INSERT INTO t2 VALUES('0 2 3', '4 5 6 7'); 412 INSERT INTO t2 VALUES('0 2 3', '4 5 6 7');
451 INSERT INTO t2 VALUES('8 9', '0 0 0 0 0 0 0 0 0 0'); 413 INSERT INTO t2 VALUES('8 9', '0 0 0 0 0 0 0 0 0 0');
452 SELECT fts5_test_columnsize(t2) FROM t2 WHERE t2 MATCH '000 AND 00 AND 0'; 414 SELECT fts5_test_columnsize(t2) FROM t2 WHERE t2 MATCH '000 AND 00 AND 0';
453 } {{3 4} {2 10}} 415 } {{3 4} {2 10}}
454 416
455 do_execsql_test 7.1.2 { 417 do_execsql_test 7.1.2 {
456 INSERT INTO t2(t2) VALUES('integrity-check'); 418 INSERT INTO t2(t2) VALUES('integrity-check');
457 } 419 }
458 420
421 } ;# foreach_detail_mode
422
459 finish_test 423 finish_test
460 424
OLDNEW
« no previous file with comments | « third_party/sqlite/src/ext/fts5/test/fts5simple3.test ('k') | third_party/sqlite/src/ext/fts5/test/fts5synonym2.test » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698