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 FTS5 module.
16 source [file join [file dirname [info script]] fts5_common.tcl]
19 # If SQLITE_ENABLE_FTS5 is defined, omit this file.
25 foreach_detail_mode $testprefix {
28 CREATE VIRTUAL TABLE t1 USING fts5(a, b, detail=%DETAIL%);
29 INSERT INTO t1(t1, rank) VALUES('pgsz', 32);
33 INSERT INTO t1 VALUES('hello', 'world');
34 SELECT rowid FROM t1 WHERE t1 MATCH 'hello' ORDER BY rowid ASC;
38 INSERT INTO t1 VALUES('world', 'hello');
39 SELECT rowid FROM t1 WHERE t1 MATCH 'hello' ORDER BY rowid ASC;
43 INSERT INTO t1 VALUES('world', 'world');
44 SELECT rowid FROM t1 WHERE t1 MATCH 'hello' ORDER BY rowid ASC;
47 do_execsql_test 1.4.1 {
48 INSERT INTO t1 VALUES('hello', 'hello');
51 do_execsql_test 1.4.2 {
52 SELECT rowid FROM t1 WHERE t1 MATCH 'hello' ORDER BY rowid ASC;
55 fts5_aux_test_functions db
57 #-------------------------------------------------------------------------
60 CREATE VIRTUAL TABLE t2 USING fts5(x, y, detail=%DETAIL%);
61 INSERT INTO t2 VALUES('u t l w w m s', 'm f m o l t k o p e');
62 INSERT INTO t2 VALUES('f g q e l n d m z x q', 'z s i i i m f w w f n g p');
66 SELECT rowid, fts5_test_poslist(t2) FROM t2
67 WHERE t2 MATCH 'm' ORDER BY rowid;
74 SELECT rowid, fts5_test_poslist(t2) FROM t2
75 WHERE t2 MATCH 'u OR q' ORDER BY rowid;
81 if {[detail_is_full]} {
83 SELECT rowid, fts5_test_poslist(t2) FROM t2
84 WHERE t2 MATCH 'y:o' ORDER BY rowid;
90 #-------------------------------------------------------------------------
93 CREATE VIRTUAL TABLE t3 USING fts5(x, y, detail=%DETAIL%);
94 INSERT INTO t3 VALUES( 'j f h o x x a z g b a f a m i b', 'j z c z y x w t');
95 INSERT INTO t3 VALUES( 'r c', '');
98 if {[detail_is_full]} {
100 SELECT rowid, fts5_test_poslist(t3) FROM t3 WHERE t3 MATCH 'NEAR(a b)';
102 1 {0.0.6 1.0.9 0.0.10 0.0.12 1.0.15}
105 do_execsql_test 3.2 {
106 SELECT rowid, fts5_test_poslist(t3) FROM t3 WHERE t3 MATCH 'NEAR(r c)';
112 do_execsql_test 3.3 {
114 VALUES('k x j r m a d o i z j', 'r t t t f e b r x i v j v g o');
115 SELECT rowid, fts5_test_poslist(t3)
116 FROM t3 WHERE t3 MATCH 'a OR b AND c';
118 1 {0.0.6 1.0.9 0.0.10 0.0.12 1.0.15 2.1.2}
122 #-------------------------------------------------------------------------
124 do_execsql_test 4.0 {
125 CREATE VIRTUAL TABLE t4 USING fts5(x, y, detail=%DETAIL%);
127 VALUES('k x j r m a d o i z j', 'r t t t f e b r x i v j v g o');
130 do_execsql_test 4.1 {
131 SELECT rowid, fts5_test_poslist(t4) FROM t4 WHERE t4 MATCH 'a OR b AND c';
136 #-------------------------------------------------------------------------
137 # Test that the xColumnSize() and xColumnAvgsize() APIs work.
140 fts5_aux_test_functions db
142 do_execsql_test 5.1 {
143 CREATE VIRTUAL TABLE t5 USING fts5(x, y, detail=%DETAIL%);
144 INSERT INTO t5 VALUES('a b c d', 'e f g h i j');
145 INSERT INTO t5 VALUES('', 'a');
146 INSERT INTO t5 VALUES('a', '');
148 do_execsql_test 5.2 {
149 SELECT rowid, fts5_test_columnsize(t5) FROM t5 WHERE t5 MATCH 'a'
157 do_execsql_test 5.3 {
158 SELECT rowid, fts5_test_columntext(t5) FROM t5 WHERE t5 MATCH 'a'
163 1 {{a b c d} {e f g h i j}}
166 do_execsql_test 5.4 {
167 SELECT rowid, fts5_test_columntotalsize(t5) FROM t5 WHERE t5 MATCH 'a'
175 do_execsql_test 5.5 {
176 INSERT INTO t5 VALUES('x y z', 'v w x y z');
177 SELECT rowid, fts5_test_columntotalsize(t5) FROM t5 WHERE t5 MATCH 'a'
185 #-------------------------------------------------------------------------
186 # Test the xTokenize() API
189 fts5_aux_test_functions db
190 do_execsql_test 6.1 {
191 CREATE VIRTUAL TABLE t6 USING fts5(x, y, detail=%DETAIL%);
192 INSERT INTO t6 VALUES('There are more', 'things in heaven and earth');
193 INSERT INTO t6 VALUES(', Horatio, Than are', 'dreamt of in your philosophy.');
196 do_execsql_test 6.2 {
197 SELECT rowid, fts5_test_tokenize(t6) FROM t6 WHERE t6 MATCH 't*'
199 1 {{there are more} {things in heaven and earth}}
200 2 {{horatio than are} {dreamt of in your philosophy}}
203 #-------------------------------------------------------------------------
204 # Test the xQueryPhrase() API
207 fts5_aux_test_functions db
208 do_execsql_test 7.1 {
209 CREATE VIRTUAL TABLE t7 USING fts5(x, y, detail=%DETAIL%);
213 {q i b w s a a e l o} {i b z a l f p t e u}
214 {b a z t a l o x d i} {b p a d b f h d w y}
215 {z m h n p p u i e g} {v h d v b x j j c z}
216 {a g i m v a u c b i} {p k s o t l r t b m}
217 {v v c j o d a s c p} {f f v o k p o f o g}
219 execsql {INSERT INTO t7 VALUES($x, $y)}
221 execsql { SELECT count(*) FROM t7 }
229 5 {a AND b} {{4 2} {3 4}}
230 6 {a OR b OR c OR d} {{4 2} {3 4} {2 1} {2 2}}
232 do_execsql_test 7.3.$tn {
233 SELECT fts5_test_queryphrase(t7) FROM t7 WHERE t7 MATCH $q LIMIT 1
237 do_execsql_test 7.4 {
238 SELECT fts5_test_rowcount(t7) FROM t7 WHERE t7 MATCH 'a';
241 #do_execsql_test 7.4 {
242 # SELECT rowid, bm25debug(t7) FROM t7 WHERE t7 MATCH 'a';
246 #-------------------------------------------------------------------------
249 execsql { CREATE VIRTUAL TABLE t8 USING fts5(x, y, detail=%DETAIL%) }
250 foreach {rowid x y} {
251 0 {A o} {o o o C o o o o o o o o}
252 1 {o o B} {o o o C C o o o o o o o}
253 2 {A o o} {o o o o D D o o o o o o}
254 3 {o B} {o o o o o D o o o o o o}
255 4 {E o G} {H o o o o o o o o o o o}
256 5 {F o G} {I o J o o o o o o o o o}
257 6 {E o o} {H o J o o o o o o o o o}
258 7 {o o o} {o o o o o o o o o o o o}
259 9 {o o o} {o o o o o o o o o o o o}
261 execsql { INSERT INTO t8(rowid, x, y) VALUES($rowid, $x, $y) }
270 5 {g AND (e OR f)} {5 4}
271 6 {j AND (h OR i)} {5 6}
273 do_execsql_test 8.2.$tn.1 {
274 SELECT rowid FROM t8 WHERE t8 MATCH $q ORDER BY bm25(t8);
277 do_execsql_test 8.2.$tn.2 {
278 SELECT rowid FROM t8 WHERE t8 MATCH $q ORDER BY +rank;
281 do_execsql_test 8.2.$tn.3 {
282 SELECT rowid FROM t8 WHERE t8 MATCH $q ORDER BY rank;
286 #-------------------------------------------------------------------------
287 # Test xPhraseCount() for some different queries.
290 execsql { CREATE VIRTUAL TABLE t9 USING fts5(x) }
294 execsql { INSERT INTO t9 VALUES($x) }
304 do_execsql_test 9.2.$tn {
305 SELECT fts5_test_phrasecount(t9) FROM t9 WHERE t9 MATCH $q LIMIT 1