]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fixes for tcl list generation in fts5_test().
authordan <dan@noemail.net>
Wed, 16 Jul 2014 20:07:59 +0000 (20:07 +0000)
committerdan <dan@noemail.net>
Wed, 16 Jul 2014 20:07:59 +0000 (20:07 +0000)
FossilOrigin-Name: c1f9a4b76c0bbc1ef9f6cdb5d62aa5d536fdf38e

ext/fts5/fts5_aux.c
manifest
manifest.uuid
test/fts5ac.test

index 3eea3c6ec2b9030acceb9dc9cb15d95cd78f1040..c7e2deccacadf74826100c7e05270ddbe22d0ef1 100644 (file)
@@ -81,22 +81,43 @@ static void fts5TestFunction(
     sqlite3Fts5BufferAppendPrintf(&rc, &s, " poslist ");
   }
   if( 0==zReq || 0==sqlite3_stricmp(zReq, "poslist") ){
-    sqlite3Fts5BufferAppendPrintf(&rc, &s, "{");
+    int bParen = 0;
+    Fts5Buffer s3;
+    memset(&s3, 0, sizeof(s3));
+
+
     for(i=0; i<nPhrase; i++){
+      Fts5Buffer s2;                  /* List of positions for phrase/column */
       int j = 0;
       int iOff = 0;
       int iCol = 0;
-      int bFirst = 1;
-      sqlite3Fts5BufferAppendPrintf(&rc, &s, "%s{", (i==0?"":" "));
+      int nElem = 0;
+
+      memset(&s2, 0, sizeof(s2));
       while( 0==pApi->xPoslist(pFts, i, &j, &iCol, &iOff) ){
-        sqlite3Fts5BufferAppendPrintf(
-            &rc, &s, "%s%d.%d", (bFirst?"":" "), iCol, iOff
-        );
-        bFirst = 0;
+        if( nElem!=0 ) sqlite3Fts5BufferAppendPrintf(&rc, &s2, " ");
+        sqlite3Fts5BufferAppendPrintf(&rc, &s2, "%d.%d", iCol, iOff);
+        nElem++;
       }
-      sqlite3Fts5BufferAppendPrintf(&rc, &s, "}");
+
+      if( i!=0 ){
+        sqlite3Fts5BufferAppendPrintf(&rc, &s3, " ");
+      }
+      if( nElem==1 ){
+        sqlite3Fts5BufferAppendPrintf(&rc, &s3, "%s", (const char*)s2.p);
+      }else{
+        sqlite3Fts5BufferAppendPrintf(&rc, &s3, "{%s}", (const char*)s2.p);
+        bParen = 1;
+      }
+      sqlite3_free(s2.p);
+    }
+
+    if(zReq==0 && (nPhrase>1 || bParen) ){
+      sqlite3Fts5BufferAppendPrintf(&rc, &s, "{%s}", (const char*)s3.p);
+    }else{
+      sqlite3Fts5BufferAppendPrintf(&rc, &s, "%s", (const char*)s3.p);
     }
-    sqlite3Fts5BufferAppendPrintf(&rc, &s, "}");
+    sqlite3_free(s3.p);
   }
 
   if( zReq==0 ){
index 16bcb4aad6e048df001069c4c34dd5ef8ba1589a..607b5f1c62f04059bf761d9817dde859ac7f391b 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Begin\sadding\sinterface\sfor\sauxiliary\sfunctions.
-D 2014-07-16T19:15:57.212
+C Fixes\sfor\stcl\slist\sgeneration\sin\sfts5_test().
+D 2014-07-16T20:07:59.378
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in b03432313a3aad96c706f8164fb9f5307eaf19f5
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -106,7 +106,7 @@ F ext/fts3/unicode/mkunicode.tcl dc6f268eb526710e2c6e496c372471d773d0c368
 F ext/fts5/fts5.c 20bcb1e10756c72b550947236960edf96929ca2f
 F ext/fts5/fts5.h cda3b9d73e6ffa6d0cd35b7da6b808bf3a1ada32
 F ext/fts5/fts5Int.h 2d4c1e1ebdf18278776fcd8a64233ff3c04ea51f
-F ext/fts5/fts5_aux.c 53ab338c6a469dc67e7a6bd8685ce727beee8403
+F ext/fts5/fts5_aux.c 27b082732fd76277fd7e9277f52903723d97f99b
 F ext/fts5/fts5_buffer.c b7aa6cdf4a63642fcc12359cedc4be748ca400cc
 F ext/fts5/fts5_config.c 94f1b4cb4de6a7cd5780c14adb0198e289df8cef
 F ext/fts5/fts5_expr.c e4e4e6d32beff1ab0d076f8fbf5cf3b2241d4dbc
@@ -597,7 +597,7 @@ F test/fts4noti.test 524807f0c36d49deea7920cdd4cd687408b58849
 F test/fts4unicode.test 01ec3fe2a7c3cfff3b4c0581b83caa11b33efa36
 F test/fts5aa.test c8d3b9694f6b2864161c7437408464a535d19343
 F test/fts5ab.test dc04ed48cf93ca957d174406e6c192f2ff4f3397
-F test/fts5ac.test 398a2d8d9576e0579a0f0955fabd8410ace969e4
+F test/fts5ac.test 14d05f412b99ccac34316b76861b5bfe3a33d0a1
 F test/fts5ad.test 2ed38bbc865678cb2905247120d02ebba7f20e07
 F test/fts5ea.test ff43b40f8879ba50b82def70f2ab67c195d1a1d4
 F test/full.test 6b3c8fb43c6beab6b95438c1675374b95fab245d
@@ -1194,7 +1194,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P b96b5e166990e4ec363b24f66e04cfa5f00f6342
-R ff6cbab233811678a295f9640beec5d4
+P 1e2a7ba0889093416455f488fca893eaeb195d45
+R c6840136b0b681ac8e496da634d56e88
 U dan
-Z 5e7398b52fb14b2e0bc342aa9223ff97
+Z a290facfa88166ccaa147b2550745bf7
index 7b1ee2441d9fe625ef109d932f902c84b8de3994..00e65c7fa99d120d1366a6cc92752175e53cbdf8 100644 (file)
@@ -1 +1 @@
-1e2a7ba0889093416455f488fca893eaeb195d45
\ No newline at end of file
+c1f9a4b76c0bbc1ef9f6cdb5d62aa5d536fdf38e
\ No newline at end of file
index 66cce1342bf07e11059dff5a5e0a7d27c57d355a..db5d9f151bacacc1e8e67e66bf49061a4e4e2196 100644 (file)
@@ -137,42 +137,6 @@ do_test 1.1 {
   }
 } {}
 
-proc phrasematch {phrase value} {
-  if {[string first $phrase $value]>=0} { return 1 }
-  return 0
-}
-
-# Usage:
-#
-proc nearmatch {nNear phraselist value} {
-  set nPhrase [llength $phraselist]
-
-  set phraselist [string tolower $phraselist]
-  set value [string tolower $value]
-
-  if {$nPhrase==1} {
-    set bMatch [phrasematch [lindex $phraselist 0] $value]
-  } else {
-    set nValue [llength $value]
-    if {$nNear >= $nValue} {set nNear [expr $nValue-1]}
-
-    for {set i $nNear} {$i < $nValue} {incr i} {
-      set bMatch 1
-      foreach phrase $phraselist {
-        set iMin [expr $i - $nNear - [llength $phrase]]
-        set iMax [expr $i - 1 + [llength $phrase]]
-        set subdoc [lrange $value $iMin $iMax]
-        if {![phrasematch $phrase $subdoc]} {
-          set bMatch 0
-          break
-        }
-      }
-      if {$bMatch} break
-    }
-  }
-  return $bMatch
-}
-
 # Usage:
 #
 #   poslist aCol ?-near N? ?-col C? -- phrase1 phrase2...
@@ -243,6 +207,7 @@ proc poslist {aCol args} {
     lappend res $plist
   }
 
+    #puts $res
   return $res
 }
 
@@ -284,9 +249,9 @@ proc matchdata {bPos expr {bAsc 0}} {
         set rowres [list]
         foreach phrase $N {
           set cmd "poslist [string range $phrase 9 end-1]"
-          lappend rowres [eval $cmd]
+          set pos [eval $cmd]
+          set rowres [concat $rowres $pos]
         }
-        if {[string first "\{" $rowres]<0} { set rowres "{{$rowres}}" }
         lappend res [list $id $rowres]
       } else {
         lappend res $id
@@ -303,7 +268,13 @@ proc matchdata {bPos expr {bAsc 0}} {
   return [concat {*}$res]
 }
 
+#
+# End of test code
+#-------------------------------------------------------------------------
 
+#-------------------------------------------------------------------------
+# Test phrase queries.
+#
 foreach {tn phrase} {
   1 "o"
   2 "b q"
@@ -316,7 +287,6 @@ foreach {tn phrase} {
   9 "no"
   10 "L O O L V V K"
 } {
-
   set expr "\"$phrase\""
   set res [matchdata 1 $expr]
 
@@ -325,20 +295,24 @@ foreach {tn phrase} {
   } $res
 }
 
-# Test the "nearmatch" commnad.
+#-------------------------------------------------------------------------
+# Test some AND and OR queries.
 #
-do_test 2.0 { nearmatch 2 {a b} {a x x b} } 1
-do_test 2.1 { nearmatch 2 {b a} {a x x b} } 1
-do_test 2.2 { nearmatch 1 {b a} {a x x b} } 0
-do_test 2.3 { nearmatch 1 {"a b" "c d"} {x x a b x c d} } 1
-do_test 2.4 { nearmatch 1 {"a b" "c d"} {x a b x x c d} } 0
-do_test 2.5 { nearmatch 400 {a b} {a x x b} } 1
-do_test 2.6 { nearmatch 0 {a} {a x x b} } 1
-do_test 2.7 { nearmatch 0 {b} {a x x b} } 1
-
-do_test 2.8  { poslist {{a b c}} -- a } {0.0}
-do_test 2.9  { poslist {{a b c}} -- c } {0.2}
+foreach {tn expr} {
+  1 "a   AND b"
+  2 "a+b AND c"
+  3 "d+c AND u"
+  4 "d+c AND u+d"
+} {
+  set res [matchdata 1 $expr]
+  do_execsql_test 2.1.$tn.[llength $res] { 
+    SELECT rowid, fts5_test(xx, 'poslist') FROM xx WHERE xx match $expr
+  } $res
+}
+
 
+do_test 2.1  { poslist {{a b c}} -- a } {0.0}
+do_test 2.2  { poslist {{a b c}} -- c } {0.2}
 
 foreach {tn expr tclexpr} {
   1 {a b} {[N $x -- {a}] && [N $x -- {b}]}