1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/fts1b.test Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,147 @@
1.4 +# 2006 September 13
1.5 +#
1.6 +# The author disclaims copyright to this source code. In place of
1.7 +# a legal notice, here is a blessing:
1.8 +#
1.9 +# May you do good and not evil.
1.10 +# May you find forgiveness for yourself and forgive others.
1.11 +# May you share freely, never taking more than you give.
1.12 +#
1.13 +#*************************************************************************
1.14 +# This file implements regression tests for SQLite library. The
1.15 +# focus of this script is testing the FTS1 module.
1.16 +#
1.17 +# $Id: fts1b.test,v 1.4 2006/09/18 02:12:48 drh Exp $
1.18 +#
1.19 +
1.20 +set testdir [file dirname $argv0]
1.21 +source $testdir/tester.tcl
1.22 +
1.23 +# If SQLITE_ENABLE_FTS1 is defined, omit this file.
1.24 +ifcapable !fts1 {
1.25 + finish_test
1.26 + return
1.27 +}
1.28 +
1.29 +# Fill the full-text index "t1" with phrases in english, spanish,
1.30 +# and german. For the i-th row, fill in the names for the bits
1.31 +# that are set in the value of i. The least significant bit is
1.32 +# 1. For example, the value 5 is 101 in binary which will be
1.33 +# converted to "one three" in english.
1.34 +#
1.35 +proc fill_multilanguage_fulltext_t1 {} {
1.36 + set english {one two three four five}
1.37 + set spanish {un dos tres cuatro cinco}
1.38 + set german {eine zwei drei vier funf}
1.39 +
1.40 + for {set i 1} {$i<=31} {incr i} {
1.41 + set cmd "INSERT INTO t1 VALUES"
1.42 + set vset {}
1.43 + foreach lang {english spanish german} {
1.44 + set words {}
1.45 + for {set j 0; set k 1} {$j<5} {incr j; incr k $k} {
1.46 + if {$k&$i} {lappend words [lindex [set $lang] $j]}
1.47 + }
1.48 + lappend vset "'$words'"
1.49 + }
1.50 + set sql "INSERT INTO t1(english,spanish,german) VALUES([join $vset ,])"
1.51 + # puts $sql
1.52 + db eval $sql
1.53 + }
1.54 +}
1.55 +
1.56 +# Construct a full-text search table containing five keywords:
1.57 +# one, two, three, four, and five, in various combinations. The
1.58 +# rowid for each will be a bitmask for the elements it contains.
1.59 +#
1.60 +db eval {
1.61 + CREATE VIRTUAL TABLE t1 USING fts1(english,spanish,german);
1.62 +}
1.63 +fill_multilanguage_fulltext_t1
1.64 +
1.65 +do_test fts1b-1.1 {
1.66 + execsql {SELECT rowid FROM t1 WHERE english MATCH 'one'}
1.67 +} {1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31}
1.68 +do_test fts1b-1.2 {
1.69 + execsql {SELECT rowid FROM t1 WHERE spanish MATCH 'one'}
1.70 +} {}
1.71 +do_test fts1b-1.3 {
1.72 + execsql {SELECT rowid FROM t1 WHERE german MATCH 'one'}
1.73 +} {}
1.74 +do_test fts1b-1.4 {
1.75 + execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'one'}
1.76 +} {1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31}
1.77 +do_test fts1b-1.5 {
1.78 + execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'one dos drei'}
1.79 +} {7 15 23 31}
1.80 +do_test fts1b-1.6 {
1.81 + execsql {SELECT english, spanish, german FROM t1 WHERE rowid=1}
1.82 +} {one un eine}
1.83 +do_test fts1b-1.7 {
1.84 + execsql {SELECT rowid FROM t1 WHERE t1 MATCH '"one un"'}
1.85 +} {}
1.86 +
1.87 +do_test fts1b-2.1 {
1.88 + execsql {
1.89 + CREATE VIRTUAL TABLE t2 USING fts1(from,to);
1.90 + INSERT INTO t2([from],[to]) VALUES ('one two three', 'four five six');
1.91 + SELECT [from], [to] FROM t2
1.92 + }
1.93 +} {{one two three} {four five six}}
1.94 +
1.95 +
1.96 +# Compute an SQL string that contains the words one, two, three,... to
1.97 +# describe bits set in the value $i. Only the lower 5 bits are examined.
1.98 +#
1.99 +proc wordset {i} {
1.100 + set x {}
1.101 + for {set j 0; set k 1} {$j<5} {incr j; incr k $k} {
1.102 + if {$k&$i} {lappend x [lindex {one two three four five} $j]}
1.103 + }
1.104 + return '$x'
1.105 +}
1.106 +
1.107 +# Create a new FTS table with three columns:
1.108 +#
1.109 +# norm: words for the bits of rowid
1.110 +# plusone: words for the bits of rowid+1
1.111 +# invert: words for the bits of ~rowid
1.112 +#
1.113 +db eval {
1.114 + CREATE VIRTUAL TABLE t4 USING fts1([norm],'plusone',"invert");
1.115 +}
1.116 +for {set i 1} {$i<=15} {incr i} {
1.117 + set vset [list [wordset $i] [wordset [expr {$i+1}]] [wordset [expr {~$i}]]]
1.118 + db eval "INSERT INTO t4(norm,plusone,invert) VALUES([join $vset ,]);"
1.119 +}
1.120 +
1.121 +do_test fts1b-4.1 {
1.122 + execsql {SELECT rowid FROM t4 WHERE t4 MATCH 'norm:one'}
1.123 +} {1 3 5 7 9 11 13 15}
1.124 +do_test fts1b-4.2 {
1.125 + execsql {SELECT rowid FROM t4 WHERE norm MATCH 'one'}
1.126 +} {1 3 5 7 9 11 13 15}
1.127 +do_test fts1b-4.3 {
1.128 + execsql {SELECT rowid FROM t4 WHERE t4 MATCH 'one'}
1.129 +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15}
1.130 +do_test fts1b-4.4 {
1.131 + execsql {SELECT rowid FROM t4 WHERE t4 MATCH 'plusone:one'}
1.132 +} {2 4 6 8 10 12 14}
1.133 +do_test fts1b-4.5 {
1.134 + execsql {SELECT rowid FROM t4 WHERE plusone MATCH 'one'}
1.135 +} {2 4 6 8 10 12 14}
1.136 +do_test fts1b-4.6 {
1.137 + execsql {SELECT rowid FROM t4 WHERE t4 MATCH 'norm:one plusone:two'}
1.138 +} {1 5 9 13}
1.139 +do_test fts1b-4.7 {
1.140 + execsql {SELECT rowid FROM t4 WHERE t4 MATCH 'norm:one two'}
1.141 +} {1 3 5 7 9 11 13 15}
1.142 +do_test fts1b-4.8 {
1.143 + execsql {SELECT rowid FROM t4 WHERE t4 MATCH 'plusone:two norm:one'}
1.144 +} {1 5 9 13}
1.145 +do_test fts1b-4.9 {
1.146 + execsql {SELECT rowid FROM t4 WHERE t4 MATCH 'two norm:one'}
1.147 +} {1 3 5 7 9 11 13 15}
1.148 +
1.149 +
1.150 +finish_test