xref: /sqlite-3.40.0/test/fts2a.test (revision 8a7de08a)
18e734e35Sshess# 2006 September 9
28e734e35Sshess#
38e734e35Sshess# The author disclaims copyright to this source code.  In place of
48e734e35Sshess# a legal notice, here is a blessing:
58e734e35Sshess#
68e734e35Sshess#    May you do good and not evil.
78e734e35Sshess#    May you find forgiveness for yourself and forgive others.
88e734e35Sshess#    May you share freely, never taking more than you give.
98e734e35Sshess#
108e734e35Sshess#*************************************************************************
118e734e35Sshess# This file implements regression tests for SQLite library.  The
128e734e35Sshess# focus of this script is testing the FTS2 module.
138e734e35Sshess#
14*8a7de08aSshess# $Id: fts2a.test,v 1.2 2007/05/21 21:59:18 shess Exp $
158e734e35Sshess#
168e734e35Sshess
178e734e35Sshessset testdir [file dirname $argv0]
188e734e35Sshesssource $testdir/tester.tcl
198e734e35Sshess
208e734e35Sshess# If SQLITE_ENABLE_FTS2 is defined, omit this file.
218e734e35Sshessifcapable !fts2 {
228e734e35Sshess  finish_test
238e734e35Sshess  return
248e734e35Sshess}
258e734e35Sshess
268e734e35Sshess# Construct a full-text search table containing five keywords:
278e734e35Sshess# one, two, three, four, and five, in various combinations.  The
288e734e35Sshess# rowid for each will be a bitmask for the elements it contains.
298e734e35Sshess#
308e734e35Sshessdb eval {
318e734e35Sshess  CREATE VIRTUAL TABLE t1 USING fts2(content);
328e734e35Sshess  INSERT INTO t1(content) VALUES('one');
338e734e35Sshess  INSERT INTO t1(content) VALUES('two');
348e734e35Sshess  INSERT INTO t1(content) VALUES('one two');
358e734e35Sshess  INSERT INTO t1(content) VALUES('three');
368e734e35Sshess  INSERT INTO t1(content) VALUES('one three');
378e734e35Sshess  INSERT INTO t1(content) VALUES('two three');
388e734e35Sshess  INSERT INTO t1(content) VALUES('one two three');
398e734e35Sshess  INSERT INTO t1(content) VALUES('four');
408e734e35Sshess  INSERT INTO t1(content) VALUES('one four');
418e734e35Sshess  INSERT INTO t1(content) VALUES('two four');
428e734e35Sshess  INSERT INTO t1(content) VALUES('one two four');
438e734e35Sshess  INSERT INTO t1(content) VALUES('three four');
448e734e35Sshess  INSERT INTO t1(content) VALUES('one three four');
458e734e35Sshess  INSERT INTO t1(content) VALUES('two three four');
468e734e35Sshess  INSERT INTO t1(content) VALUES('one two three four');
478e734e35Sshess  INSERT INTO t1(content) VALUES('five');
488e734e35Sshess  INSERT INTO t1(content) VALUES('one five');
498e734e35Sshess  INSERT INTO t1(content) VALUES('two five');
508e734e35Sshess  INSERT INTO t1(content) VALUES('one two five');
518e734e35Sshess  INSERT INTO t1(content) VALUES('three five');
528e734e35Sshess  INSERT INTO t1(content) VALUES('one three five');
538e734e35Sshess  INSERT INTO t1(content) VALUES('two three five');
548e734e35Sshess  INSERT INTO t1(content) VALUES('one two three five');
558e734e35Sshess  INSERT INTO t1(content) VALUES('four five');
568e734e35Sshess  INSERT INTO t1(content) VALUES('one four five');
578e734e35Sshess  INSERT INTO t1(content) VALUES('two four five');
588e734e35Sshess  INSERT INTO t1(content) VALUES('one two four five');
598e734e35Sshess  INSERT INTO t1(content) VALUES('three four five');
608e734e35Sshess  INSERT INTO t1(content) VALUES('one three four five');
618e734e35Sshess  INSERT INTO t1(content) VALUES('two three four five');
628e734e35Sshess  INSERT INTO t1(content) VALUES('one two three four five');
638e734e35Sshess}
648e734e35Sshess
658e734e35Sshessdo_test fts2a-1.1 {
668e734e35Sshess  execsql {SELECT rowid FROM t1 WHERE content MATCH 'one'}
678e734e35Sshess} {1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31}
688e734e35Sshessdo_test fts2a-1.2 {
698e734e35Sshess  execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two'}
708e734e35Sshess} {3 7 11 15 19 23 27 31}
718e734e35Sshessdo_test fts2a-1.3 {
728e734e35Sshess  execsql {SELECT rowid FROM t1 WHERE content MATCH 'two one'}
738e734e35Sshess} {3 7 11 15 19 23 27 31}
748e734e35Sshessdo_test fts2a-1.4 {
758e734e35Sshess  execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two three'}
768e734e35Sshess} {7 15 23 31}
778e734e35Sshessdo_test fts2a-1.5 {
788e734e35Sshess  execsql {SELECT rowid FROM t1 WHERE content MATCH 'one three two'}
798e734e35Sshess} {7 15 23 31}
808e734e35Sshessdo_test fts2a-1.6 {
818e734e35Sshess  execsql {SELECT rowid FROM t1 WHERE content MATCH 'two three one'}
828e734e35Sshess} {7 15 23 31}
838e734e35Sshessdo_test fts2a-1.7 {
848e734e35Sshess  execsql {SELECT rowid FROM t1 WHERE content MATCH 'two one three'}
858e734e35Sshess} {7 15 23 31}
868e734e35Sshessdo_test fts2a-1.8 {
878e734e35Sshess  execsql {SELECT rowid FROM t1 WHERE content MATCH 'three one two'}
888e734e35Sshess} {7 15 23 31}
898e734e35Sshessdo_test fts2a-1.9 {
908e734e35Sshess  execsql {SELECT rowid FROM t1 WHERE content MATCH 'three two one'}
918e734e35Sshess} {7 15 23 31}
928e734e35Sshessdo_test fts2a-1.10 {
938e734e35Sshess  execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two THREE'}
948e734e35Sshess} {7 15 23 31}
958e734e35Sshessdo_test fts2a-1.11 {
968e734e35Sshess  execsql {SELECT rowid FROM t1 WHERE content MATCH '  ONE    Two   three  '}
978e734e35Sshess} {7 15 23 31}
988e734e35Sshess
998e734e35Sshessdo_test fts2a-2.1 {
1008e734e35Sshess  execsql {SELECT rowid FROM t1 WHERE content MATCH '"one"'}
1018e734e35Sshess} {1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31}
1028e734e35Sshessdo_test fts2a-2.2 {
1038e734e35Sshess  execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two"'}
1048e734e35Sshess} {3 7 11 15 19 23 27 31}
1058e734e35Sshessdo_test fts2a-2.3 {
1068e734e35Sshess  execsql {SELECT rowid FROM t1 WHERE content MATCH '"two one"'}
1078e734e35Sshess} {}
1088e734e35Sshessdo_test fts2a-2.4 {
1098e734e35Sshess  execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two three"'}
1108e734e35Sshess} {7 15 23 31}
1118e734e35Sshessdo_test fts2a-2.5 {
1128e734e35Sshess  execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three two"'}
1138e734e35Sshess} {}
1148e734e35Sshessdo_test fts2a-2.6 {
1158e734e35Sshess  execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two three four"'}
1168e734e35Sshess} {15 31}
1178e734e35Sshessdo_test fts2a-2.7 {
1188e734e35Sshess  execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three two four"'}
1198e734e35Sshess} {}
1208e734e35Sshessdo_test fts2a-2.8 {
1218e734e35Sshess  execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three five"'}
1228e734e35Sshess} {21}
1238e734e35Sshessdo_test fts2a-2.9 {
1248e734e35Sshess  execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three" five'}
1258e734e35Sshess} {21 29}
1268e734e35Sshessdo_test fts2a-2.10 {
1278e734e35Sshess  execsql {SELECT rowid FROM t1 WHERE content MATCH 'five "one three"'}
1288e734e35Sshess} {21 29}
1298e734e35Sshessdo_test fts2a-2.11 {
1308e734e35Sshess  execsql {SELECT rowid FROM t1 WHERE content MATCH 'five "one three" four'}
1318e734e35Sshess} {29}
1328e734e35Sshessdo_test fts2a-2.12 {
1338e734e35Sshess  execsql {SELECT rowid FROM t1 WHERE content MATCH 'five four "one three"'}
1348e734e35Sshess} {29}
1358e734e35Sshessdo_test fts2a-2.13 {
1368e734e35Sshess  execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three" four five'}
1378e734e35Sshess} {29}
1388e734e35Sshess
1398e734e35Sshessdo_test fts2a-3.1 {
1408e734e35Sshess  execsql {SELECT rowid FROM t1 WHERE content MATCH 'one'}
1418e734e35Sshess} {1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31}
1428e734e35Sshessdo_test fts2a-3.2 {
1438e734e35Sshess  execsql {SELECT rowid FROM t1 WHERE content MATCH 'one -two'}
1448e734e35Sshess} {1 5 9 13 17 21 25 29}
1458e734e35Sshessdo_test fts2a-3.3 {
1468e734e35Sshess  execsql {SELECT rowid FROM t1 WHERE content MATCH '-two one'}
1478e734e35Sshess} {1 5 9 13 17 21 25 29}
1488e734e35Sshess
1498e734e35Sshessdo_test fts2a-4.1 {
1508e734e35Sshess  execsql {SELECT rowid FROM t1 WHERE content MATCH 'one OR two'}
1518e734e35Sshess} {1 2 3 5 6 7 9 10 11 13 14 15 17 18 19 21 22 23 25 26 27 29 30 31}
1528e734e35Sshessdo_test fts2a-4.2 {
1538e734e35Sshess  execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two" OR three'}
1548e734e35Sshess} {3 4 5 6 7 11 12 13 14 15 19 20 21 22 23 27 28 29 30 31}
1558e734e35Sshessdo_test fts2a-4.3 {
1568e734e35Sshess  execsql {SELECT rowid FROM t1 WHERE content MATCH 'three OR "one two"'}
1578e734e35Sshess} {3 4 5 6 7 11 12 13 14 15 19 20 21 22 23 27 28 29 30 31}
1588e734e35Sshessdo_test fts2a-4.4 {
1598e734e35Sshess  execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two OR three'}
1608e734e35Sshess} {3 5 7 11 13 15 19 21 23 27 29 31}
1618e734e35Sshessdo_test fts2a-4.5 {
1628e734e35Sshess  execsql {SELECT rowid FROM t1 WHERE content MATCH 'three OR two one'}
1638e734e35Sshess} {3 5 7 11 13 15 19 21 23 27 29 31}
1648e734e35Sshessdo_test fts2a-4.6 {
1658e734e35Sshess  execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two OR three OR four'}
1668e734e35Sshess} {3 5 7 9 11 13 15 19 21 23 25 27 29 31}
1678e734e35Sshessdo_test fts2a-4.7 {
1688e734e35Sshess  execsql {SELECT rowid FROM t1 WHERE content MATCH 'two OR three OR four one'}
1698e734e35Sshess} {3 5 7 9 11 13 15 19 21 23 25 27 29 31}
1708e734e35Sshess
1718e734e35Sshess# Test the ability to handle NULL content
1728e734e35Sshess#
1738e734e35Sshessdo_test fts2a-5.1 {
1748e734e35Sshess  execsql {INSERT INTO t1(content) VALUES(NULL)}
1758e734e35Sshess} {}
1768e734e35Sshessdo_test fts2a-5.2 {
1778e734e35Sshess  set rowid [db last_insert_rowid]
1788e734e35Sshess  execsql {SELECT content FROM t1 WHERE rowid=$rowid}
1798e734e35Sshess} {{}}
1808e734e35Sshessdo_test fts2a-5.3 {
1818e734e35Sshess  execsql {SELECT rowid FROM t1 WHERE content MATCH NULL}
1828e734e35Sshess} {}
1838e734e35Sshess
184*8a7de08aSshess# Test the ability to handle non-positive rowids
185*8a7de08aSshess#
186*8a7de08aSshessdo_test fts2a-6.0 {
187*8a7de08aSshess  execsql {INSERT INTO t1(rowid, content) VALUES(0, 'four five')}
188*8a7de08aSshess} {}
189*8a7de08aSshessdo_test fts2a-6.1 {
190*8a7de08aSshess  execsql {SELECT content FROM t1 WHERE rowid = 0}
191*8a7de08aSshess} {{four five}}
192*8a7de08aSshessdo_test fts2a-6.2 {
193*8a7de08aSshess  execsql {INSERT INTO t1(rowid, content) VALUES(-1, 'three four')}
194*8a7de08aSshess} {}
195*8a7de08aSshessdo_test fts2a-6.3 {
196*8a7de08aSshess  execsql {SELECT content FROM t1 WHERE rowid = -1}
197*8a7de08aSshess} {{three four}}
198*8a7de08aSshessdo_test fts2a-6.4 {
199*8a7de08aSshess  execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'four'}
200*8a7de08aSshess} {-1 0 8 9 10 11 12 13 14 15 24 25 26 27 28 29 30 31}
2018e734e35Sshess
2028e734e35Sshessfinish_test
203