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 #*************************************************************************
11 # This file implements regression tests for SQLite library. The
12 # focus of this script is testing the FTS4 module.
16 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl
19 # If SQLITE_ENABLE_FTS3 is defined, omit this file.
25 # Create the fts_kjv_genesis procedure which fills and FTS3/4 table with
26 # the complete text of the Book of Genesis.
28 source $testdir/genesis.tcl
30 # The following is a list of queries to perform against the above
31 # FTS3/FTS4 database. We will be trying these queries in various
32 # configurations to ensure that they always return the same answers.
46 unset -nocomplain fts4aa_res
48 # Set up the baseline results
52 CREATE VIRTUAL TABLE t1 USING fts4(words, tokenize porter);
55 foreach q $::fts4aa_queries {
56 set r [db eval {SELECT docid FROM t1 WHERE words MATCH $q ORDER BY docid}]
57 set ::fts4aa_res($q) $r
65 SELECT docid FROM t1 EXCEPT SELECT docid FROM t1_docsize
70 SELECT docid FROM t1_docsize EXCEPT SELECT docid FROM t1
75 set scan(littleEndian) i*
76 set scan(bigEndian) I*
77 binary scan $blob $scan($::tcl_platform(byteOrder)) r
84 SELECT docid, mit(matchinfo(t1, 'pcxnal')) FROM t1 WHERE t1 MATCH 'melchizedek';
86 } {1014018 {1 1 1 1 1 1533 25 20}}
89 SELECT docid, mit(matchinfo(t1, 'pcxnal')) FROM t1
90 WHERE t1 MATCH 'spake hebrew'
93 } {1039014 {2 1 1 40 40 1 6 6 1533 25 42} 1039017 {2 1 1 40 40 1 6 6 1533 25 26}}
96 SELECT docid, mit(matchinfo(t1, 'pcxnal')) FROM t1
97 WHERE t1 MATCH 'laban overtook jacob'
100 } {1031025 {3 1 2 54 46 1 3 3 2 181 160 1533 25 24}}
104 DELETE FROM t1 WHERE docid!=1050026;
105 SELECT hex(size) FROM t1_docsize;
106 SELECT hex(value) FROM t1_stat;
112 SELECT docid FROM t1 EXCEPT SELECT docid FROM t1_docsize
117 SELECT docid FROM t1_docsize EXCEPT SELECT docid FROM t1
120 ifcapable fts4_deferred {
122 # Note: Token 'in' is being deferred in the following query.
124 SELECT docid, mit(matchinfo(t1, 'pcxnal')) FROM t1
125 WHERE t1 MATCH 'joseph died in egypt'
128 } {1050026 {4 1 1 1 1 1 1 1 2 1 1 1 1 1 1 23 23}}
131 # Should get the same search results from FTS3
136 CREATE VIRTUAL TABLE t1 USING fts3(words, tokenize porter);
142 foreach {q r} [array get fts4aa_res] {
144 do_test fts4aa-2.$ii {
145 db eval {SELECT docid FROM t1 WHERE words MATCH $::q ORDER BY docid}
149 # Should get the same search results when the page size is very large
156 PRAGMA page_size=65536;
157 CREATE VIRTUAL TABLE t1 USING fts4(words, tokenize porter);
163 foreach {q r} [array get fts4aa_res] {
165 do_test fts4aa-3.$ii {
166 db eval {SELECT docid FROM t1 WHERE words MATCH $::q ORDER BY docid}
170 # Should get the same search results when an authorizer prevents
171 # all PRAGMA statements.
173 proc no_pragma_auth {code arg1 arg2 arg3 arg4 args} {
174 if {$code=="SQLITE_PRAGMA"} {return SQLITE_DENY}
178 db auth ::no_pragma_auth
181 CREATE VIRTUAL TABLE t1 USING fts4(words, tokenize porter);
187 foreach {q r} [array get fts4aa_res] {
189 do_test fts4aa-4.$ii {
190 db eval {SELECT docid FROM t1 WHERE words MATCH $::q ORDER BY docid}