sl@0: # 2006 September 13 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: # This file implements regression tests for SQLite library. The sl@0: # focus of this script is testing the FTS2 module. sl@0: # sl@0: # $Id: fts2b.test,v 1.1 2006/10/19 23:36:26 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_FTS2 is defined, omit this file. sl@0: ifcapable !fts2 { sl@0: finish_test sl@0: return sl@0: } sl@0: sl@0: # Fill the full-text index "t1" with phrases in english, spanish, sl@0: # and german. For the i-th row, fill in the names for the bits sl@0: # that are set in the value of i. The least significant bit is sl@0: # 1. For example, the value 5 is 101 in binary which will be sl@0: # converted to "one three" in english. sl@0: # sl@0: proc fill_multilanguage_fulltext_t1 {} { sl@0: set english {one two three four five} sl@0: set spanish {un dos tres cuatro cinco} sl@0: set german {eine zwei drei vier funf} sl@0: sl@0: for {set i 1} {$i<=31} {incr i} { sl@0: set cmd "INSERT INTO t1 VALUES" sl@0: set vset {} sl@0: foreach lang {english spanish german} { sl@0: set words {} sl@0: for {set j 0; set k 1} {$j<5} {incr j; incr k $k} { sl@0: if {$k&$i} {lappend words [lindex [set $lang] $j]} sl@0: } sl@0: lappend vset "'$words'" sl@0: } sl@0: set sql "INSERT INTO t1(english,spanish,german) VALUES([join $vset ,])" sl@0: # puts $sql sl@0: db eval $sql sl@0: } sl@0: } sl@0: sl@0: # Construct a full-text search table containing five keywords: sl@0: # one, two, three, four, and five, in various combinations. The sl@0: # rowid for each will be a bitmask for the elements it contains. sl@0: # sl@0: db eval { sl@0: CREATE VIRTUAL TABLE t1 USING fts2(english,spanish,german); sl@0: } sl@0: fill_multilanguage_fulltext_t1 sl@0: sl@0: do_test fts2b-1.1 { sl@0: execsql {SELECT rowid FROM t1 WHERE english MATCH 'one'} sl@0: } {1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31} sl@0: do_test fts2b-1.2 { sl@0: execsql {SELECT rowid FROM t1 WHERE spanish MATCH 'one'} sl@0: } {} sl@0: do_test fts2b-1.3 { sl@0: execsql {SELECT rowid FROM t1 WHERE german MATCH 'one'} sl@0: } {} sl@0: do_test fts2b-1.4 { sl@0: execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'one'} sl@0: } {1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31} sl@0: do_test fts2b-1.5 { sl@0: execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'one dos drei'} sl@0: } {7 15 23 31} sl@0: do_test fts2b-1.6 { sl@0: execsql {SELECT english, spanish, german FROM t1 WHERE rowid=1} sl@0: } {one un eine} sl@0: do_test fts2b-1.7 { sl@0: execsql {SELECT rowid FROM t1 WHERE t1 MATCH '"one un"'} sl@0: } {} sl@0: sl@0: do_test fts2b-2.1 { sl@0: execsql { sl@0: CREATE VIRTUAL TABLE t2 USING fts2(from,to); sl@0: INSERT INTO t2([from],[to]) VALUES ('one two three', 'four five six'); sl@0: SELECT [from], [to] FROM t2 sl@0: } sl@0: } {{one two three} {four five six}} sl@0: sl@0: sl@0: # Compute an SQL string that contains the words one, two, three,... to sl@0: # describe bits set in the value $i. Only the lower 5 bits are examined. sl@0: # sl@0: proc wordset {i} { sl@0: set x {} sl@0: for {set j 0; set k 1} {$j<5} {incr j; incr k $k} { sl@0: if {$k&$i} {lappend x [lindex {one two three four five} $j]} sl@0: } sl@0: return '$x' sl@0: } sl@0: sl@0: # Create a new FTS table with three columns: sl@0: # sl@0: # norm: words for the bits of rowid sl@0: # plusone: words for the bits of rowid+1 sl@0: # invert: words for the bits of ~rowid sl@0: # sl@0: db eval { sl@0: CREATE VIRTUAL TABLE t4 USING fts2([norm],'plusone',"invert"); sl@0: } sl@0: for {set i 1} {$i<=15} {incr i} { sl@0: set vset [list [wordset $i] [wordset [expr {$i+1}]] [wordset [expr {~$i}]]] sl@0: db eval "INSERT INTO t4(norm,plusone,invert) VALUES([join $vset ,]);" sl@0: } sl@0: sl@0: do_test fts2b-4.1 { sl@0: execsql {SELECT rowid FROM t4 WHERE t4 MATCH 'norm:one'} sl@0: } {1 3 5 7 9 11 13 15} sl@0: do_test fts2b-4.2 { sl@0: execsql {SELECT rowid FROM t4 WHERE norm MATCH 'one'} sl@0: } {1 3 5 7 9 11 13 15} sl@0: do_test fts2b-4.3 { sl@0: execsql {SELECT rowid FROM t4 WHERE t4 MATCH 'one'} sl@0: } {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15} sl@0: do_test fts2b-4.4 { sl@0: execsql {SELECT rowid FROM t4 WHERE t4 MATCH 'plusone:one'} sl@0: } {2 4 6 8 10 12 14} sl@0: do_test fts2b-4.5 { sl@0: execsql {SELECT rowid FROM t4 WHERE plusone MATCH 'one'} sl@0: } {2 4 6 8 10 12 14} sl@0: do_test fts2b-4.6 { sl@0: execsql {SELECT rowid FROM t4 WHERE t4 MATCH 'norm:one plusone:two'} sl@0: } {1 5 9 13} sl@0: do_test fts2b-4.7 { sl@0: execsql {SELECT rowid FROM t4 WHERE t4 MATCH 'norm:one two'} sl@0: } {1 3 5 7 9 11 13 15} sl@0: do_test fts2b-4.8 { sl@0: execsql {SELECT rowid FROM t4 WHERE t4 MATCH 'plusone:two norm:one'} sl@0: } {1 5 9 13} sl@0: do_test fts2b-4.9 { sl@0: execsql {SELECT rowid FROM t4 WHERE t4 MATCH 'two norm:one'} sl@0: } {1 3 5 7 9 11 13 15} sl@0: sl@0: sl@0: finish_test