2010-01-07 10:54:28 +00:00
|
|
|
# 2010 January 07
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
#*************************************************************************
|
|
|
|
#
|
2010-01-06 17:19:21 +00:00
|
|
|
|
|
|
|
set testdir [file dirname $argv0]
|
|
|
|
source $testdir/tester.tcl
|
|
|
|
|
2010-01-07 10:54:28 +00:00
|
|
|
# If SQLITE_ENABLE_FTS3 is not defined, omit this file.
|
2010-01-06 17:19:21 +00:00
|
|
|
ifcapable !fts3 { finish_test ; return }
|
|
|
|
|
2010-01-07 10:54:28 +00:00
|
|
|
# Transform the list $L to its "normal" form. So that it can be compared to
|
|
|
|
# another list with the same set of elements using [string compare].
|
|
|
|
#
|
|
|
|
proc normalize {L} {
|
|
|
|
set ret [list]
|
|
|
|
foreach l $L {lappend ret $l}
|
|
|
|
return $ret
|
|
|
|
}
|
|
|
|
|
2010-01-06 17:19:21 +00:00
|
|
|
do_test fts3snippet-1.1 {
|
|
|
|
execsql {
|
|
|
|
CREATE VIRTUAL TABLE ft USING fts3;
|
|
|
|
INSERT INTO ft VALUES('xxx xxx xxx xxx');
|
|
|
|
}
|
|
|
|
} {}
|
|
|
|
|
|
|
|
do_test fts3snippet-1.2 {
|
|
|
|
execsql { SELECT offsets(ft) FROM ft WHERE ft MATCH 'xxx' }
|
|
|
|
} {{0 0 0 3 0 0 4 3 0 0 8 3 0 0 12 3}}
|
|
|
|
|
|
|
|
do_test fts3snippet-1.3 {
|
|
|
|
execsql { SELECT offsets(ft) FROM ft WHERE ft MATCH '"xxx xxx"' }
|
|
|
|
} [list [normalize {
|
|
|
|
0 0 0 3
|
|
|
|
0 0 4 3
|
|
|
|
0 1 4 3
|
|
|
|
0 0 8 3
|
|
|
|
0 1 8 3
|
|
|
|
0 1 12 3
|
|
|
|
}]]
|
|
|
|
|
|
|
|
|
|
|
|
do_test fts3snippet-1.4 {
|
|
|
|
execsql { SELECT offsets(ft) FROM ft WHERE ft MATCH '"xxx xxx" xxx' }
|
|
|
|
} [list [normalize {
|
|
|
|
0 0 0 3
|
|
|
|
0 2 0 3
|
|
|
|
0 0 4 3
|
|
|
|
0 1 4 3
|
|
|
|
0 2 4 3
|
|
|
|
0 0 8 3
|
|
|
|
0 1 8 3
|
|
|
|
0 2 8 3
|
|
|
|
0 1 12 3
|
|
|
|
0 2 12 3
|
|
|
|
}]]
|
|
|
|
|
|
|
|
do_test fts3snippet-1.5 {
|
|
|
|
execsql { SELECT offsets(ft) FROM ft WHERE ft MATCH 'xxx "xxx xxx"' }
|
|
|
|
} [list [normalize {
|
|
|
|
0 0 0 3
|
|
|
|
0 1 0 3
|
|
|
|
0 0 4 3
|
|
|
|
0 1 4 3
|
|
|
|
0 2 4 3
|
|
|
|
0 0 8 3
|
|
|
|
0 1 8 3
|
|
|
|
0 2 8 3
|
|
|
|
0 0 12 3
|
|
|
|
0 2 12 3
|
|
|
|
}]]
|
|
|
|
|
2010-01-07 10:54:28 +00:00
|
|
|
do_test fts3snippet-2.1 {
|
|
|
|
execsql {
|
|
|
|
DROP TABLE IF EXISTS ft;
|
|
|
|
CREATE VIRTUAL TABLE ft USING fts3;
|
|
|
|
INSERT INTO ft VALUES('one two three four five six seven eight nine ten');
|
|
|
|
}
|
|
|
|
} {}
|
|
|
|
foreach {tn expr res} {
|
|
|
|
1 one "[one] two three four five..."
|
|
|
|
2 two "one [two] three four five..."
|
|
|
|
3 three "one two [three] four five..."
|
|
|
|
4 four "...two three [four] five six..."
|
|
|
|
5 five "...three four [five] six seven..."
|
|
|
|
6 six "...four five [six] seven eight..."
|
|
|
|
7 seven "...five six [seven] eight nine..."
|
|
|
|
8 eight "...six seven [eight] nine ten"
|
|
|
|
9 nine "...six seven eight [nine] ten"
|
|
|
|
10 ten "...six seven eight nine [ten]"
|
|
|
|
} {
|
|
|
|
do_test fts3snippet-2.2.$tn {
|
|
|
|
execsql {
|
|
|
|
SELECT snippet(ft, '[', ']', '...', 0, 5) FROM ft WHERE ft MATCH $expr
|
|
|
|
}
|
|
|
|
} [list $res]
|
|
|
|
}
|
|
|
|
|
2010-01-06 17:19:21 +00:00
|
|
|
finish_test
|
|
|
|
|