From a6be0dc938137e78b37f503726e73b5de733be25 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 13 Sep 2006 12:36:08 +0000 Subject: [PATCH] Fix the FTS1 test cases and add new tests. Comments added to the FTS1 code. (CVS 3409) FossilOrigin-Name: 528036c828c93c78ca879bf89a52131b72e24067 --- ext/fts1/fts1.c | 51 +++++++++++++++++++++++------- manifest | 17 +++++----- manifest.uuid | 2 +- test/fts1a.test | 4 +-- test/fts1b.test | 84 +++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 136 insertions(+), 22 deletions(-) create mode 100644 test/fts1b.test diff --git a/ext/fts1/fts1.c b/ext/fts1/fts1.c index b3f10f69d7..f4109a345b 100644 --- a/ext/fts1/fts1.c +++ b/ext/fts1/fts1.c @@ -432,11 +432,11 @@ static void printDoclist(DocList *p){ printf("%s%lld", zSep, docid); zSep = ","; if( p->iType>=DL_POSITIONS ){ - int iPos; + int iPos, iCol; const char *zDiv = ""; printf("("); - while( (iPos = readPosition(&r))>=0 ){ - printf("%s%d", zDiv, iPos); + while( (iPos = readPosition(&r, &iCol))>=0 ){ + printf("%s%d:%d", zDiv, iCol, iPos); zDiv = ":"; } printf(")"); @@ -610,7 +610,7 @@ static void mergePosList( iLeftPos = readPosition(pLeft, &iLeftCol); iRightPos = readPosition(pRight, &iRightCol); }else if( iRightColnColumn. If iColumn==v->nColumn, then return +** position information about all columns. If iColumnnColumn, +** then only return position information about the iColumn-th column +** (where the first column is 0). */ -static int term_select_all(fulltext_vtab *v, int iColumn, - const char *pTerm, int nTerm, DocList *out){ +static int term_select_all( + fulltext_vtab *v, /* The fulltext index we are querying against */ + int iColumn, /* If =nColumn */ QueryTerm *pQTerm, /* Term we are looking for, or 1st term of a phrase */ DocList **ppResult /* Write the result here */ ){ @@ -1889,9 +1900,27 @@ static int fulltextQuery(fulltext_vtab *v, int iColumn, return rc; } -static int fulltextFilter(sqlite3_vtab_cursor *pCursor, - int idxNum, const char *idxStr, - int argc, sqlite3_value **argv){ +/* +** This is the xFilter interface for the virtual table. See +** the virtual table xFilter method documentation for additional +** information. +** +** If idxNum==QUERY_GENERIC then do a full table scan against +** the %_content table. +** +** If idxNum==QUERY_ROWID then do a rowid lookup for a single entry +** in the %_content table. +** +** If idxNum>=QUERY_FULLTEXT then use the full text index. The +** column on the left-hand side of the MATCH operator is column +** number idxNum-QUERY_FULLTEXT, 0 indexed. argv[0] is the right-hand +** side of the MATCH operator. +*/ +static int fulltextFilter( + sqlite3_vtab_cursor *pCursor, /* The cursor used for this query */ + int idxNum, const char *idxStr, /* Which indexing scheme to use */ + int argc, sqlite3_value **argv /* Arguments for the indexing scheme */ +){ fulltext_cursor *c = (fulltext_cursor *) pCursor; fulltext_vtab *v = cursor_vtab(c); int rc; diff --git a/manifest b/manifest index f26c27e18c..4ded448114 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Allow\svirtual\stables\sto\scontain\smultiple\sfull-text-indexed\scolumns.\s\sAdded\sa\smagic\scolumn\s"_all"\swhich\scan\sbe\sused\sfor\squerying\sall\scolumns\sin\sa\stable\sat\sonce.\n\nFor\snow,\seach\sposting\slist\sstores\sposition/offset\sinformation\sfor\smultiple\scolumns.\s\sWe\smay\simplement\sseparate\sposting\slists\sfor\sseparate\scolumns\sat\ssome\sfuture\spoint.\s(CVS\s3408) -D 2006-09-13T02:18:20 +C Fix\sthe\sFTS1\stest\scases\sand\sadd\snew\stests.\s\sComments\sadded\sto\sthe\sFTS1\scode.\s(CVS\s3409) +D 2006-09-13T12:36:09 F Makefile.in cabd42d34340f49260bc2a7668c38eba8d4cfd99 F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 @@ -21,7 +21,7 @@ F ext/README.txt 913a7bd3f4837ab14d7e063304181787658b14e1 F ext/fts1/README.txt 20ac73b006a70bcfd80069bdaf59214b6cf1db5e F ext/fts1/ft_hash.c 3927bd880e65329bdc6f506555b228b28924921b F ext/fts1/ft_hash.h 1a35e654a235c2c662d3ca0dfc3138ad60b8b7d5 -F ext/fts1/fts1.c bbca0688db98735db31f2c22d389d4fe22253d14 +F ext/fts1/fts1.c dc11410cc77148bb8a810ccecaedcf05a13b77d0 F ext/fts1/fts1.h fe8e8f38dd6d2d2645b9b0d6972e80985249575f F ext/fts1/fts1_hash.c 3196cee866edbebb1c0521e21672e6d599965114 F ext/fts1/fts1_hash.h 957d378355ed29f672cd5add012ce8b088a5e089 @@ -190,7 +190,8 @@ F test/enc3.test 890508efff6677345e93bf2a8adb0489b30df030 F test/expr.test c78843f730ccbe973d0c2ad1c99978f936893131 F test/fkey1.test 153004438d51e6769fb1ce165f6313972d6263ce F test/format4.test bf3bed3b13c63abfb3cfec232597a319a31d0bcc -F test/fts1a.test 78cc3c4630fbc3c64eeafc67464947054dc540d1 +F test/fts1a.test 54fd9451c00fb91074d5abdc207b05dcba6d2d65 +F test/fts1b.test 8775bd07b152812b00854b01e48493ac1e744eeb F test/func.test 7f2c91a948a0a177635835dc9afa078413c54ae1 F test/hook.test 7e7645fd9a033f79cce8fdff151e32715e7ec50a F test/in.test 369cb2aa1eab02296b4ec470732fe8c131260b1d @@ -397,7 +398,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513 -P 877d5558b1a6f65201b1825336935b146583bffa -R 6897ea9018a27ccc88818cf1445af451 -U adamd -Z 12207b3a7ea3e2f51bc5edc36565fa2c +P 366a70b086c817bddecd83053472ec76ef20f309 +R 7cbb899d0d838798179d462a72c54e7a +U drh +Z 508a1753e05074d38687e46ff3134800 diff --git a/manifest.uuid b/manifest.uuid index 071684ad13..4c5ed5190b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -366a70b086c817bddecd83053472ec76ef20f309 \ No newline at end of file +528036c828c93c78ca879bf89a52131b72e24067 \ No newline at end of file diff --git a/test/fts1a.test b/test/fts1a.test index 28da35d5e5..5b8cc9d280 100644 --- a/test/fts1a.test +++ b/test/fts1a.test @@ -11,7 +11,7 @@ # This file implements regression tests for SQLite library. The # focus of this script is testing the FTS1 module. # -# $Id: fts1a.test,v 1.1 2006/09/10 03:34:06 drh Exp $ +# $Id: fts1a.test,v 1.2 2006/09/13 12:36:09 drh Exp $ # set testdir [file dirname $argv0] @@ -28,7 +28,7 @@ ifcapable !fts1 { # rowid for each will be a bitmask for the elements it contains. # db eval { - CREATE VIRTUAL TABLE t1 USING fts1; + CREATE VIRTUAL TABLE t1 USING fts1(content); INSERT INTO t1(content) VALUES('one'); INSERT INTO t1(content) VALUES('two'); INSERT INTO t1(content) VALUES('one two'); diff --git a/test/fts1b.test b/test/fts1b.test new file mode 100644 index 0000000000..6b97dc99dd --- /dev/null +++ b/test/fts1b.test @@ -0,0 +1,84 @@ +# 2006 September 13 +# +# 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 FTS1 module. +# +# $Id: fts1b.test,v 1.1 2006/09/13 12:36:09 drh Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS1 is defined, omit this file. +ifcapable !fts1 { + finish_test + return +} + +# Fill the full-text index "t1" with phrases in english, spanish, +# and german. For the i-th row, fill in the names for the bits +# that are set in the value of i. The least significant bit is +# 1. For example, the value 5 is 101 in binary which will be +# converted to "one three" in english. +# +proc fill_multilanguage_fulltext_t1 {} { + set english {one two three four five} + set spanish {un dos tres cuatro cinco} + set german {eine zwei drei vier funf} + + for {set i 1} {$i<=31} {incr i} { + set cmd "INSERT INTO t1 VALUES" + set vset {} + foreach lang {english spanish german} { + set words {} + for {set j 0; set k 1} {$j<5} {incr j; incr k $k} { + if {$k&$i} {lappend words [lindex [set $lang] $j]} + } + lappend vset "'$words'" + } + set sql "INSERT INTO t1(english,spanish,german) VALUES([join $vset ,])" + # puts $sql + db eval $sql + } +} + +# Construct a full-text search table containing five keywords: +# one, two, three, four, and five, in various combinations. The +# rowid for each will be a bitmask for the elements it contains. +# +db eval { + CREATE VIRTUAL TABLE t1 USING fts1(english,spanish,german); +} +fill_multilanguage_fulltext_t1 + +do_test fts1b-1.1 { + execsql {SELECT rowid FROM t1 WHERE english MATCH 'one'} +} {1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31} +do_test fts1b-1.2 { + execsql {SELECT rowid FROM t1 WHERE spanish MATCH 'one'} +} {} +do_test fts1b-1.3 { + execsql {SELECT rowid FROM t1 WHERE german MATCH 'one'} +} {} +do_test fts1b-1.4 { + execsql {SELECT rowid FROM t1 WHERE _all MATCH 'one'} +} {1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31} +do_test fts1b-1.5 { + execsql {SELECT rowid FROM t1 WHERE _all MATCH 'one dos drei'} +} {7 15 23 31} +do_test fts1b-1.6 { + execsql {SELECT english, spanish, german FROM t1 WHERE rowid=1} +} {one un eine} +do_test fts1b-1.7 { + execsql {SELECT rowid FROM t1 WHERE _all MATCH '"one un"'} +} {} + +finish_test