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||!fts4_deferred { 17 finish_test 18 return 19} 20 21set testprefix fts3defer2 22 23proc mit {blob} { 24 set scan(littleEndian) i* 25 set scan(bigEndian) I* 26 binary scan $blob $scan($::tcl_platform(byteOrder)) r 27 return $r 28} 29db func mit mit 30 31#----------------------------------------------------------------------------- 32# This block of tests - fts3defer2-1.* - test the interaction of deferred NEAR 33# expressions and the snippet, offsets and matchinfo functions. 34# 35do_execsql_test 1.1.1 { 36 CREATE VIRTUAL TABLE t1 USING fts4; 37} 38do_execsql_test 1.1.2 "INSERT INTO t1 VALUES('[string repeat {a } 20000]')" 39do_execsql_test 1.1.3 "INSERT INTO t1 VALUES('[string repeat {z } 20000]')" 40do_execsql_test 1.1.4 { 41 INSERT INTO t1 VALUES('a b c d e f a x y'); 42 INSERT INTO t1 VALUES(''); 43 INSERT INTO t1 VALUES(''); 44 INSERT INTO t1 VALUES(''); 45 INSERT INTO t1 VALUES(''); 46 INSERT INTO t1 VALUES(''); 47 INSERT INTO t1(t1) VALUES('optimize'); 48} 49do_execsql_test 1.1.4 { 50 SELECT count(*) FROM t1_segments WHERE length(block)>10000; 51 UPDATE t1_segments SET block = zeroblob(length(block)) WHERE length(block)>10000; 52} {2} 53 54do_execsql_test 1.2.0 { 55 SELECT content FROM t1 WHERE t1 MATCH 'f (e a)'; 56} {{a b c d e f a x y}} 57 58do_execsql_test 1.2.1 { 59 SELECT content FROM t1 WHERE t1 MATCH 'f (e NEAR/2 a)'; 60} {{a b c d e f a x y}} 61 62do_execsql_test 1.2.2 { 63 SELECT snippet(t1, '[', ']'), offsets(t1), mit(matchinfo(t1, 'pcxnal')) 64 FROM t1 WHERE t1 MATCH 'f (e NEAR/2 a)'; 65} [list \ 66 {a b c d [e] [f] [a] x y} \ 67 {0 1 8 1 0 0 10 1 0 2 12 1} \ 68 [list 3 1 1 1 1 1 1 1 1 1 1 8 5001 9] 69] 70 71do_execsql_test 1.2.3 { 72 SELECT snippet(t1, '[', ']'), offsets(t1), mit(matchinfo(t1, 'pcxnal')) 73 FROM t1 WHERE t1 MATCH 'f (e NEAR/3 a)'; 74} [list \ 75 {[a] b c d [e] [f] [a] x y} \ 76 {0 2 0 1 0 1 8 1 0 0 10 1 0 2 12 1} \ 77 [list 3 1 1 1 1 1 1 1 2 2 1 8 5001 9] 78] 79 80do_execsql_test 1.3.1 { DROP TABLE t1 } 81 82#----------------------------------------------------------------------------- 83# Test cases fts3defer2-2.* focus specifically on the matchinfo function. 84# 85do_execsql_test 2.1.1 "CREATE VIRTUAL TABLE t2 USING fts4" 86do_execsql_test 2.1.2 "INSERT INTO t2 VALUES('[string repeat {a } 10000]')" 87do_execsql_test 2.1.3 "INSERT INTO t2 VALUES('b [string repeat {z } 10000]')" 88do_execsql_test 2.1.4 [string repeat "INSERT INTO t2 VALUES('x');" 50] 89do_execsql_test 2.1.5 { 90 INSERT INTO t2 VALUES('a b c d e f g z'); 91 INSERT INTO t2 VALUES('a b c d e f g'); 92} 93foreach {tn sql} { 94 1 {} 95 2 { INSERT INTO t2(t2) VALUES('optimize') } 96 3 { UPDATE t2_segments SET block = zeroblob(length(block)) 97 WHERE length(block)>10000; 98 } 99} { 100 execsql $sql 101 102 do_execsql_test 2.2.$tn.1 { 103 SELECT mit(matchinfo(t2, 'pcxnal')) FROM t2 WHERE t2 MATCH 'a b'; 104 } [list \ 105 [list 2 1 1 54 54 1 3 3 54 372 8] \ 106 [list 2 1 1 54 54 1 3 3 54 372 7] \ 107 ] 108 109 do_execsql_test 2.2.$tn.2 { 110 SELECT mit(matchinfo(t2, 'x')) FROM t2 WHERE t2 MATCH 'g z'; 111 } [list \ 112 [list 1 2 2 1 54 54] \ 113 ] 114 115 set sqlite_fts3_enable_parentheses 1 116 do_execsql_test 2.2.$tn.3 { 117 SELECT mit(matchinfo(t2, 'x')) FROM t2 WHERE t2 MATCH 'g OR (g z)'; 118 } [list \ 119 [list 1 2 2 1 2 2 1 54 54] \ 120 [list 1 2 2 1 2 2 0 54 54] \ 121 ] 122 set sqlite_fts3_enable_parentheses 0 123} 124 125do_execsql_test 2.3.1 { 126 CREATE VIRTUAL TABLE t3 USING fts4; 127 INSERT INTO t3 VALUES('a b c d e f'); 128 INSERT INTO t3 VALUES('x b c d e f'); 129 INSERT INTO t3 VALUES('d e f a b c'); 130 INSERT INTO t3 VALUES('b c d e f'); 131 INSERT INTO t3 VALUES(''); 132 INSERT INTO t3 VALUES(''); 133 INSERT INTO t3 VALUES(''); 134 INSERT INTO t3 VALUES(''); 135 INSERT INTO t3 VALUES(''); 136 INSERT INTO t3 VALUES(''); 137} 138do_execsql_test 2.3.2 " 139 INSERT INTO t3 VALUES('f e d c b [string repeat {a } 10000]') 140" 141foreach {tn sql} { 142 1 {} 143 2 { INSERT INTO t3(t3) VALUES('optimize') } 144 3 { UPDATE t3_segments SET block = zeroblob(length(block)) 145 WHERE length(block)>10000; 146 } 147} { 148 execsql $sql 149 do_execsql_test 2.4.$tn { 150 SELECT docid, mit(matchinfo(t3, 'pcxnal')) FROM t3 WHERE t3 MATCH '"a b c"'; 151 } {1 {1 1 1 4 4 11 912 6} 3 {1 1 1 4 4 11 912 6}} 152} 153 154 155finish_test 156