]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix a bug in the handling of the OR operator in FTS1. Test cases added to
authordrh <drh@noemail.net>
Thu, 28 Sep 2006 19:43:31 +0000 (19:43 +0000)
committerdrh <drh@noemail.net>
Thu, 28 Sep 2006 19:43:31 +0000 (19:43 +0000)
prevent a repeat. (CVS 3450)

FossilOrigin-Name: 8cdf1d6ae018dfc93f8f0962b2530e31aa0bebff

ext/fts1/fts1.c
manifest
manifest.uuid
test/fts1a.test
test/fts1c.test

index c293eacf25d746c512e9f15bd145b91253a7e543..098a66a7398af1f8f0216a1feb2a5d13a4330878 100644 (file)
@@ -2705,9 +2705,9 @@ static int fulltextQuery(
   DocList **pResult,     /* Write the result doclist here */
   Query *pQuery          /* Put parsed query string here */
 ){
-  int i, rc;
+  int i, iNext, rc;
   DocList *pLeft = NULL;
-  DocList *pRight, *pNew;
+  DocList *pRight, *pNew, *pOr;
   int nNot = 0;
   QueryTerm *aTerm;
 
@@ -2716,28 +2716,37 @@ static int fulltextQuery(
 
   /* Merge AND terms. */
   aTerm = pQuery->pTerms;
-  for(i = 0; i<pQuery->nTerms; i += aTerm[i].nPhrase + 1){
-
+  for(i = 0; i<pQuery->nTerms; i=iNext){
     if( aTerm[i].isNot ){
       /* Handle all NOT terms in a separate pass */
       nNot++;
+      iNext = i + aTerm[i].nPhrase+1;
       continue;
     }
-
+    iNext = i + aTerm[i].nPhrase + 1;
     rc = docListOfTerm(v, aTerm[i].iColumn, &aTerm[i], &pRight);
     if( rc ){
       queryClear(pQuery);
       return rc;
     }
+    while( iNext<pQuery->nTerms && aTerm[iNext].isOr ){
+      rc = docListOfTerm(v, aTerm[iNext].iColumn, &aTerm[iNext], &pOr);
+      iNext += aTerm[iNext].nPhrase + 1;
+      if( rc ){
+        queryClear(pQuery);
+        return rc;
+      }
+      pNew = docListNew(DL_DOCIDS);
+      docListOrMerge(pRight, pOr, pNew);
+      docListDelete(pRight);
+      docListDelete(pOr);
+      pRight = pNew;
+    }
     if( pLeft==0 ){
       pLeft = pRight;
     }else{
       pNew = docListNew(DL_DOCIDS);
-      if( aTerm[i].isOr ){
-        docListOrMerge(pLeft, pRight, pNew);
-      }else{
-        docListAndMerge(pLeft, pRight, pNew);
-      }
+      docListAndMerge(pLeft, pRight, pNew);
       docListDelete(pRight);
       docListDelete(pLeft);
       pLeft = pNew;
index d3449cfd6b95f0e550842b59303dedf7b8b767e2..a90c69385c6ff1bba4e37750c790a5b72436dcd5 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C More\ssnippet\sgenerator\simprovements\sand\stest\scases.\s(CVS\s3449)
-D 2006-09-28T18:58:00
+C Fix\sa\sbug\sin\sthe\shandling\sof\sthe\sOR\soperator\sin\sFTS1.\s\sTest\scases\sadded\sto\nprevent\sa\srepeat.\s(CVS\s3450)
+D 2006-09-28T19:43:32
 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 197909c5a7de842db70f19424f146d2aa8d0cbe1
+F ext/fts1/fts1.c bad8872dd51a51bc433a6b2d4d199c939e033cb9
 F ext/fts1/fts1.h 6060b8f62c1d925ea8356cb1a6598073eb9159a6
 F ext/fts1/fts1_hash.c 3196cee866edbebb1c0521e21672e6d599965114
 F ext/fts1/fts1_hash.h 957d378355ed29f672cd5add012ce8b088a5e089
@@ -190,9 +190,9 @@ F test/enc3.test 890508efff6677345e93bf2a8adb0489b30df030
 F test/expr.test c78843f730ccbe973d0c2ad1c99978f936893131
 F test/fkey1.test 153004438d51e6769fb1ce165f6313972d6263ce
 F test/format4.test bf3bed3b13c63abfb3cfec232597a319a31d0bcc
-F test/fts1a.test 8fa66282a2a297faebdab76279c1693eb7920a3b
+F test/fts1a.test 46090311f85da51bb33bd5ce84f7948359c6d8d7
 F test/fts1b.test 5d8a01aefbecc8b7442b36c94c05eb7a845462d5
-F test/fts1c.test 0e24394ee94d784f5f9f1209f263b4ea6f6da15b
+F test/fts1c.test 8790cc74bfc3141772f5cc0252dcdef20832f755
 F test/func.test 0ed54b5aeaad319f68016c033acfebef56f5874a
 F test/hook.test 7e7645fd9a033f79cce8fdff151e32715e7ec50a
 F test/in.test 369cb2aa1eab02296b4ec470732fe8c131260b1d
@@ -399,7 +399,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9
 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
 F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
-P d3f4ae827582bd0aac54ae3211d272a1429b6523
-R b0a42d4df1bd94d2804b7ca6ec30b589
+P 0934d220b33c52024f42c89fa13326bd52333f39
+R 105e424a6b1cb9ae66050c731572cf3e
 U drh
-Z 590788f47d28ad4e2ac7d0df17461f98
+Z ffcf097b13ab31485785605d678fc1c5
index a8b468ed1eb5049488408ccf2aa3a9b3179aff2e..fe399790382fc93fa2efc82f9951400aa4353930 100644 (file)
@@ -1 +1 @@
-0934d220b33c52024f42c89fa13326bd52333f39
\ No newline at end of file
+8cdf1d6ae018dfc93f8f0962b2530e31aa0bebff
\ No newline at end of file
index 5286fd71af64e3a568982f4e409f73cba01c2f98..b63e79a81b30dbd591e745426c523cd2ff797cd8 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.3 2006/09/28 11:41:41 drh Exp $
+# $Id: fts1a.test,v 1.4 2006/09/28 19:43:32 drh Exp $
 #
 
 set testdir [file dirname $argv0]
@@ -155,6 +155,18 @@ do_test fts1a-4.2 {
 do_test fts1a-4.3 {
   execsql {SELECT rowid FROM t1 WHERE content MATCH 'three OR "one two"'}
 } {3 4 5 6 7 11 12 13 14 15 19 20 21 22 23 27 28 29 30 31}
+do_test fts1a-4.4 {
+  execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two OR three'}
+} {3 5 7 11 13 15 19 21 23 27 29 31}
+do_test fts1a-4.5 {
+  execsql {SELECT rowid FROM t1 WHERE content MATCH 'three OR two one'}
+} {3 5 7 11 13 15 19 21 23 27 29 31}
+do_test fts1a-4.6 {
+  execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two OR three OR four'}
+} {3 5 7 9 11 13 15 19 21 23 25 27 29 31}
+do_test fts1a-4.7 {
+  execsql {SELECT rowid FROM t1 WHERE content MATCH 'two OR three OR four one'}
+} {3 5 7 9 11 13 15 19 21 23 25 27 29 31}
 
 # Test the ability to handle NULL content
 #
index e681d1f8d37ce9fa8be66a7a473a2b650c809867..3c5ff7ef0c2f417dce3186c05879e7001435d7c7 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: fts1c.test,v 1.9 2006/09/28 18:58:00 drh Exp $
+# $Id: fts1c.test,v 1.10 2006/09/28 19:43:32 drh Exp $
 #
 
 set testdir [file dirname $argv0]
@@ -1185,4 +1185,29 @@ Variances detected in <b>Load</b> schedule.
 
 PARSING <b>...</b>}}
 
+# Combinations of AND and OR operators:
+#
+do_test fts1c-5.1 {
+  execsql {
+    SELECT snippet(email) FROM email
+     WHERE email MATCH 'questar enron OR com'
+  }
+} {{matt.smith@<b>enron</b>.<b>com</b> <b>...</b> six reports:  
+
+31 Keystone Receipts
+15 <b>Questar</b> Pipeline
+40 Rockies Production
+22 West_2 <b>...</b>}}
+do_test fts1c-5.2 {
+  execsql {
+    SELECT snippet(email) FROM email
+     WHERE email MATCH 'enron OR com questar'
+  }
+} {{matt.smith@<b>enron</b>.<b>com</b> <b>...</b> six reports:  
+
+31 Keystone Receipts
+15 <b>Questar</b> Pipeline
+40 Rockies Production
+22 West_2 <b>...</b>}}
+
 finish_test