OLD | NEW |
1 # 2010 November 02 | 1 # 2015 August 05 |
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 # This file implements regression tests for the FTS3 module. The focus | |
12 # of this file is tables created with the "matchinfo=fts3" option. | |
13 # | 11 # |
14 | 12 |
15 set testdir [file dirname $argv0] | 13 source [file join [file dirname [info script]] fts5_common.tcl] |
16 source $testdir/tester.tcl | 14 set testprefix fts5matchinfo |
17 | 15 |
18 # If SQLITE_ENABLE_FTS3 is not defined, omit this file. | 16 # If SQLITE_ENABLE_FTS5 is not defined, omit this file. |
19 ifcapable !fts3 { finish_test ; return } | 17 ifcapable !fts5 { finish_test ; return } |
20 | |
21 set testprefix fts3matchinfo | |
22 set sqlite_fts3_enable_parentheses 0 | |
23 | 18 |
24 proc mit {blob} { | 19 proc mit {blob} { |
25 set scan(littleEndian) i* | 20 set scan(littleEndian) i* |
26 set scan(bigEndian) I* | 21 set scan(bigEndian) I* |
27 binary scan $blob $scan($::tcl_platform(byteOrder)) r | 22 binary scan $blob $scan($::tcl_platform(byteOrder)) r |
28 return $r | 23 return $r |
29 } | 24 } |
30 db func mit mit | 25 db func mit mit |
31 | 26 |
| 27 sqlite3_fts5_register_matchinfo db |
| 28 |
32 do_execsql_test 1.0 { | 29 do_execsql_test 1.0 { |
33 CREATE VIRTUAL TABLE t1 USING fts4(matchinfo=fts3); | 30 CREATE VIRTUAL TABLE t1 USING fts5(content); |
34 SELECT name FROM sqlite_master WHERE type = 'table'; | 31 } |
35 } {t1 t1_content t1_segments t1_segdir t1_stat} | |
36 | 32 |
37 do_execsql_test 1.1 { | 33 do_execsql_test 1.1 { |
38 INSERT INTO t1(content) VALUES('I wandered lonely as a cloud'); | 34 INSERT INTO t1(content) VALUES('I wandered lonely as a cloud'); |
39 INSERT INTO t1(content) VALUES('That floats on high o''er vales and hills,'); | 35 INSERT INTO t1(content) VALUES('That floats on high o''er vales and hills,'); |
40 INSERT INTO t1(content) VALUES('When all at once I saw a crowd,'); | 36 INSERT INTO t1(content) VALUES('When all at once I saw a crowd,'); |
41 INSERT INTO t1(content) VALUES('A host, of golden daffodils,'); | 37 INSERT INTO t1(content) VALUES('A host, of golden daffodils,'); |
42 SELECT mit(matchinfo(t1)) FROM t1 WHERE t1 MATCH 'I'; | 38 SELECT mit(matchinfo(t1)) FROM t1 WHERE t1 MATCH 'I'; |
43 } {{1 1 1 2 2} {1 1 1 2 2}} | 39 } {{1 1 1 2 2} {1 1 1 2 2}} |
44 | 40 |
45 # Now create an FTS4 table that does not specify matchinfo=fts3. | 41 # Now create an FTS4 table that does not specify matchinfo=fts3. |
46 # | 42 # |
47 do_execsql_test 1.2 { | 43 do_execsql_test 1.2 { |
48 CREATE VIRTUAL TABLE t2 USING fts4; | 44 CREATE VIRTUAL TABLE t2 USING fts5(content); |
49 INSERT INTO t2 SELECT * FROM t1; | 45 INSERT INTO t2 SELECT * FROM t1; |
50 SELECT mit(matchinfo(t2)) FROM t2 WHERE t2 MATCH 'I'; | 46 SELECT mit(matchinfo(t2)) FROM t2 WHERE t2 MATCH 'I'; |
51 } {{1 1 1 2 2} {1 1 1 2 2}} | 47 } {{1 1 1 2 2} {1 1 1 2 2}} |
52 | 48 |
53 # Test some syntax-error handling. | |
54 # | |
55 do_catchsql_test 2.0 { | |
56 CREATE VIRTUAL TABLE x1 USING fts4(matchinfo=fs3); | |
57 } {1 {unrecognized matchinfo: fs3}} | |
58 do_catchsql_test 2.1 { | |
59 CREATE VIRTUAL TABLE x2 USING fts4(mtchinfo=fts3); | |
60 } {1 {unrecognized parameter: mtchinfo=fts3}} | |
61 do_catchsql_test 2.2 { | |
62 CREATE VIRTUAL TABLE x2 USING fts4(matchinfo=fts5); | |
63 } {1 {unrecognized matchinfo: fts5}} | |
64 | |
65 # Check that with fts3, the "=" character is permitted in column definitions. | |
66 # | |
67 do_execsql_test 3.1 { | |
68 CREATE VIRTUAL TABLE t3 USING fts3(mtchinfo=fts3); | |
69 INSERT INTO t3(mtchinfo) VALUES('Beside the lake, beneath the trees'); | |
70 SELECT mtchinfo FROM t3; | |
71 } {{Beside the lake, beneath the trees}} | |
72 | |
73 do_execsql_test 3.2 { | |
74 CREATE VIRTUAL TABLE xx USING FTS4; | |
75 } | |
76 do_execsql_test 3.3 { | |
77 SELECT * FROM xx WHERE xx MATCH 'abc'; | |
78 } | |
79 do_execsql_test 3.4 { | |
80 SELECT * FROM xx WHERE xx MATCH 'a b c'; | |
81 } | |
82 | |
83 | 49 |
84 #-------------------------------------------------------------------------- | 50 #-------------------------------------------------------------------------- |
85 # Proc [do_matchinfo_test] is used to test the FTSX matchinfo() function. | 51 # Proc [do_matchinfo_test] is used to test the FTSX matchinfo() function. |
86 # | 52 # |
87 # The first argument - $tn - is a test identifier. This may be either a | 53 # The first argument - $tn - is a test identifier. This may be either a |
88 # full identifier (i.e. "fts3matchinfo-1.1") or, if global var $testprefix | 54 # full identifier (i.e. "fts3matchinfo-1.1") or, if global var $testprefix |
89 # is set, just the numeric component (i.e. "1.1"). | 55 # is set, just the numeric component (i.e. "1.1"). |
90 # | 56 # |
91 # The second argument is the name of an FTSX table. The third is the | 57 # The second argument is the name of an FTSX table. The third is the |
92 # full text of a WHERE/MATCH expression to query the table for | 58 # full text of a WHERE/MATCH expression to query the table for |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 proc normalize2 {list_of_lists} { | 144 proc normalize2 {list_of_lists} { |
179 set res [list] | 145 set res [list] |
180 foreach elem $list_of_lists { | 146 foreach elem $list_of_lists { |
181 lappend res [list {*}$elem] | 147 lappend res [list {*}$elem] |
182 } | 148 } |
183 return $res | 149 return $res |
184 } | 150 } |
185 | 151 |
186 | 152 |
187 do_execsql_test 4.1.0 { | 153 do_execsql_test 4.1.0 { |
188 CREATE VIRTUAL TABLE t4 USING fts4(x, y); | 154 CREATE VIRTUAL TABLE t4 USING fts5(x, y); |
189 INSERT INTO t4 VALUES('a b c d e', 'f g h i j'); | 155 INSERT INTO t4 VALUES('a b c d e', 'f g h i j'); |
190 INSERT INTO t4 VALUES('f g h i j', 'a b c d e'); | 156 INSERT INTO t4 VALUES('f g h i j', 'a b c d e'); |
191 } | 157 } |
192 | 158 |
193 do_matchinfo_test 4.1.1 t4 {t4 MATCH 'a b c'} { | 159 do_matchinfo_test 4.1.1 t4 {t4 MATCH 'a b c'} { |
| 160 s {{3 0} {0 3}} |
| 161 } |
| 162 |
| 163 do_matchinfo_test 4.1.1 t4 {t4 MATCH 'a b c'} { |
| 164 p {3 3} |
| 165 x { |
| 166 {1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 0 1 1} |
| 167 {0 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1} |
| 168 } |
| 169 } |
| 170 |
| 171 do_matchinfo_test 4.1.1 t4 {t4 MATCH 'a b c'} { |
194 p {3 3} | 172 p {3 3} |
195 c {2 2} | 173 c {2 2} |
196 x { | 174 x { |
197 {1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 0 1 1} | 175 {1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 0 1 1} |
198 {0 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1} | 176 {0 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1} |
199 } | 177 } |
200 n {2 2} | 178 n {2 2} |
201 l {{5 5} {5 5}} | 179 l {{5 5} {5 5}} |
202 a {{5 5} {5 5}} | 180 a {{5 5} {5 5}} |
203 | 181 |
(...skipping 23 matching lines...) Expand all Loading... |
227 do_matchinfo_test 4.1.3 t4 {t4 MATCH 'a b'} { s {{2 0} {0 2}} } | 205 do_matchinfo_test 4.1.3 t4 {t4 MATCH 'a b'} { s {{2 0} {0 2}} } |
228 do_matchinfo_test 4.1.4 t4 {t4 MATCH '"a b" c'} { s {{2 0} {0 2}} } | 206 do_matchinfo_test 4.1.4 t4 {t4 MATCH '"a b" c'} { s {{2 0} {0 2}} } |
229 do_matchinfo_test 4.1.5 t4 {t4 MATCH 'a "b c"'} { s {{2 0} {0 2}} } | 207 do_matchinfo_test 4.1.5 t4 {t4 MATCH 'a "b c"'} { s {{2 0} {0 2}} } |
230 do_matchinfo_test 4.1.6 t4 {t4 MATCH 'd d'} { s {{1 0} {0 1}} } | 208 do_matchinfo_test 4.1.6 t4 {t4 MATCH 'd d'} { s {{1 0} {0 1}} } |
231 do_matchinfo_test 4.1.7 t4 {t4 MATCH 'f OR abcd'} { | 209 do_matchinfo_test 4.1.7 t4 {t4 MATCH 'f OR abcd'} { |
232 x { | 210 x { |
233 {0 1 1 1 1 1 0 0 0 0 0 0} | 211 {0 1 1 1 1 1 0 0 0 0 0 0} |
234 {1 1 1 0 1 1 0 0 0 0 0 0} | 212 {1 1 1 0 1 1 0 0 0 0 0 0} |
235 } | 213 } |
236 } | 214 } |
237 do_matchinfo_test 4.1.8 t4 {t4 MATCH 'f -abcd'} { | 215 do_matchinfo_test 4.1.8 t4 {t4 MATCH 'f NOT abcd'} { |
238 x { | 216 x { |
239 {0 1 1 1 1 1} | 217 {0 1 1 1 1 1 0 0 0 0 0 0} |
240 {1 1 1 0 1 1} | 218 {1 1 1 0 1 1 0 0 0 0 0 0} |
241 } | 219 } |
242 } | 220 } |
243 | 221 |
244 do_execsql_test 4.2.0 { | 222 do_execsql_test 4.2.0 { |
245 CREATE VIRTUAL TABLE t5 USING fts4; | 223 CREATE VIRTUAL TABLE t5 USING fts5(content); |
246 INSERT INTO t5 VALUES('a a a a a'); | 224 INSERT INTO t5 VALUES('a a a a a'); |
247 INSERT INTO t5 VALUES('a b a b a'); | 225 INSERT INTO t5 VALUES('a b a b a'); |
248 INSERT INTO t5 VALUES('c b c b c'); | 226 INSERT INTO t5 VALUES('c b c b c'); |
249 INSERT INTO t5 VALUES('x x x x x'); | 227 INSERT INTO t5 VALUES('x x x x x'); |
250 } | 228 } |
251 do_matchinfo_test 4.2.1 t5 {t5 MATCH 'a a'} { | 229 do_matchinfo_test 4.2.1 t5 {t5 MATCH 'a a'} { |
252 x {{5 8 2 5 8 2} {3 8 2 3 8 2}} | 230 x {{5 8 2 5 8 2} {3 8 2 3 8 2}} |
253 s {2 1} | 231 s {2 1} |
254 } | 232 } |
255 do_matchinfo_test 4.2.2 t5 {t5 MATCH 'a b'} { s {2} } | 233 do_matchinfo_test 4.2.2 t5 {t5 MATCH 'a b'} { s {2} } |
(...skipping 14 matching lines...) Expand all Loading... |
270 } | 248 } |
271 | 249 |
272 do_matchinfo_test 4.3.2 t5 {t5 MATCH 'a b'} { s {2} } | 250 do_matchinfo_test 4.3.2 t5 {t5 MATCH 'a b'} { s {2} } |
273 do_matchinfo_test 4.3.3 t5 {t5 MATCH 'a b a'} { s {3} } | 251 do_matchinfo_test 4.3.3 t5 {t5 MATCH 'a b a'} { s {3} } |
274 do_matchinfo_test 4.3.4 t5 {t5 MATCH 'a a a'} { s {3 1} } | 252 do_matchinfo_test 4.3.4 t5 {t5 MATCH 'a a a'} { s {3 1} } |
275 do_matchinfo_test 4.3.5 t5 {t5 MATCH '"a b" "a b"'} { s {2} } | 253 do_matchinfo_test 4.3.5 t5 {t5 MATCH '"a b" "a b"'} { s {2} } |
276 do_matchinfo_test 4.3.6 t5 {t5 MATCH 'a OR b'} { s {1 2 1 1} } | 254 do_matchinfo_test 4.3.6 t5 {t5 MATCH 'a OR b'} { s {1 2 1 1} } |
277 | 255 |
278 do_execsql_test 4.4.0.1 { INSERT INTO t5(t5) VALUES('optimize') } | 256 do_execsql_test 4.4.0.1 { INSERT INTO t5(t5) VALUES('optimize') } |
279 | 257 |
280 ifcapable fts4_deferred { | |
281 do_execsql_test 4.4.0.2 { | |
282 UPDATE t5_segments | |
283 SET block = zeroblob(length(block)) | |
284 WHERE length(block)>10000; | |
285 } | |
286 } | |
287 | |
288 do_matchinfo_test 4.4.2 t5 {t5 MATCH 'a b'} { s {2} } | 258 do_matchinfo_test 4.4.2 t5 {t5 MATCH 'a b'} { s {2} } |
289 do_matchinfo_test 4.4.1 t5 {t5 MATCH 'a a'} { s {2 1} } | 259 do_matchinfo_test 4.4.1 t5 {t5 MATCH 'a a'} { s {2 1} } |
290 do_matchinfo_test 4.4.2 t5 {t5 MATCH 'a b'} { s {2} } | 260 do_matchinfo_test 4.4.2 t5 {t5 MATCH 'a b'} { s {2} } |
291 do_matchinfo_test 4.4.3 t5 {t5 MATCH 'a b a'} { s {3} } | 261 do_matchinfo_test 4.4.3 t5 {t5 MATCH 'a b a'} { s {3} } |
292 do_matchinfo_test 4.4.4 t5 {t5 MATCH 'a a a'} { s {3 1} } | 262 do_matchinfo_test 4.4.4 t5 {t5 MATCH 'a a a'} { s {3 1} } |
293 do_matchinfo_test 4.4.5 t5 {t5 MATCH '"a b" "a b"'} { s {2} } | 263 do_matchinfo_test 4.4.5 t5 {t5 MATCH '"a b" "a b"'} { s {2} } |
294 | 264 |
295 do_execsql_test 4.5.0 { | 265 do_execsql_test 4.5.0 { |
296 CREATE VIRTUAL TABLE t6 USING fts4(a, b, c); | 266 CREATE VIRTUAL TABLE t6 USING fts5(a, b, c); |
297 INSERT INTO t6 VALUES('a', 'b', 'c'); | 267 INSERT INTO t6 VALUES('a', 'b', 'c'); |
298 } | 268 } |
299 do_matchinfo_test 4.5.1 t6 {t6 MATCH 'a b c'} { s {{1 1 1}} } | 269 do_matchinfo_test 4.5.1 t6 {t6 MATCH 'a b c'} { s {{1 1 1}} } |
300 | 270 |
301 | 271 |
302 #------------------------------------------------------------------------- | 272 #------------------------------------------------------------------------- |
303 # Check the following restrictions: | |
304 # | |
305 # + Matchinfo flags 'a', 'l' and 'n' can only be used with fts4, not fts3. | |
306 # + Matchinfo flag 'l' cannot be used with matchinfo=fts3. | |
307 # | |
308 do_execsql_test 5.1 { | |
309 CREATE VIRTUAL TABLE t7 USING fts3(a, b); | |
310 INSERT INTO t7 VALUES('u v w', 'x y z'); | |
311 | |
312 CREATE VIRTUAL TABLE t8 USING fts4(a, b, matchinfo=fts3); | |
313 INSERT INTO t8 VALUES('u v w', 'x y z'); | |
314 } | |
315 | |
316 do_catchsql_test 5.2.1 { | |
317 SELECT matchinfo(t7, 'a') FROM t7 WHERE t7 MATCH 'x y' | |
318 } {1 {unrecognized matchinfo request: a}} | |
319 do_catchsql_test 5.2.2 { | |
320 SELECT matchinfo(t7, 'l') FROM t7 WHERE t7 MATCH 'x y' | |
321 } {1 {unrecognized matchinfo request: l}} | |
322 do_catchsql_test 5.2.3 { | |
323 SELECT matchinfo(t7, 'n') FROM t7 WHERE t7 MATCH 'x y' | |
324 } {1 {unrecognized matchinfo request: n}} | |
325 | |
326 do_catchsql_test 5.3.1 { | |
327 SELECT matchinfo(t8, 'l') FROM t8 WHERE t8 MATCH 'x y' | |
328 } {1 {unrecognized matchinfo request: l}} | |
329 | |
330 #------------------------------------------------------------------------- | |
331 # Test that the offsets() function handles corruption in the %_content | |
332 # table correctly. | |
333 # | |
334 do_execsql_test 6.1 { | |
335 CREATE VIRTUAL TABLE t9 USING fts4; | |
336 INSERT INTO t9 VALUES( | |
337 'this record is used to try to dectect corruption' | |
338 ); | |
339 SELECT offsets(t9) FROM t9 WHERE t9 MATCH 'to'; | |
340 } {{0 0 20 2 0 0 27 2}} | |
341 | |
342 do_catchsql_test 6.2 { | |
343 UPDATE t9_content SET c0content = 'this record is used to'; | |
344 SELECT offsets(t9) FROM t9 WHERE t9 MATCH 'to'; | |
345 } {1 {database disk image is malformed}} | |
346 | |
347 #------------------------------------------------------------------------- | |
348 # Test the outcome of matchinfo() when used within a query that does not | 273 # Test the outcome of matchinfo() when used within a query that does not |
349 # use the full-text index (i.e. lookup by rowid or full-table scan). | 274 # use the full-text index (i.e. lookup by rowid or full-table scan). |
350 # | 275 # |
351 do_execsql_test 7.1 { | 276 do_execsql_test 7.1 { |
352 CREATE VIRTUAL TABLE t10 USING fts4; | 277 CREATE VIRTUAL TABLE t10 USING fts5(content); |
353 INSERT INTO t10 VALUES('first record'); | 278 INSERT INTO t10 VALUES('first record'); |
354 INSERT INTO t10 VALUES('second record'); | 279 INSERT INTO t10 VALUES('second record'); |
355 } | 280 } |
356 do_execsql_test 7.2 { | 281 do_execsql_test 7.2 { |
357 SELECT typeof(matchinfo(t10)), length(matchinfo(t10)) FROM t10; | 282 SELECT typeof(matchinfo(t10)), length(matchinfo(t10)) FROM t10; |
358 } {blob 0 blob 0} | 283 } {blob 8 blob 8} |
359 do_execsql_test 7.3 { | 284 do_execsql_test 7.3 { |
360 SELECT typeof(matchinfo(t10)), length(matchinfo(t10)) FROM t10 WHERE docid=1; | 285 SELECT typeof(matchinfo(t10)), length(matchinfo(t10)) FROM t10 WHERE rowid=1; |
361 } {blob 0} | 286 } {blob 8} |
362 do_execsql_test 7.4 { | 287 do_execsql_test 7.4 { |
363 SELECT typeof(matchinfo(t10)), length(matchinfo(t10)) | 288 SELECT typeof(matchinfo(t10)), length(matchinfo(t10)) |
364 FROM t10 WHERE t10 MATCH 'record' | 289 FROM t10 WHERE t10 MATCH 'record' |
365 } {blob 20 blob 20} | 290 } {blob 20 blob 20} |
366 | 291 |
367 #------------------------------------------------------------------------- | 292 #------------------------------------------------------------------------- |
368 # Test a special case - matchinfo('nxa') with many zero length documents. | 293 # Test a special case - matchinfo('nxa') with many zero length documents. |
369 # Special because "x" internally uses a statement used by both "n" and "a". | 294 # Special because "x" internally uses a statement used by both "n" and "a". |
370 # This was causing a problem at one point in the obscure case where the | 295 # This was causing a problem at one point in the obscure case where the |
371 # total number of bytes of data stored in an fts3 table was greater than | 296 # total number of bytes of data stored in an fts3 table was greater than |
372 # the number of rows. i.e. when the following query returns true: | 297 # the number of rows. i.e. when the following query returns true: |
373 # | 298 # |
374 # SELECT sum(length(content)) < count(*) FROM fts4table; | 299 # SELECT sum(length(content)) < count(*) FROM fts4table; |
375 # | 300 # |
376 do_execsql_test 8.1 { | 301 do_execsql_test 8.1 { |
377 CREATE VIRTUAL TABLE t11 USING fts4; | 302 CREATE VIRTUAL TABLE t11 USING fts5(content); |
378 INSERT INTO t11(t11) VALUES('nodesize=24'); | 303 INSERT INTO t11(t11, rank) VALUES('pgsz', 32); |
379 INSERT INTO t11 VALUES('quitealongstringoftext'); | 304 INSERT INTO t11 VALUES('quitealongstringoftext'); |
380 INSERT INTO t11 VALUES('anotherquitealongstringoftext'); | 305 INSERT INTO t11 VALUES('anotherquitealongstringoftext'); |
381 INSERT INTO t11 VALUES('athirdlongstringoftext'); | 306 INSERT INTO t11 VALUES('athirdlongstringoftext'); |
382 INSERT INTO t11 VALUES('andonemoreforgoodluck'); | 307 INSERT INTO t11 VALUES('andonemoreforgoodluck'); |
383 } | 308 } |
384 do_test 8.2 { | 309 do_test 8.2 { |
385 for {set i 0} {$i < 200} {incr i} { | 310 for {set i 0} {$i < 200} {incr i} { |
386 execsql { INSERT INTO t11 VALUES('') } | 311 execsql { INSERT INTO t11 VALUES('') } |
387 } | 312 } |
388 execsql { INSERT INTO t11(t11) VALUES('optimize') } | 313 execsql { INSERT INTO t11(t11) VALUES('optimize') } |
389 } {} | 314 } {} |
390 do_execsql_test 8.3 { | 315 do_execsql_test 8.3 { |
391 SELECT mit(matchinfo(t11, 'nxa')) FROM t11 WHERE t11 MATCH 'a*' | 316 SELECT mit(matchinfo(t11, 'nxa')) FROM t11 WHERE t11 MATCH 'a*' |
392 } {{204 1 3 3 0} {204 1 3 3 0} {204 1 3 3 0}} | 317 } {{204 1 3 3 0} {204 1 3 3 0} {204 1 3 3 0}} |
393 | 318 |
394 # Corruption related tests. | |
395 do_execsql_test 8.4.1.1 { UPDATE t11_stat SET value = X'0000'; } | |
396 do_catchsql_test 8.5.1.2 { | |
397 SELECT mit(matchinfo(t11, 'nxa')) FROM t11 WHERE t11 MATCH 'a*' | |
398 } {1 {database disk image is malformed}} | |
399 | |
400 do_execsql_test 8.4.2.1 { UPDATE t11_stat SET value = X'00'; } | |
401 do_catchsql_test 8.5.2.2 { | |
402 SELECT mit(matchinfo(t11, 'nxa')) FROM t11 WHERE t11 MATCH 'a*' | |
403 } {1 {database disk image is malformed}} | |
404 | |
405 do_execsql_test 8.4.3.1 { UPDATE t11_stat SET value = NULL; } | |
406 do_catchsql_test 8.5.3.2 { | |
407 SELECT mit(matchinfo(t11, 'nxa')) FROM t11 WHERE t11 MATCH 'a*' | |
408 } {1 {database disk image is malformed}} | |
409 | |
410 #------------------------------------------------------------------------- | 319 #------------------------------------------------------------------------- |
411 do_execsql_test 8.1 { | |
412 CREATE VIRTUAL TABLE t12 USING fts4; | |
413 INSERT INTO t12 VALUES('a b c d'); | |
414 SELECT mit(matchinfo(t12, 'x')) FROM t12 WHERE t12 MATCH 'a NEAR/1 d OR a'; | |
415 } {{0 0 0 0 0 0 1 1 1}} | |
416 do_execsql_test 8.2 { | |
417 INSERT INTO t12 VALUES('a d c d'); | |
418 SELECT mit(matchinfo(t12, 'x')) FROM t12 WHERE t12 MATCH 'a NEAR/1 d OR a'; | |
419 } { | |
420 {0 1 1 0 1 1 1 2 2} {1 1 1 1 1 1 1 2 2} | |
421 } | |
422 do_execsql_test 8.3 { | |
423 INSERT INTO t12 VALUES('a d d a'); | |
424 SELECT mit(matchinfo(t12, 'x')) FROM t12 WHERE t12 MATCH 'a NEAR/1 d OR a'; | |
425 } { | |
426 {0 3 2 0 3 2 1 4 3} {1 3 2 1 3 2 1 4 3} {2 3 2 2 3 2 2 4 3} | |
427 } | |
428 | 320 |
429 do_execsql_test 9.1 { | 321 do_execsql_test 9.1 { |
430 CREATE VIRTUAL TABLE ft2 USING fts4; | 322 CREATE VIRTUAL TABLE t12 USING fts5(content); |
431 INSERT INTO ft2 VALUES('a b c d e'); | 323 INSERT INTO t12 VALUES('a b c d'); |
432 INSERT INTO ft2 VALUES('f a b c d'); | 324 SELECT mit(matchinfo(t12, 'x')) FROM t12 WHERE t12 MATCH 'NEAR(a d, 1) OR a'; |
433 SELECT snippet(ft2, '[', ']', '', -1, 1) FROM ft2 WHERE ft2 MATCH 'c'; | 325 } {{0 1 1 0 1 1 1 1 1}} |
434 } {{[c]} {[c]}} | 326 do_execsql_test 9.2 { |
| 327 INSERT INTO t12 VALUES('a d c d'); |
| 328 SELECT mit(matchinfo(t12, 'x')) FROM t12 WHERE t12 MATCH 'NEAR(a d, 1) OR a'; |
| 329 } { |
| 330 {0 2 2 0 3 2 1 2 2} {1 2 2 1 3 2 1 2 2} |
| 331 } |
| 332 do_execsql_test 9.3 { |
| 333 INSERT INTO t12 VALUES('a d d a'); |
| 334 SELECT mit(matchinfo(t12, 'x')) FROM t12 WHERE t12 MATCH 'NEAR(a d, 1) OR a'; |
| 335 } { |
| 336 {0 4 3 0 5 3 1 4 3} {1 4 3 1 5 3 1 4 3} {2 4 3 2 5 3 2 4 3} |
| 337 } |
435 | 338 |
436 #--------------------------------------------------------------------------- | 339 #--------------------------------------------------------------------------- |
437 # Test for a memory leak | 340 # Test for a memory leak |
438 # | 341 # |
439 do_execsql_test 10.1 { | 342 do_execsql_test 10.1 { |
440 DROP TABLE t10; | 343 DROP TABLE t10; |
441 CREATE VIRTUAL TABLE t10 USING fts4(idx, value); | 344 CREATE VIRTUAL TABLE t10 USING fts5(idx, value); |
442 INSERT INTO t10 values (1, 'one'),(2, 'two'),(3, 'three'); | 345 INSERT INTO t10 values (1, 'one'),(2, 'two'),(3, 'three'); |
443 SELECT docId, t10.* | 346 SELECT t10.rowid, t10.* |
444 FROM t10 | 347 FROM t10 |
445 JOIN (SELECT 1 AS idx UNION SELECT 2 UNION SELECT 3) AS x | 348 JOIN (SELECT 1 AS idx UNION SELECT 2 UNION SELECT 3) AS x |
446 WHERE t10 MATCH x.idx | 349 WHERE t10 MATCH x.idx |
447 AND matchinfo(t10) not null | 350 AND matchinfo(t10) not null |
448 GROUP BY docId | 351 GROUP BY t10.rowid |
449 ORDER BY 1; | 352 ORDER BY 1; |
450 } {1 1 one 2 2 two 3 3 three} | 353 } {1 1 one 2 2 two 3 3 three} |
451 | 354 |
| 355 #--------------------------------------------------------------------------- |
| 356 # Test the 'y' matchinfo flag |
| 357 # |
| 358 reset_db |
| 359 sqlite3_fts5_register_matchinfo db |
| 360 do_execsql_test 11.0 { |
| 361 CREATE VIRTUAL TABLE tt USING fts5(x, y); |
| 362 INSERT INTO tt VALUES('c d a c d d', 'e a g b d a'); -- 1 |
| 363 INSERT INTO tt VALUES('c c g a e b', 'c g d g e c'); -- 2 |
| 364 INSERT INTO tt VALUES('b e f d e g', 'b a c b c g'); -- 3 |
| 365 INSERT INTO tt VALUES('a c f f g d', 'd b f d e g'); -- 4 |
| 366 INSERT INTO tt VALUES('g a c f c f', 'd g g b c c'); -- 5 |
| 367 INSERT INTO tt VALUES('g a c e b b', 'd b f b g g'); -- 6 |
| 368 INSERT INTO tt VALUES('f d a a f c', 'e e a d c f'); -- 7 |
| 369 INSERT INTO tt VALUES('a c b b g f', 'a b a e d f'); -- 8 |
| 370 INSERT INTO tt VALUES('b a f e c c', 'f d b b a b'); -- 9 |
| 371 INSERT INTO tt VALUES('f d c e a c', 'f a f a a f'); -- 10 |
| 372 } |
| 373 |
| 374 db func mit mit |
| 375 foreach {tn expr res} { |
| 376 1 "a" { |
| 377 1 {1 2} 2 {1 0} 3 {0 1} 4 {1 0} 5 {1 0} |
| 378 6 {1 0} 7 {2 1} 8 {1 2} 9 {1 1} 10 {1 3} |
| 379 } |
| 380 |
| 381 2 "b" { |
| 382 1 {0 1} 2 {1 0} 3 {1 2} 4 {0 1} 5 {0 1} |
| 383 6 {2 2} 8 {2 1} 9 {1 3} |
| 384 } |
| 385 |
| 386 3 "y:a" { |
| 387 1 {0 2} 3 {0 1} |
| 388 7 {0 1} 8 {0 2} 9 {0 1} 10 {0 3} |
| 389 } |
| 390 |
| 391 4 "x:a" { |
| 392 1 {1 0} 2 {1 0} 4 {1 0} 5 {1 0} |
| 393 6 {1 0} 7 {2 0} 8 {1 0} 9 {1 0} 10 {1 0} |
| 394 } |
| 395 |
| 396 5 "a OR b" { |
| 397 1 {1 2 0 1} 2 {1 0 1 0} 3 {0 1 1 2} 4 {1 0 0 1} 5 {1 0 0 1} |
| 398 6 {1 0 2 2} 7 {2 1 0 0} 8 {1 2 2 1} 9 {1 1 1 3} 10 {1 3 0 0} |
| 399 } |
| 400 |
| 401 6 "a AND b" { |
| 402 1 {1 2 0 1} 2 {1 0 1 0} 3 {0 1 1 2} 4 {1 0 0 1} 5 {1 0 0 1} |
| 403 6 {1 0 2 2} 8 {1 2 2 1} 9 {1 1 1 3} |
| 404 } |
| 405 |
| 406 7 "a OR (a AND b)" { |
| 407 1 {1 2 1 2 0 1} 2 {1 0 1 0 1 0} 3 {0 1 0 1 1 2} 4 {1 0 1 0 0 1} |
| 408 5 {1 0 1 0 0 1} 6 {1 0 1 0 2 2} 7 {2 1 0 0 0 0} 8 {1 2 1 2 2 1} |
| 409 9 {1 1 1 1 1 3} 10 {1 3 0 0 0 0} |
| 410 } |
| 411 |
| 412 } { |
| 413 do_execsql_test 11.1.$tn.1 { |
| 414 SELECT rowid, mit(matchinfo(tt, 'y')) FROM tt WHERE tt MATCH $expr |
| 415 } $res |
| 416 |
| 417 set r2 [list] |
| 418 foreach {rowid L} $res { |
| 419 lappend r2 $rowid |
| 420 set M [list] |
| 421 foreach {a b} $L { |
| 422 lappend M [expr ($a ? 1 : 0) + ($b ? 2 : 0)] |
| 423 } |
| 424 lappend r2 $M |
| 425 } |
| 426 |
| 427 do_execsql_test 11.1.$tn.2 { |
| 428 SELECT rowid, mit(matchinfo(tt, 'b')) FROM tt WHERE tt MATCH $expr |
| 429 } $r2 |
| 430 |
| 431 do_execsql_test 11.1.$tn.2 { |
| 432 SELECT rowid, mit(matchinfo(tt, 'b')) FROM tt WHERE tt MATCH $expr |
| 433 } $r2 |
| 434 } |
| 435 |
| 436 #--------------------------------------------------------------------------- |
| 437 # Test the 'b' matchinfo flag |
| 438 # |
| 439 reset_db |
| 440 sqlite3_fts5_register_matchinfo db |
| 441 db func mit mit |
| 442 |
| 443 do_test 12.0 { |
| 444 set cols [list] |
| 445 for {set i 0} {$i < 50} {incr i} { lappend cols "c$i" } |
| 446 execsql "CREATE VIRTUAL TABLE tt USING fts5([join $cols ,])" |
| 447 } {} |
| 448 |
| 449 do_execsql_test 12.1 { |
| 450 INSERT INTO tt (rowid, c4, c45) VALUES(1, 'abc', 'abc'); |
| 451 SELECT mit(matchinfo(tt, 'b')) FROM tt WHERE tt MATCH 'abc'; |
| 452 } [list [list [expr 1<<4] [expr 1<<(45-32)]]] |
452 | 453 |
453 finish_test | 454 finish_test |
| 455 |
OLD | NEW |