2010-02-03 22:55:13 +03:00
|
|
|
# 2010 February 02
|
|
|
|
#
|
|
|
|
# The author disclaims copyright to this source code. In place of
|
|
|
|
# a legal notice, here is a blessing:
|
|
|
|
#
|
|
|
|
# May you do good and not evil.
|
|
|
|
# May you find forgiveness for yourself and forgive others.
|
|
|
|
# May you share freely, never taking more than you give.
|
|
|
|
#
|
|
|
|
#*************************************************************************
|
|
|
|
# This file implements regression tests for SQLite library. The
|
|
|
|
# focus of this script is testing the FTS4 module.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
|
|
|
|
set testdir [file dirname $argv0]
|
|
|
|
source $testdir/tester.tcl
|
|
|
|
|
|
|
|
# If SQLITE_ENABLE_FTS3 is defined, omit this file.
|
|
|
|
ifcapable !fts3 {
|
|
|
|
finish_test
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2013-09-30 21:37:15 +04:00
|
|
|
# Create the fts_kjv_genesis procedure which fills and FTS3/4 table with
|
|
|
|
# the complete text of the Book of Genesis.
|
2011-06-23 04:59:41 +04:00
|
|
|
#
|
2013-09-30 21:37:15 +04:00
|
|
|
source $testdir/genesis.tcl
|
2010-02-03 22:55:13 +03:00
|
|
|
|
2011-06-23 04:59:41 +04:00
|
|
|
# The following is a list of queries to perform against the above
|
|
|
|
# FTS3/FTS4 database. We will be trying these queries in various
|
|
|
|
# configurations to ensure that they always return the same answers.
|
|
|
|
#
|
|
|
|
set fts4aa_queries {
|
|
|
|
{abraham}
|
|
|
|
{the king}
|
|
|
|
{"the king"}
|
|
|
|
{abraham OR joseph}
|
|
|
|
{ab* OR jos*}
|
|
|
|
{lived t*}
|
|
|
|
{spake hebrew}
|
|
|
|
{melchizedek}
|
|
|
|
{t* melchizedek}
|
|
|
|
{melchizedek t*}
|
|
|
|
}
|
|
|
|
unset -nocomplain fts4aa_res
|
2010-02-03 22:55:13 +03:00
|
|
|
|
2011-06-23 04:59:41 +04:00
|
|
|
# Set up the baseline results
|
|
|
|
#
|
|
|
|
do_test fts4aa-1.0 {
|
|
|
|
db eval {
|
|
|
|
CREATE VIRTUAL TABLE t1 USING fts4(words, tokenize porter);
|
|
|
|
}
|
2013-09-30 21:37:15 +04:00
|
|
|
fts_kjv_genesis
|
2011-06-23 04:59:41 +04:00
|
|
|
foreach q $::fts4aa_queries {
|
|
|
|
set r [db eval {SELECT docid FROM t1 WHERE words MATCH $q ORDER BY docid}]
|
|
|
|
set ::fts4aa_res($q) $r
|
|
|
|
}
|
|
|
|
} {}
|
|
|
|
|
|
|
|
# Legacy test cases
|
|
|
|
#
|
2010-02-03 22:55:13 +03:00
|
|
|
do_test fts4aa-1.1 {
|
|
|
|
db eval {
|
|
|
|
SELECT docid FROM t1 EXCEPT SELECT docid FROM t1_docsize
|
|
|
|
}
|
|
|
|
} {}
|
|
|
|
do_test fts4aa-1.2 {
|
|
|
|
db eval {
|
|
|
|
SELECT docid FROM t1_docsize EXCEPT SELECT docid FROM t1
|
|
|
|
}
|
|
|
|
} {}
|
|
|
|
|
|
|
|
proc mit {blob} {
|
|
|
|
set scan(littleEndian) i*
|
|
|
|
set scan(bigEndian) I*
|
|
|
|
binary scan $blob $scan($::tcl_platform(byteOrder)) r
|
|
|
|
return $r
|
|
|
|
}
|
|
|
|
db func mit mit
|
|
|
|
|
2011-06-23 04:59:41 +04:00
|
|
|
do_test fts4aa-1.3 {
|
2010-02-03 22:55:13 +03:00
|
|
|
db eval {
|
2011-06-20 16:24:26 +04:00
|
|
|
SELECT docid, mit(matchinfo(t1, 'pcxnal')) FROM t1 WHERE t1 MATCH 'melchizedek';
|
2010-02-03 22:55:13 +03:00
|
|
|
}
|
|
|
|
} {1014018 {1 1 1 1 1 1533 25 20}}
|
2011-06-23 04:59:41 +04:00
|
|
|
do_test fts4aa-1.4 {
|
2010-02-03 22:55:13 +03:00
|
|
|
db eval {
|
2011-06-20 16:24:26 +04:00
|
|
|
SELECT docid, mit(matchinfo(t1, 'pcxnal')) FROM t1
|
2010-02-03 22:55:13 +03:00
|
|
|
WHERE t1 MATCH 'spake hebrew'
|
|
|
|
ORDER BY docid;
|
|
|
|
}
|
|
|
|
} {1039014 {2 1 1 40 40 1 6 6 1533 25 42} 1039017 {2 1 1 40 40 1 6 6 1533 25 26}}
|
2011-06-23 04:59:41 +04:00
|
|
|
do_test fts4aa-1.5 {
|
2010-02-03 22:55:13 +03:00
|
|
|
db eval {
|
2011-06-20 16:24:26 +04:00
|
|
|
SELECT docid, mit(matchinfo(t1, 'pcxnal')) FROM t1
|
2010-02-03 22:55:13 +03:00
|
|
|
WHERE t1 MATCH 'laban overtook jacob'
|
|
|
|
ORDER BY docid;
|
|
|
|
}
|
|
|
|
} {1031025 {3 1 2 54 46 1 3 3 2 181 160 1533 25 24}}
|
|
|
|
|
2011-06-23 04:59:41 +04:00
|
|
|
do_test fts4aa-1.6 {
|
2010-02-03 22:55:13 +03:00
|
|
|
db eval {
|
|
|
|
DELETE FROM t1 WHERE docid!=1050026;
|
|
|
|
SELECT hex(size) FROM t1_docsize;
|
|
|
|
SELECT hex(value) FROM t1_stat;
|
|
|
|
}
|
2011-06-20 16:24:26 +04:00
|
|
|
} {17 01176F}
|
2010-02-03 22:55:13 +03:00
|
|
|
|
2011-06-23 04:59:41 +04:00
|
|
|
do_test fts4aa-1.7 {
|
2010-02-03 22:55:13 +03:00
|
|
|
db eval {
|
|
|
|
SELECT docid FROM t1 EXCEPT SELECT docid FROM t1_docsize
|
|
|
|
}
|
|
|
|
} {}
|
2011-06-23 04:59:41 +04:00
|
|
|
do_test fts4aa-1.8 {
|
2010-02-03 22:55:13 +03:00
|
|
|
db eval {
|
|
|
|
SELECT docid FROM t1_docsize EXCEPT SELECT docid FROM t1
|
|
|
|
}
|
|
|
|
} {}
|
2012-08-20 21:24:48 +04:00
|
|
|
ifcapable fts4_deferred {
|
|
|
|
do_test fts4aa-1.9 {
|
|
|
|
# Note: Token 'in' is being deferred in the following query.
|
|
|
|
db eval {
|
|
|
|
SELECT docid, mit(matchinfo(t1, 'pcxnal')) FROM t1
|
|
|
|
WHERE t1 MATCH 'joseph died in egypt'
|
|
|
|
ORDER BY docid;
|
|
|
|
}
|
|
|
|
} {1050026 {4 1 1 1 1 1 1 1 2 1 1 1 1 1 1 23 23}}
|
|
|
|
}
|
2010-02-03 22:55:13 +03:00
|
|
|
|
2011-06-23 04:59:41 +04:00
|
|
|
# Should get the same search results from FTS3
|
|
|
|
#
|
|
|
|
do_test fts4aa-2.0 {
|
|
|
|
db eval {
|
|
|
|
DROP TABLE t1;
|
|
|
|
CREATE VIRTUAL TABLE t1 USING fts3(words, tokenize porter);
|
|
|
|
}
|
2013-09-30 21:37:15 +04:00
|
|
|
fts_kjv_genesis
|
2011-06-23 04:59:41 +04:00
|
|
|
} {}
|
|
|
|
unset -nocomplain ii
|
|
|
|
set ii 0
|
|
|
|
foreach {q r} [array get fts4aa_res] {
|
|
|
|
incr ii
|
|
|
|
do_test fts4aa-2.$ii {
|
|
|
|
db eval {SELECT docid FROM t1 WHERE words MATCH $::q ORDER BY docid}
|
|
|
|
} $r
|
|
|
|
}
|
|
|
|
|
|
|
|
# Should get the same search results when the page size is very large
|
|
|
|
#
|
|
|
|
do_test fts4aa-3.0 {
|
|
|
|
db close
|
2011-08-02 04:57:34 +04:00
|
|
|
forcedelete test.db
|
2011-06-23 04:59:41 +04:00
|
|
|
sqlite3 db test.db
|
|
|
|
db eval {
|
|
|
|
PRAGMA page_size=65536;
|
|
|
|
CREATE VIRTUAL TABLE t1 USING fts4(words, tokenize porter);
|
|
|
|
}
|
2013-09-30 21:37:15 +04:00
|
|
|
fts_kjv_genesis
|
2011-06-23 04:59:41 +04:00
|
|
|
} {}
|
|
|
|
unset -nocomplain ii
|
|
|
|
set ii 0
|
|
|
|
foreach {q r} [array get fts4aa_res] {
|
|
|
|
incr ii
|
|
|
|
do_test fts4aa-3.$ii {
|
|
|
|
db eval {SELECT docid FROM t1 WHERE words MATCH $::q ORDER BY docid}
|
|
|
|
} $r
|
|
|
|
}
|
|
|
|
|
|
|
|
# Should get the same search results when an authorizer prevents
|
|
|
|
# all PRAGMA statements.
|
|
|
|
#
|
|
|
|
proc no_pragma_auth {code arg1 arg2 arg3 arg4} {
|
|
|
|
if {$code=="SQLITE_PRAGMA"} {return SQLITE_DENY}
|
|
|
|
return SQLITE_OK;
|
|
|
|
}
|
|
|
|
do_test fts4aa-4.0 {
|
|
|
|
db auth ::no_pragma_auth
|
|
|
|
db eval {
|
|
|
|
DROP TABLE t1;
|
|
|
|
CREATE VIRTUAL TABLE t1 USING fts4(words, tokenize porter);
|
|
|
|
}
|
2013-09-30 21:37:15 +04:00
|
|
|
fts_kjv_genesis
|
2011-06-23 04:59:41 +04:00
|
|
|
} {}
|
|
|
|
unset -nocomplain ii
|
|
|
|
set ii 0
|
|
|
|
foreach {q r} [array get fts4aa_res] {
|
|
|
|
incr ii
|
|
|
|
do_test fts4aa-4.$ii {
|
|
|
|
db eval {SELECT docid FROM t1 WHERE words MATCH $::q ORDER BY docid}
|
|
|
|
} $r
|
|
|
|
}
|
|
|
|
|
2010-02-03 22:55:13 +03:00
|
|
|
finish_test
|