]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix the FTS1 test cases and add new tests. Comments added to the FTS1 code. (CVS...
authordrh <drh@noemail.net>
Wed, 13 Sep 2006 12:36:08 +0000 (12:36 +0000)
committerdrh <drh@noemail.net>
Wed, 13 Sep 2006 12:36:08 +0000 (12:36 +0000)
FossilOrigin-Name: 528036c828c93c78ca879bf89a52131b72e24067

ext/fts1/fts1.c
manifest
manifest.uuid
test/fts1a.test
test/fts1b.test [new file with mode: 0644]

index b3f10f69d780bee3456b1bc3b997e430c06d8d44..f4109a345beaa89900597b259602d6519f865bc6 100644 (file)
@@ -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( iRightCol<iLeftCol ||
-              iRightCol==iLeftCol && iRightPos<iLeftPos+1 ){
+              (iRightCol==iLeftCol && iRightPos<iLeftPos+1) ){
       iRightPos = readPosition(pRight, &iRightCol);
     }else{
       iLeftPos = readPosition(pLeft, &iLeftCol);
@@ -1126,9 +1126,20 @@ static int term_select(fulltext_vtab *v, const char *pTerm, int nTerm,
 ** appropriate order into out.  Returns SQLITE_OK if successful.  If
 ** there are no segments for pTerm, successfully returns an empty
 ** doclist in out.
+**
+** Each document consists of 1 or more "columns".  The number of
+** columns is v->nColumn.  If iColumn==v->nColumn, then return
+** position information about all columns.  If iColumn<v->nColumn,
+** 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, only look at the iColumn-th column */
+  const char *pTerm,    /* The term whose posting lists we want */
+  int nTerm,            /* Number of bytes in pTerm */
+  DocList *out          /* Write the resulting doclist here */
+){
   DocList doclist;
   sqlite3_stmt *s;
   int rc = sql_get_statement(v, TERM_SELECT_ALL_STMT, &s);
@@ -1446,7 +1457,7 @@ static int fulltextConnect(
   return rc;
 }
 
-  /* The %_content table holds the text of each full-text item, with
+  /* The %_content table holds the text of each document, with
   ** the rowid used as the docid.
   **
   ** The %_term table maps each term to a document list blob
@@ -1645,7 +1656,7 @@ typedef struct QueryTerm {
 */
 static int docListOfTerm(
   fulltext_vtab *v,     /* The full text index */
-  int iColumn,           /* column to restrict to */
+  int iColumn,          /* column to restrict to.  No restrition 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;
index f26c27e18c3a60e9a94c4eda0ecedb829a540b67..4ded448114d98ccdc15c1f45383efe69390c69d7 100644 (file)
--- 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
index 071684ad13e79e756353bfef259a1d560ce76bfa..4c5ed5190b58bd8ff30bd5f33eee825e3e3f8989 100644 (file)
@@ -1 +1 @@
-366a70b086c817bddecd83053472ec76ef20f309
\ No newline at end of file
+528036c828c93c78ca879bf89a52131b72e24067
\ No newline at end of file
index 28da35d5e5c50f60633f775cccdda810de8a4191..5b8cc9d280e924958f78e20a85bc5bb310abe604 100644 (file)
@@ -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 (file)
index 0000000..6b97dc9
--- /dev/null
@@ -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