1# 2010 October 23 2# 3# The author disclaims copyright to this source code. In place of 4# a legal notice, here is a blessing: 5# 6# May you do good and not evil. 7# May you find forgiveness for yourself and forgive others. 8# May you share freely, never taking more than you give. 9# 10#*********************************************************************** 11# 12 13set testdir [file dirname $argv0] 14source $testdir/tester.tcl 15source $testdir/malloc_common.tcl 16ifcapable !fts3 { finish_test ; return } 17 18set testprefix fts3defer2 19 20proc mit {blob} { 21 set scan(littleEndian) i* 22 set scan(bigEndian) I* 23 binary scan $blob $scan($::tcl_platform(byteOrder)) r 24 return $r 25} 26db func mit mit 27 28#----------------------------------------------------------------------------- 29# This block of tests - fts3defer2-1.* - test the interaction of deferred NEAR 30# expressions and the snippet, offsets and matchinfo functions. 31# 32do_execsql_test 1.1.1 { 33 CREATE VIRTUAL TABLE t1 USING fts4; 34} 35do_execsql_test 1.1.2 "INSERT INTO t1 VALUES('[string repeat {a } 20000]')" 36do_execsql_test 1.1.3 "INSERT INTO t1 VALUES('[string repeat {z } 20000]')" 37do_execsql_test 1.1.4 { 38 INSERT INTO t1 VALUES('a b c d e f a x y'); 39 INSERT INTO t1 VALUES(''); 40 INSERT INTO t1 VALUES(''); 41 INSERT INTO t1 VALUES(''); 42 INSERT INTO t1 VALUES(''); 43 INSERT INTO t1 VALUES(''); 44 INSERT INTO t1(t1) VALUES('optimize'); 45} 46do_execsql_test 1.1.4 { 47 SELECT count(*) FROM t1_segments WHERE length(block)>10000; 48 UPDATE t1_segments SET block = zeroblob(length(block)) WHERE length(block)>10000; 49} {2} 50 51do_execsql_test 1.2.1 { 52 SELECT content FROM t1 WHERE t1 MATCH 'f (e NEAR/2 a)'; 53} {{a b c d e f a x y}} 54 55do_execsql_test 1.2.2 { 56 SELECT snippet(t1, '[', ']'), offsets(t1), mit(matchinfo(t1, 'pcxnal')) 57 FROM t1 WHERE t1 MATCH 'f (e NEAR/2 a)'; 58} [list \ 59 {a b c d [e] [f] [a] x y} \ 60 {0 1 8 1 0 0 10 1 0 2 12 1} \ 61 [list 3 1 1 1 1 1 8 8 1 8 8 8 5001 9] 62] 63 64do_execsql_test 1.2.3 { 65 SELECT snippet(t1, '[', ']'), offsets(t1), mit(matchinfo(t1, 'pcxnal')) 66 FROM t1 WHERE t1 MATCH 'f (e NEAR/3 a)'; 67} [list \ 68 {[a] b c d [e] [f] [a] x y} \ 69 {0 2 0 1 0 1 8 1 0 0 10 1 0 2 12 1} \ 70 [list 3 1 1 1 1 1 8 8 2 8 8 8 5001 9] 71] 72 73do_execsql_test 1.3.1 { DROP TABLE t1 } 74 75#----------------------------------------------------------------------------- 76# Test cases fts3defer2-2.* focus specifically on the matchinfo function. 77# 78do_execsql_test 2.1.1 "CREATE VIRTUAL TABLE t2 USING fts4" 79do_execsql_test 2.1.2 "INSERT INTO t2 VALUES('[string repeat {a } 10000]')" 80do_execsql_test 2.1.3 "INSERT INTO t2 VALUES('b [string repeat {z } 10000]')" 81do_execsql_test 2.1.4 [string repeat "INSERT INTO t2 VALUES('x');" 50] 82do_execsql_test 2.1.5 { 83 INSERT INTO t2 VALUES('a b c d e f g z'); 84 INSERT INTO t2 VALUES('a b c d e f g'); 85} 86foreach {tn sql} { 87 1 {} 88 2 { INSERT INTO t2(t2) VALUES('optimize') } 89 3 { UPDATE t2_segments SET block = zeroblob(length(block)) 90 WHERE length(block)>10000; 91 } 92} { 93 execsql $sql 94 95 do_execsql_test 2.2.$tn.1 { 96 SELECT mit(matchinfo(t2, 'pcxnal')) FROM t2 WHERE t2 MATCH 'a b'; 97 } [list \ 98 [list 2 1 1 54 54 1 3 3 54 372 8] \ 99 [list 2 1 1 54 54 1 3 3 54 372 7] \ 100 ] 101 102 set sqlite_fts3_enable_parentheses 1 103 do_execsql_test 2.2.$tn.2 { 104 SELECT mit(matchinfo(t2, 'x')) FROM t2 WHERE t2 MATCH 'g OR (g z)'; 105 } [list \ 106 [list 1 2 2 1 2 2 1 54 54] \ 107 [list 1 2 2 1 2 2 0 54 54] \ 108 ] 109 set sqlite_fts3_enable_parentheses 0 110} 111 112do_execsql_test 2.3.1 { 113 CREATE VIRTUAL TABLE t3 USING fts4; 114 INSERT INTO t3 VALUES('a b c d e f'); 115 INSERT INTO t3 VALUES('x b c d e f'); 116 INSERT INTO t3 VALUES('d e f a b c'); 117 INSERT INTO t3 VALUES('b c d e f'); 118 INSERT INTO t3 VALUES(''); 119 INSERT INTO t3 VALUES(''); 120 INSERT INTO t3 VALUES(''); 121 INSERT INTO t3 VALUES(''); 122 INSERT INTO t3 VALUES(''); 123 INSERT INTO t3 VALUES(''); 124} 125do_execsql_test 2.3.2 " 126 INSERT INTO t3 VALUES('f e d c b [string repeat {a } 10000]') 127" 128foreach {tn sql} { 129 1 {} 130 2 { INSERT INTO t3(t3) VALUES('optimize') } 131 3 { UPDATE t3_segments SET block = zeroblob(length(block)) 132 WHERE length(block)>10000; 133 } 134} { 135 execsql $sql 136 do_execsql_test 2.4.$tn { 137 SELECT docid, mit(matchinfo(t3, 'pcxnal')) FROM t3 WHERE t3 MATCH '"a b c"'; 138 } {1 {1 1 1 4 4 11 912 6} 3 {1 1 1 4 4 11 912 6}} 139} 140 141 142finish_test 143 144