2010-10-22 23:03:33 +04:00
|
|
|
# 2010 October 23
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
#***********************************************************************
|
|
|
|
#
|
|
|
|
|
|
|
|
set testdir [file dirname $argv0]
|
|
|
|
source $testdir/tester.tcl
|
|
|
|
source $testdir/malloc_common.tcl
|
2012-08-20 21:24:48 +04:00
|
|
|
ifcapable !fts3||!fts4_deferred {
|
|
|
|
finish_test
|
|
|
|
return
|
|
|
|
}
|
2010-10-22 23:03:33 +04:00
|
|
|
|
|
|
|
set testprefix fts3defer2
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
# This block of tests - fts3defer2-1.* - test the interaction of deferred NEAR
|
|
|
|
# expressions and the snippet, offsets and matchinfo functions.
|
|
|
|
#
|
|
|
|
do_execsql_test 1.1.1 {
|
|
|
|
CREATE VIRTUAL TABLE t1 USING fts4;
|
|
|
|
}
|
|
|
|
do_execsql_test 1.1.2 "INSERT INTO t1 VALUES('[string repeat {a } 20000]')"
|
|
|
|
do_execsql_test 1.1.3 "INSERT INTO t1 VALUES('[string repeat {z } 20000]')"
|
|
|
|
do_execsql_test 1.1.4 {
|
|
|
|
INSERT INTO t1 VALUES('a b c d e f a x y');
|
2010-10-27 20:52:27 +04:00
|
|
|
INSERT INTO t1 VALUES('');
|
|
|
|
INSERT INTO t1 VALUES('');
|
|
|
|
INSERT INTO t1 VALUES('');
|
|
|
|
INSERT INTO t1 VALUES('');
|
|
|
|
INSERT INTO t1 VALUES('');
|
2010-10-22 23:03:33 +04:00
|
|
|
INSERT INTO t1(t1) VALUES('optimize');
|
|
|
|
}
|
|
|
|
do_execsql_test 1.1.4 {
|
|
|
|
SELECT count(*) FROM t1_segments WHERE length(block)>10000;
|
2010-10-27 20:52:27 +04:00
|
|
|
UPDATE t1_segments SET block = zeroblob(length(block)) WHERE length(block)>10000;
|
2010-10-22 23:03:33 +04:00
|
|
|
} {2}
|
|
|
|
|
2011-06-07 22:35:45 +04:00
|
|
|
do_execsql_test 1.2.0 {
|
|
|
|
SELECT content FROM t1 WHERE t1 MATCH 'f (e a)';
|
|
|
|
} {{a b c d e f a x y}}
|
|
|
|
|
2010-10-22 23:03:33 +04:00
|
|
|
do_execsql_test 1.2.1 {
|
|
|
|
SELECT content FROM t1 WHERE t1 MATCH 'f (e NEAR/2 a)';
|
|
|
|
} {{a b c d e f a x y}}
|
|
|
|
|
2014-05-07 23:59:36 +04:00
|
|
|
|
2010-10-22 23:03:33 +04:00
|
|
|
do_execsql_test 1.2.2 {
|
2010-11-23 22:16:47 +03:00
|
|
|
SELECT snippet(t1, '[', ']'), offsets(t1), mit(matchinfo(t1, 'pcxnal'))
|
2010-10-22 23:03:33 +04:00
|
|
|
FROM t1 WHERE t1 MATCH 'f (e NEAR/2 a)';
|
|
|
|
} [list \
|
|
|
|
{a b c d [e] [f] [a] x y} \
|
|
|
|
{0 1 8 1 0 0 10 1 0 2 12 1} \
|
2011-06-13 21:00:12 +04:00
|
|
|
[list 3 1 1 1 1 1 1 1 1 1 1 8 5001 9]
|
2010-10-22 23:03:33 +04:00
|
|
|
]
|
|
|
|
|
|
|
|
do_execsql_test 1.2.3 {
|
2010-11-23 22:16:47 +03:00
|
|
|
SELECT snippet(t1, '[', ']'), offsets(t1), mit(matchinfo(t1, 'pcxnal'))
|
2010-10-22 23:03:33 +04:00
|
|
|
FROM t1 WHERE t1 MATCH 'f (e NEAR/3 a)';
|
|
|
|
} [list \
|
|
|
|
{[a] b c d [e] [f] [a] x y} \
|
|
|
|
{0 2 0 1 0 1 8 1 0 0 10 1 0 2 12 1} \
|
2011-06-13 21:00:12 +04:00
|
|
|
[list 3 1 1 1 1 1 1 1 2 2 1 8 5001 9]
|
2010-10-22 23:03:33 +04:00
|
|
|
]
|
|
|
|
|
|
|
|
do_execsql_test 1.3.1 { DROP TABLE t1 }
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
# Test cases fts3defer2-2.* focus specifically on the matchinfo function.
|
|
|
|
#
|
2010-10-25 13:01:57 +04:00
|
|
|
do_execsql_test 2.1.1 "CREATE VIRTUAL TABLE t2 USING fts4"
|
2010-10-23 23:07:30 +04:00
|
|
|
do_execsql_test 2.1.2 "INSERT INTO t2 VALUES('[string repeat {a } 10000]')"
|
|
|
|
do_execsql_test 2.1.3 "INSERT INTO t2 VALUES('b [string repeat {z } 10000]')"
|
|
|
|
do_execsql_test 2.1.4 [string repeat "INSERT INTO t2 VALUES('x');" 50]
|
|
|
|
do_execsql_test 2.1.5 {
|
2011-03-23 20:10:43 +03:00
|
|
|
INSERT INTO t2 VALUES('a b c d e f g z');
|
2010-10-22 23:03:33 +04:00
|
|
|
INSERT INTO t2 VALUES('a b c d e f g');
|
|
|
|
}
|
|
|
|
foreach {tn sql} {
|
|
|
|
1 {}
|
|
|
|
2 { INSERT INTO t2(t2) VALUES('optimize') }
|
|
|
|
3 { UPDATE t2_segments SET block = zeroblob(length(block))
|
|
|
|
WHERE length(block)>10000;
|
|
|
|
}
|
|
|
|
} {
|
|
|
|
execsql $sql
|
2010-11-24 22:26:18 +03:00
|
|
|
|
2011-03-23 20:10:43 +03:00
|
|
|
do_execsql_test 2.2.$tn.1 {
|
2010-11-23 22:16:47 +03:00
|
|
|
SELECT mit(matchinfo(t2, 'pcxnal')) FROM t2 WHERE t2 MATCH 'a b';
|
2010-10-22 23:03:33 +04:00
|
|
|
} [list \
|
2011-03-23 20:10:43 +03:00
|
|
|
[list 2 1 1 54 54 1 3 3 54 372 8] \
|
2010-10-23 23:07:30 +04:00
|
|
|
[list 2 1 1 54 54 1 3 3 54 372 7] \
|
2010-10-22 23:03:33 +04:00
|
|
|
]
|
2011-03-23 20:10:43 +03:00
|
|
|
|
|
|
|
do_execsql_test 2.2.$tn.2 {
|
2011-06-07 22:35:45 +04:00
|
|
|
SELECT mit(matchinfo(t2, 'x')) FROM t2 WHERE t2 MATCH 'g z';
|
|
|
|
} [list \
|
|
|
|
[list 1 2 2 1 54 54] \
|
|
|
|
]
|
|
|
|
|
|
|
|
set sqlite_fts3_enable_parentheses 1
|
|
|
|
do_execsql_test 2.2.$tn.3 {
|
2011-03-23 20:10:43 +03:00
|
|
|
SELECT mit(matchinfo(t2, 'x')) FROM t2 WHERE t2 MATCH 'g OR (g z)';
|
|
|
|
} [list \
|
|
|
|
[list 1 2 2 1 2 2 1 54 54] \
|
|
|
|
[list 1 2 2 1 2 2 0 54 54] \
|
|
|
|
]
|
|
|
|
set sqlite_fts3_enable_parentheses 0
|
2015-05-25 13:57:13 +03:00
|
|
|
|
|
|
|
do_execsql_test 2.2.$tn.4 {
|
|
|
|
SELECT mit(matchinfo(t2, 'x')) FROM t2 WHERE t2 MATCH 'e "g z"';
|
|
|
|
} [list \
|
|
|
|
[list 1 2 2 1 2 2] \
|
|
|
|
]
|
2010-10-22 23:03:33 +04:00
|
|
|
}
|
|
|
|
|
2010-10-25 13:01:57 +04:00
|
|
|
do_execsql_test 2.3.1 {
|
|
|
|
CREATE VIRTUAL TABLE t3 USING fts4;
|
|
|
|
INSERT INTO t3 VALUES('a b c d e f');
|
|
|
|
INSERT INTO t3 VALUES('x b c d e f');
|
|
|
|
INSERT INTO t3 VALUES('d e f a b c');
|
|
|
|
INSERT INTO t3 VALUES('b c d e f');
|
2010-10-27 20:52:27 +04:00
|
|
|
INSERT INTO t3 VALUES('');
|
|
|
|
INSERT INTO t3 VALUES('');
|
|
|
|
INSERT INTO t3 VALUES('');
|
|
|
|
INSERT INTO t3 VALUES('');
|
|
|
|
INSERT INTO t3 VALUES('');
|
|
|
|
INSERT INTO t3 VALUES('');
|
2010-10-25 13:01:57 +04:00
|
|
|
}
|
|
|
|
do_execsql_test 2.3.2 "
|
|
|
|
INSERT INTO t3 VALUES('f e d c b [string repeat {a } 10000]')
|
|
|
|
"
|
|
|
|
foreach {tn sql} {
|
|
|
|
1 {}
|
|
|
|
2 { INSERT INTO t3(t3) VALUES('optimize') }
|
|
|
|
3 { UPDATE t3_segments SET block = zeroblob(length(block))
|
|
|
|
WHERE length(block)>10000;
|
|
|
|
}
|
|
|
|
} {
|
|
|
|
execsql $sql
|
|
|
|
do_execsql_test 2.4.$tn {
|
2010-11-23 22:16:47 +03:00
|
|
|
SELECT docid, mit(matchinfo(t3, 'pcxnal')) FROM t3 WHERE t3 MATCH '"a b c"';
|
2010-10-27 20:52:27 +04:00
|
|
|
} {1 {1 1 1 4 4 11 912 6} 3 {1 1 1 4 4 11 912 6}}
|
2010-10-25 13:01:57 +04:00
|
|
|
}
|
|
|
|
|
2010-10-22 23:03:33 +04:00
|
|
|
|
|
|
|
finish_test
|