xref: /sqlite-3.40.0/test/fts3aa.test (revision db00b6ae)
1*db00b6aeSshess# 2006 September 9
2*db00b6aeSshess#
3*db00b6aeSshess# The author disclaims copyright to this source code.  In place of
4*db00b6aeSshess# a legal notice, here is a blessing:
5*db00b6aeSshess#
6*db00b6aeSshess#    May you do good and not evil.
7*db00b6aeSshess#    May you find forgiveness for yourself and forgive others.
8*db00b6aeSshess#    May you share freely, never taking more than you give.
9*db00b6aeSshess#
10*db00b6aeSshess#*************************************************************************
11*db00b6aeSshess# This file implements regression tests for SQLite library.  The
12*db00b6aeSshess# focus of this script is testing the FTS3 module.
13*db00b6aeSshess#
14*db00b6aeSshess# $Id: fts3aa.test,v 1.1 2007/08/20 17:38:42 shess Exp $
15*db00b6aeSshess#
16*db00b6aeSshess
17*db00b6aeSshessset testdir [file dirname $argv0]
18*db00b6aeSshesssource $testdir/tester.tcl
19*db00b6aeSshess
20*db00b6aeSshess# If SQLITE_ENABLE_FTS3 is defined, omit this file.
21*db00b6aeSshessifcapable !fts3 {
22*db00b6aeSshess  finish_test
23*db00b6aeSshess  return
24*db00b6aeSshess}
25*db00b6aeSshess
26*db00b6aeSshess# Construct a full-text search table containing five keywords:
27*db00b6aeSshess# one, two, three, four, and five, in various combinations.  The
28*db00b6aeSshess# rowid for each will be a bitmask for the elements it contains.
29*db00b6aeSshess#
30*db00b6aeSshessdb eval {
31*db00b6aeSshess  CREATE VIRTUAL TABLE t1 USING fts3(content);
32*db00b6aeSshess  INSERT INTO t1(content) VALUES('one');
33*db00b6aeSshess  INSERT INTO t1(content) VALUES('two');
34*db00b6aeSshess  INSERT INTO t1(content) VALUES('one two');
35*db00b6aeSshess  INSERT INTO t1(content) VALUES('three');
36*db00b6aeSshess  INSERT INTO t1(content) VALUES('one three');
37*db00b6aeSshess  INSERT INTO t1(content) VALUES('two three');
38*db00b6aeSshess  INSERT INTO t1(content) VALUES('one two three');
39*db00b6aeSshess  INSERT INTO t1(content) VALUES('four');
40*db00b6aeSshess  INSERT INTO t1(content) VALUES('one four');
41*db00b6aeSshess  INSERT INTO t1(content) VALUES('two four');
42*db00b6aeSshess  INSERT INTO t1(content) VALUES('one two four');
43*db00b6aeSshess  INSERT INTO t1(content) VALUES('three four');
44*db00b6aeSshess  INSERT INTO t1(content) VALUES('one three four');
45*db00b6aeSshess  INSERT INTO t1(content) VALUES('two three four');
46*db00b6aeSshess  INSERT INTO t1(content) VALUES('one two three four');
47*db00b6aeSshess  INSERT INTO t1(content) VALUES('five');
48*db00b6aeSshess  INSERT INTO t1(content) VALUES('one five');
49*db00b6aeSshess  INSERT INTO t1(content) VALUES('two five');
50*db00b6aeSshess  INSERT INTO t1(content) VALUES('one two five');
51*db00b6aeSshess  INSERT INTO t1(content) VALUES('three five');
52*db00b6aeSshess  INSERT INTO t1(content) VALUES('one three five');
53*db00b6aeSshess  INSERT INTO t1(content) VALUES('two three five');
54*db00b6aeSshess  INSERT INTO t1(content) VALUES('one two three five');
55*db00b6aeSshess  INSERT INTO t1(content) VALUES('four five');
56*db00b6aeSshess  INSERT INTO t1(content) VALUES('one four five');
57*db00b6aeSshess  INSERT INTO t1(content) VALUES('two four five');
58*db00b6aeSshess  INSERT INTO t1(content) VALUES('one two four five');
59*db00b6aeSshess  INSERT INTO t1(content) VALUES('three four five');
60*db00b6aeSshess  INSERT INTO t1(content) VALUES('one three four five');
61*db00b6aeSshess  INSERT INTO t1(content) VALUES('two three four five');
62*db00b6aeSshess  INSERT INTO t1(content) VALUES('one two three four five');
63*db00b6aeSshess}
64*db00b6aeSshess
65*db00b6aeSshessdo_test fts3aa-1.1 {
66*db00b6aeSshess  execsql {SELECT rowid FROM t1 WHERE content MATCH 'one'}
67*db00b6aeSshess} {1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31}
68*db00b6aeSshessdo_test fts3aa-1.2 {
69*db00b6aeSshess  execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two'}
70*db00b6aeSshess} {3 7 11 15 19 23 27 31}
71*db00b6aeSshessdo_test fts3aa-1.3 {
72*db00b6aeSshess  execsql {SELECT rowid FROM t1 WHERE content MATCH 'two one'}
73*db00b6aeSshess} {3 7 11 15 19 23 27 31}
74*db00b6aeSshessdo_test fts3aa-1.4 {
75*db00b6aeSshess  execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two three'}
76*db00b6aeSshess} {7 15 23 31}
77*db00b6aeSshessdo_test fts3aa-1.5 {
78*db00b6aeSshess  execsql {SELECT rowid FROM t1 WHERE content MATCH 'one three two'}
79*db00b6aeSshess} {7 15 23 31}
80*db00b6aeSshessdo_test fts3aa-1.6 {
81*db00b6aeSshess  execsql {SELECT rowid FROM t1 WHERE content MATCH 'two three one'}
82*db00b6aeSshess} {7 15 23 31}
83*db00b6aeSshessdo_test fts3aa-1.7 {
84*db00b6aeSshess  execsql {SELECT rowid FROM t1 WHERE content MATCH 'two one three'}
85*db00b6aeSshess} {7 15 23 31}
86*db00b6aeSshessdo_test fts3aa-1.8 {
87*db00b6aeSshess  execsql {SELECT rowid FROM t1 WHERE content MATCH 'three one two'}
88*db00b6aeSshess} {7 15 23 31}
89*db00b6aeSshessdo_test fts3aa-1.9 {
90*db00b6aeSshess  execsql {SELECT rowid FROM t1 WHERE content MATCH 'three two one'}
91*db00b6aeSshess} {7 15 23 31}
92*db00b6aeSshessdo_test fts3aa-1.10 {
93*db00b6aeSshess  execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two THREE'}
94*db00b6aeSshess} {7 15 23 31}
95*db00b6aeSshessdo_test fts3aa-1.11 {
96*db00b6aeSshess  execsql {SELECT rowid FROM t1 WHERE content MATCH '  ONE    Two   three  '}
97*db00b6aeSshess} {7 15 23 31}
98*db00b6aeSshess
99*db00b6aeSshessdo_test fts3aa-2.1 {
100*db00b6aeSshess  execsql {SELECT rowid FROM t1 WHERE content MATCH '"one"'}
101*db00b6aeSshess} {1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31}
102*db00b6aeSshessdo_test fts3aa-2.2 {
103*db00b6aeSshess  execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two"'}
104*db00b6aeSshess} {3 7 11 15 19 23 27 31}
105*db00b6aeSshessdo_test fts3aa-2.3 {
106*db00b6aeSshess  execsql {SELECT rowid FROM t1 WHERE content MATCH '"two one"'}
107*db00b6aeSshess} {}
108*db00b6aeSshessdo_test fts3aa-2.4 {
109*db00b6aeSshess  execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two three"'}
110*db00b6aeSshess} {7 15 23 31}
111*db00b6aeSshessdo_test fts3aa-2.5 {
112*db00b6aeSshess  execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three two"'}
113*db00b6aeSshess} {}
114*db00b6aeSshessdo_test fts3aa-2.6 {
115*db00b6aeSshess  execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two three four"'}
116*db00b6aeSshess} {15 31}
117*db00b6aeSshessdo_test fts3aa-2.7 {
118*db00b6aeSshess  execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three two four"'}
119*db00b6aeSshess} {}
120*db00b6aeSshessdo_test fts3aa-2.8 {
121*db00b6aeSshess  execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three five"'}
122*db00b6aeSshess} {21}
123*db00b6aeSshessdo_test fts3aa-2.9 {
124*db00b6aeSshess  execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three" five'}
125*db00b6aeSshess} {21 29}
126*db00b6aeSshessdo_test fts3aa-2.10 {
127*db00b6aeSshess  execsql {SELECT rowid FROM t1 WHERE content MATCH 'five "one three"'}
128*db00b6aeSshess} {21 29}
129*db00b6aeSshessdo_test fts3aa-2.11 {
130*db00b6aeSshess  execsql {SELECT rowid FROM t1 WHERE content MATCH 'five "one three" four'}
131*db00b6aeSshess} {29}
132*db00b6aeSshessdo_test fts3aa-2.12 {
133*db00b6aeSshess  execsql {SELECT rowid FROM t1 WHERE content MATCH 'five four "one three"'}
134*db00b6aeSshess} {29}
135*db00b6aeSshessdo_test fts3aa-2.13 {
136*db00b6aeSshess  execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three" four five'}
137*db00b6aeSshess} {29}
138*db00b6aeSshess
139*db00b6aeSshessdo_test fts3aa-3.1 {
140*db00b6aeSshess  execsql {SELECT rowid FROM t1 WHERE content MATCH 'one'}
141*db00b6aeSshess} {1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31}
142*db00b6aeSshessdo_test fts3aa-3.2 {
143*db00b6aeSshess  execsql {SELECT rowid FROM t1 WHERE content MATCH 'one -two'}
144*db00b6aeSshess} {1 5 9 13 17 21 25 29}
145*db00b6aeSshessdo_test fts3aa-3.3 {
146*db00b6aeSshess  execsql {SELECT rowid FROM t1 WHERE content MATCH '-two one'}
147*db00b6aeSshess} {1 5 9 13 17 21 25 29}
148*db00b6aeSshess
149*db00b6aeSshessdo_test fts3aa-4.1 {
150*db00b6aeSshess  execsql {SELECT rowid FROM t1 WHERE content MATCH 'one OR two'}
151*db00b6aeSshess} {1 2 3 5 6 7 9 10 11 13 14 15 17 18 19 21 22 23 25 26 27 29 30 31}
152*db00b6aeSshessdo_test fts3aa-4.2 {
153*db00b6aeSshess  execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two" OR three'}
154*db00b6aeSshess} {3 4 5 6 7 11 12 13 14 15 19 20 21 22 23 27 28 29 30 31}
155*db00b6aeSshessdo_test fts3aa-4.3 {
156*db00b6aeSshess  execsql {SELECT rowid FROM t1 WHERE content MATCH 'three OR "one two"'}
157*db00b6aeSshess} {3 4 5 6 7 11 12 13 14 15 19 20 21 22 23 27 28 29 30 31}
158*db00b6aeSshessdo_test fts3aa-4.4 {
159*db00b6aeSshess  execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two OR three'}
160*db00b6aeSshess} {3 5 7 11 13 15 19 21 23 27 29 31}
161*db00b6aeSshessdo_test fts3aa-4.5 {
162*db00b6aeSshess  execsql {SELECT rowid FROM t1 WHERE content MATCH 'three OR two one'}
163*db00b6aeSshess} {3 5 7 11 13 15 19 21 23 27 29 31}
164*db00b6aeSshessdo_test fts3aa-4.6 {
165*db00b6aeSshess  execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two OR three OR four'}
166*db00b6aeSshess} {3 5 7 9 11 13 15 19 21 23 25 27 29 31}
167*db00b6aeSshessdo_test fts3aa-4.7 {
168*db00b6aeSshess  execsql {SELECT rowid FROM t1 WHERE content MATCH 'two OR three OR four one'}
169*db00b6aeSshess} {3 5 7 9 11 13 15 19 21 23 25 27 29 31}
170*db00b6aeSshess
171*db00b6aeSshess# Test the ability to handle NULL content
172*db00b6aeSshess#
173*db00b6aeSshessdo_test fts3aa-5.1 {
174*db00b6aeSshess  execsql {INSERT INTO t1(content) VALUES(NULL)}
175*db00b6aeSshess} {}
176*db00b6aeSshessdo_test fts3aa-5.2 {
177*db00b6aeSshess  set rowid [db last_insert_rowid]
178*db00b6aeSshess  execsql {SELECT content FROM t1 WHERE rowid=$rowid}
179*db00b6aeSshess} {{}}
180*db00b6aeSshessdo_test fts3aa-5.3 {
181*db00b6aeSshess  execsql {SELECT rowid FROM t1 WHERE content MATCH NULL}
182*db00b6aeSshess} {}
183*db00b6aeSshess
184*db00b6aeSshess# Test the ability to handle non-positive rowids
185*db00b6aeSshess#
186*db00b6aeSshessdo_test fts3aa-6.0 {
187*db00b6aeSshess  execsql {INSERT INTO t1(rowid, content) VALUES(0, 'four five')}
188*db00b6aeSshess} {}
189*db00b6aeSshessdo_test fts3aa-6.1 {
190*db00b6aeSshess  execsql {SELECT content FROM t1 WHERE rowid = 0}
191*db00b6aeSshess} {{four five}}
192*db00b6aeSshessdo_test fts3aa-6.2 {
193*db00b6aeSshess  execsql {INSERT INTO t1(rowid, content) VALUES(-1, 'three four')}
194*db00b6aeSshess} {}
195*db00b6aeSshessdo_test fts3aa-6.3 {
196*db00b6aeSshess  execsql {SELECT content FROM t1 WHERE rowid = -1}
197*db00b6aeSshess} {{three four}}
198*db00b6aeSshessdo_test fts3aa-6.4 {
199*db00b6aeSshess  execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'four'}
200*db00b6aeSshess} {-1 0 8 9 10 11 12 13 14 15 24 25 26 27 28 29 30 31}
201*db00b6aeSshess
202*db00b6aeSshessfinish_test
203