sl@0: # 2008 July 29 sl@0: # sl@0: # The author disclaims copyright to this source code. In place of sl@0: # a legal notice, here is a blessing: sl@0: # sl@0: # May you do good and not evil. sl@0: # May you find forgiveness for yourself and forgive others. sl@0: # May you share freely, never taking more than you give. sl@0: # sl@0: #************************************************************************* sl@0: # These tests exercise the various types of fts3 cursors. sl@0: # sl@0: # $Id: fts3e.test,v 1.1 2008/07/29 20:24:46 shess Exp $ sl@0: # sl@0: sl@0: set testdir [file dirname $argv0] sl@0: source $testdir/tester.tcl sl@0: sl@0: # If SQLITE_ENABLE_FTS3 is not defined, omit this file. sl@0: ifcapable !fts3 { sl@0: finish_test sl@0: return sl@0: } sl@0: sl@0: #************************************************************************* sl@0: # Test table scan (QUERY_GENERIC). This kind of query happens for sl@0: # queries with no WHERE clause, or for WHERE clauses which cannot be sl@0: # satisfied by an index. sl@0: db eval { sl@0: DROP TABLE IF EXISTS t1; sl@0: CREATE VIRTUAL TABLE t1 USING fts3(c); sl@0: INSERT INTO t1 (docid, c) VALUES (1, 'This is a test'); sl@0: INSERT INTO t1 (docid, c) VALUES (2, 'That was a test'); sl@0: INSERT INTO t1 (docid, c) VALUES (3, 'This is a test'); sl@0: } sl@0: sl@0: do_test fts3e-1.1 { sl@0: execsql { sl@0: SELECT docid FROM t1 ORDER BY docid; sl@0: } sl@0: } {1 2 3} sl@0: sl@0: do_test fts3e-1.2 { sl@0: execsql { sl@0: SELECT docid FROM t1 WHERE c LIKE '%test' ORDER BY docid; sl@0: } sl@0: } {1 2 3} sl@0: sl@0: do_test fts3e-1.3 { sl@0: execsql { sl@0: SELECT docid FROM t1 WHERE c LIKE 'That%' ORDER BY docid; sl@0: } sl@0: } {2} sl@0: sl@0: #************************************************************************* sl@0: # Test lookup by docid (QUERY_DOCID). This kind of query happens for sl@0: # queries which select by the docid/rowid implicit index. sl@0: db eval { sl@0: DROP TABLE IF EXISTS t1; sl@0: DROP TABLE IF EXISTS t2; sl@0: CREATE VIRTUAL TABLE t1 USING fts3(c); sl@0: CREATE TABLE t2(id INTEGER PRIMARY KEY AUTOINCREMENT, weight INTEGER UNIQUE); sl@0: INSERT INTO t2 VALUES (null, 10); sl@0: INSERT INTO t1 (docid, c) VALUES (last_insert_rowid(), 'This is a test'); sl@0: INSERT INTO t2 VALUES (null, 5); sl@0: INSERT INTO t1 (docid, c) VALUES (last_insert_rowid(), 'That was a test'); sl@0: INSERT INTO t2 VALUES (null, 20); sl@0: INSERT INTO t1 (docid, c) VALUES (last_insert_rowid(), 'This is a test'); sl@0: } sl@0: sl@0: # TODO(shess): This actually is doing QUERY_GENERIC? I'd have sl@0: # expected QUERY_DOCID in this case, as for a very large table the sl@0: # full scan is less efficient. sl@0: do_test fts3e-2.1 { sl@0: execsql { sl@0: SELECT docid FROM t1 WHERE docid in (1, 2, 10); sl@0: SELECT rowid FROM t1 WHERE rowid in (1, 2, 10); sl@0: } sl@0: } {1 2 1 2} sl@0: sl@0: do_test fts3e-2.2 { sl@0: execsql { sl@0: SELECT docid, weight FROM t1, t2 WHERE t2.id = t1.docid ORDER BY weight; sl@0: SELECT t1.rowid, weight FROM t1, t2 WHERE t2.id = t1.rowid ORDER BY weight; sl@0: } sl@0: } {2 5 1 10 3 20 2 5 1 10 3 20} sl@0: sl@0: do_test fts3e-2.3 { sl@0: execsql { sl@0: SELECT docid, weight FROM t1, t2 sl@0: WHERE t2.weight>5 AND t2.id = t1.docid ORDER BY weight; sl@0: SELECT t1.rowid, weight FROM t1, t2 sl@0: WHERE t2.weight>5 AND t2.id = t1.rowid ORDER BY weight; sl@0: } sl@0: } {1 10 3 20 1 10 3 20} sl@0: sl@0: #************************************************************************* sl@0: # Test lookup by MATCH (QUERY_FULLTEXT). This is the fulltext index. sl@0: db eval { sl@0: DROP TABLE IF EXISTS t1; sl@0: DROP TABLE IF EXISTS t2; sl@0: CREATE VIRTUAL TABLE t1 USING fts3(c); sl@0: CREATE TABLE t2(id INTEGER PRIMARY KEY AUTOINCREMENT, weight INTEGER UNIQUE); sl@0: INSERT INTO t2 VALUES (null, 10); sl@0: INSERT INTO t1 (docid, c) VALUES (last_insert_rowid(), 'This is a test'); sl@0: INSERT INTO t2 VALUES (null, 5); sl@0: INSERT INTO t1 (docid, c) VALUES (last_insert_rowid(), 'That was a test'); sl@0: INSERT INTO t2 VALUES (null, 20); sl@0: INSERT INTO t1 (docid, c) VALUES (last_insert_rowid(), 'This is a test'); sl@0: } sl@0: sl@0: do_test fts3e-3.1 { sl@0: execsql { sl@0: SELECT docid FROM t1 WHERE t1 MATCH 'this' ORDER BY docid; sl@0: } sl@0: } {1 3} sl@0: sl@0: do_test fts3e-3.2 { sl@0: execsql { sl@0: SELECT docid, weight FROM t1, t2 sl@0: WHERE t1 MATCH 'this' AND t1.docid = t2.id ORDER BY weight; sl@0: } sl@0: } {1 10 3 20} sl@0: sl@0: finish_test