3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
13 set testdir [file dirname $argv0]
14 source $testdir/tester.tcl
15 source $testdir/malloc_common.tcl
16 ifcapable !fts3||!fts4_deferred {
21 set testprefix fts3defer2
24 set scan(littleEndian) i*
25 set scan(bigEndian) I*
26 binary scan $blob $scan($::tcl_platform(byteOrder)) r
31 #-----------------------------------------------------------------------------
32 # This block of tests - fts3defer2-1.* - test the interaction of deferred NEAR
33 # expressions and the snippet, offsets and matchinfo functions.
35 do_execsql_test 1.1.1 {
36 CREATE VIRTUAL TABLE t1 USING fts4;
38 do_execsql_test 1.1.2 "INSERT INTO t1 VALUES('[string repeat {a } 20000]')"
39 do_execsql_test 1.1.3 "INSERT INTO t1 VALUES('[string repeat {z } 20000]')"
40 do_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');
49 sqlite3_db_config db DEFENSIVE 0
50 do_execsql_test 1.1.4 {
51 SELECT count(*) FROM t1_segments WHERE length(block)>10000;
52 UPDATE t1_segments SET block = zeroblob(length(block)) WHERE length(block)>10000;
55 do_execsql_test 1.2.0 {
56 SELECT content FROM t1 WHERE t1 MATCH 'f (e a)';
57 } {{a b c d e f a x y}}
59 do_execsql_test 1.2.1 {
60 SELECT content FROM t1 WHERE t1 MATCH 'f (e NEAR/2 a)';
61 } {{a b c d e f a x y}}
64 do_execsql_test 1.2.2 {
65 SELECT snippet(t1, '[', ']'), offsets(t1), mit(matchinfo(t1, 'pcxnal'))
66 FROM t1 WHERE t1 MATCH 'f (e NEAR/2 a)';
68 {a b c d [e] [f] [a] x y} \
69 {0 1 8 1 0 0 10 1 0 2 12 1} \
70 [list 3 1 1 1 1 1 1 1 1 1 1 8 5001 9]
73 do_execsql_test 1.2.3 {
74 SELECT snippet(t1, '[', ']'), offsets(t1), mit(matchinfo(t1, 'pcxnal'))
75 FROM t1 WHERE t1 MATCH 'f (e NEAR/3 a)';
77 {[a] b c d [e] [f] [a] x y} \
78 {0 2 0 1 0 1 8 1 0 0 10 1 0 2 12 1} \
79 [list 3 1 1 1 1 1 1 1 2 2 1 8 5001 9]
82 do_execsql_test 1.3.1 { DROP TABLE t1 }
84 #-----------------------------------------------------------------------------
85 # Test cases fts3defer2-2.* focus specifically on the matchinfo function.
87 do_execsql_test 2.1.1 "CREATE VIRTUAL TABLE t2 USING fts4"
88 do_execsql_test 2.1.2 "INSERT INTO t2 VALUES('[string repeat {a } 10000]')"
89 do_execsql_test 2.1.3 "INSERT INTO t2 VALUES('b [string repeat {z } 10000]')"
90 do_execsql_test 2.1.4 [string repeat "INSERT INTO t2 VALUES('x');" 50]
91 do_execsql_test 2.1.5 {
92 INSERT INTO t2 VALUES('a b c d e f g z');
93 INSERT INTO t2 VALUES('a b c d e f g');
97 2 { INSERT INTO t2(t2) VALUES('optimize') }
98 3 { UPDATE t2_segments SET block = zeroblob(length(block))
99 WHERE length(block)>10000;
102 sqlite3_db_config db DEFENSIVE 0
105 do_execsql_test 2.2.$tn.1 {
106 SELECT mit(matchinfo(t2, 'pcxnal')) FROM t2 WHERE t2 MATCH 'a b';
108 [list 2 1 1 54 54 1 3 3 54 372 8] \
109 [list 2 1 1 54 54 1 3 3 54 372 7] \
112 do_execsql_test 2.2.$tn.2 {
113 SELECT mit(matchinfo(t2, 'x')) FROM t2 WHERE t2 MATCH 'g z';
115 [list 1 2 2 1 54 54] \
118 set sqlite_fts3_enable_parentheses 1
119 do_execsql_test 2.2.$tn.3 {
120 SELECT mit(matchinfo(t2, 'x')) FROM t2 WHERE t2 MATCH 'g OR (g z)';
122 [list 1 2 2 1 2 2 1 54 54] \
123 [list 1 2 2 1 2 2 0 54 54] \
125 set sqlite_fts3_enable_parentheses 0
127 do_execsql_test 2.2.$tn.4 {
128 SELECT mit(matchinfo(t2, 'x')) FROM t2 WHERE t2 MATCH 'e "g z"';
134 do_execsql_test 2.3.1 {
135 CREATE VIRTUAL TABLE t3 USING fts4;
136 INSERT INTO t3 VALUES('a b c d e f');
137 INSERT INTO t3 VALUES('x b c d e f');
138 INSERT INTO t3 VALUES('d e f a b c');
139 INSERT INTO t3 VALUES('b c d e f');
140 INSERT INTO t3 VALUES('');
141 INSERT INTO t3 VALUES('');
142 INSERT INTO t3 VALUES('');
143 INSERT INTO t3 VALUES('');
144 INSERT INTO t3 VALUES('');
145 INSERT INTO t3 VALUES('');
147 do_execsql_test 2.3.2 "
148 INSERT INTO t3 VALUES('f e d c b [string repeat {a } 10000]')
152 2 { INSERT INTO t3(t3) VALUES('optimize') }
153 3 { UPDATE t3_segments SET block = zeroblob(length(block))
154 WHERE length(block)>10000;
157 sqlite3_db_config db DEFENSIVE 0
159 do_execsql_test 2.4.$tn {
160 SELECT docid, mit(matchinfo(t3, 'pcxnal')) FROM t3 WHERE t3 MATCH '"a b c"';
161 } {1 {1 1 1 4 4 11 912 6} 3 {1 1 1 4 4 11 912 6}}
164 do_execsql_test 2.5 {
165 INSERT INTO t3(t3) VALUES('rebuild');
167 do_execsql_test 2.6 {
168 SELECT rowid, length(offsets(t3)) FROM t3 WHERE t3 MATCH '(a NEAR a)';
170 do_execsql_test 2.7 {
171 SELECT rowid, length(offsets(t3)) FROM t3 WHERE t3 MATCH '(a NEAR b NEAR a)';
173 do_execsql_test 2.8 {
174 SELECT rowid, length(offsets(t3)) FROM t3 WHERE t3 MATCH '(a NEAR b)';
177 do_execsql_test 2.9 {
178 SELECT rowid, length(matchinfo(t3)) FROM t3 WHERE t3 MATCH '(a NEAR a)';
180 do_execsql_test 2.10 {
181 SELECT rowid, length(matchinfo(t3)) FROM t3 WHERE t3 MATCH '(a NEAR b NEAR a)'
183 do_execsql_test 2.11 {
184 SELECT rowid, length(matchinfo(t3)) FROM t3 WHERE t3 MATCH '(a NEAR b)';
187 do_execsql_test 2.12 {
188 SELECT rowid, length(matchinfo(t3)) FROM t3
189 WHERE t3 MATCH '(a NEAR b NEAR a NEAR b NEAR a)'