/ Check-in [aefd46df]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add a couple of extra tests.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | fts3-prefix-search
Files: files | file ages | folders
SHA1: aefd46dfae7e06fbaf4f2b9a86a7f2ac6927331e
User & Date: dan 2011-06-14 11:32:50
Context
2011-06-14
11:50
Merge fts3-prefix-search branch with trunk. check-in: b1f9c1e0 user: dan tags: trunk
11:32
Add a couple of extra tests. Closed-Leaf check-in: aefd46df user: dan tags: fts3-prefix-search
09:00
Fix another bug caused by NEAR/matchinfo/order=DESC interaction. check-in: 04907fba user: dan tags: fts3-prefix-search
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to test/fts3auto.test.

    17     17   source $testdir/malloc_common.tcl
    18     18   
    19     19   set testprefix fts3auto
    20     20   set sfep $sqlite_fts3_enable_parentheses
    21     21   set sqlite_fts3_enable_parentheses 1
    22     22   
    23     23   #--------------------------------------------------------------------------
    24         -# Start of Tcl infrastructure used by tests. The entry point is
    25         -# [do_fts3query_test] (described below).
           24  +# Start of Tcl infrastructure used by tests. The entry points are:
           25  +#
           26  +#   do_fts3query_test
           27  +#   fts3_make_deferrable
           28  +#   fts3_zero_long_segments 
    26     29   #
    27     30   
           31  +#
    28     32   #    do_fts3query_test TESTNAME ?OPTIONS? TABLE MATCHEXPR
    29     33   #
    30     34   # This proc runs several test cases on FTS3/4 table $TABLE using match
    31     35   # expression $MATCHEXPR. All documents in $TABLE must be formatted so that
    32     36   # they can be "tokenized" using the Tcl list commands (llength, lindex etc.).
    33     37   # The name and column names used by $TABLE must not require any quoting or
    34     38   # escaping when used in SQL statements.
................................................................................
    98    102     " $matchinfo_desc
    99    103   
   100    104     do_execsql_test $tn$title.4 "
   101    105       SELECT docid, mit(matchinfo($tbl, 'x')) FROM $tbl 
   102    106       WHERE $tbl MATCH '$match' ORDER BY docid ASC
   103    107     " $matchinfo_asc
   104    108   }
          109  +
          110  +#    fts3_make_deferrable TABLE TOKEN
          111  +#
          112  +proc fts3_make_deferrable {tbl token} {
          113  +
          114  +  set stmt [sqlite3_prepare db "SELECT * FROM $tbl" -1 dummy]
          115  +  set name [sqlite3_column_name $stmt 0]
          116  +  sqlite3_finalize $stmt
          117  +
          118  +  set nRow [db one "SELECT count(*) FROM $tbl"]
          119  +  set pgsz [db one "PRAGMA page_size"]
          120  +  execsql BEGIN
          121  +  for {set i 0} {$i < ($nRow * $pgsz * 1.2)/100} {incr i} {
          122  +    set doc [string repeat "$token " 100]
          123  +    execsql "INSERT INTO $tbl ($name) VALUES(\$doc)"
          124  +  }
          125  +  execsql "INSERT INTO $tbl ($name) VALUES('aaaaaaa ${token}aaaaa')"
          126  +  execsql COMMIT
          127  +
          128  +  return [expr $nRow*$pgsz]
          129  +}
          130  +
          131  +#    fts3_zero_long_segments TABLE ?LIMIT?
          132  +#
          133  +proc fts3_zero_long_segments {tbl limit} {
          134  +  execsql " 
          135  +    UPDATE ${tbl}_segments 
          136  +    SET block = zeroblob(length(block)) 
          137  +    WHERE length(block)>$limit
          138  +  "
          139  +  return [db changes]
          140  +}
   105    141   
   106    142   
   107    143   proc mit {blob} {
   108    144     set scan(littleEndian) i*
   109    145     set scan(bigEndian) I*
   110    146     binary scan $blob $scan($::tcl_platform(byteOrder)) r
   111    147     return $r
................................................................................
   410    446       do_fts3query_test 2.$tn.2.$tn2 t1 $expr
   411    447     }
   412    448   }
   413    449   
   414    450   #--------------------------------------------------------------------------
   415    451   # Some test cases involving deferred tokens.
   416    452   #
   417         -proc make_token_deferrable {tbl token} {
   418         -  set nRow [db one "SELECT count(*) FROM $tbl"]
   419         -  set pgsz [db one "PRAGMA page_size"]
   420         -  execsql BEGIN
   421         -  for {set i 0} {$i < ($nRow * $pgsz * 1.2)/100} {incr i} {
   422         -    set doc [string repeat "$token " 100]
   423         -    execsql "INSERT INTO $tbl VALUES(\$doc)"
   424         -  }
   425         -  execsql "INSERT INTO $tbl VALUES('aaaaaaa ${token}aaaaa')"
   426         -  execsql COMMIT
   427         -}
   428    453   
   429    454   foreach {tn create} {
   430    455     1    "fts4(x)"
   431    456     2    "fts4(x, order=DESC)"
   432    457   } {
   433    458     catchsql { DROP TABLE t1 }
   434    459     execsql  "CREATE VIRTUAL TABLE t1 USING $create"
................................................................................
   440    465       INSERT INTO t1(docid, x) VALUES(2, 'e f g h i j k a b c d');
   441    466       INSERT INTO t1(docid, x) VALUES(3, 'f g h i j k a b c d e');
   442    467       INSERT INTO t1(docid, x) VALUES(4, 'a c e g i k');
   443    468       INSERT INTO t1(docid, x) VALUES(5, 'a d g j');
   444    469       INSERT INTO t1(docid, x) VALUES(6, 'c a b');
   445    470     }
   446    471   
   447         -  make_token_deferrable t1 c
          472  +  set limit [fts3_make_deferrable t1 c]
   448    473   
   449         -  foreach {tn2 expr} {
   450         -    1     {a OR c}
   451         -  } {
   452         -    do_fts3query_test 3.$tn.2.$tn2 t1 $expr
   453         -  }
          474  +  do_fts3query_test 3.$tn.2.1 t1 {a OR c}
   454    475   
   455         -  execsql { 
   456         -    UPDATE t1_segments 
   457         -    SET block = zeroblob(length(block)) 
   458         -    WHERE length(block)>10000 AND 0
   459         -  }
          476  +  do_test 3.$tn.3 { 
          477  +    fts3_zero_long_segments t1 $limit 
          478  +  } {1}
          479  +
   460    480     foreach {tn2 expr def} {
   461    481       1     {a NEAR c}            {}
   462    482       2     {a AND c}             c
   463    483       3     {"a c"}               c
   464    484       4     {"c a"}               c
   465    485       5     {"a c" NEAR/1 g}      {}
   466    486       6     {"a c" NEAR/0 g}      {}
   467    487     } {
   468         -    do_fts3query_test 3.$tn.2.$tn2 -deferred $def t1 $expr
          488  +    do_fts3query_test 3.$tn.4.$tn2 -deferred $def t1 $expr
   469    489     }
   470    490   }
   471    491   
   472    492   #--------------------------------------------------------------------------
   473         -#
          493  +# 
   474    494   foreach {tn create} {
   475    495     1    "fts4(x, y)"
   476    496     2    "fts4(x, y, order=DESC)"
          497  +  3    "fts4(x, y, order=DESC, prefix=2)"
   477    498   } {
   478         -  catchsql { DROP TABLE t1 }
   479         -  execsql  "CREATE VIRTUAL TABLE t1 USING $create"
          499  +
          500  +  execsql [subst {
          501  +    DROP TABLE t1;
          502  +    CREATE VIRTUAL TABLE t1 USING $create;
          503  +    INSERT INTO t1 VALUES('one two five four five', '');
          504  +    INSERT INTO t1 VALUES('', 'one two five four five');
          505  +    INSERT INTO t1 VALUES('one two', 'five four five');
          506  +  }]
          507  +
          508  +  do_fts3query_test 4.$tn.1.1 t1 {one AND five}
          509  +  do_fts3query_test 4.$tn.1.2 t1 {one NEAR five}
          510  +  do_fts3query_test 4.$tn.1.3 t1 {one NEAR/1 five}
          511  +  do_fts3query_test 4.$tn.1.4 t1 {one NEAR/2 five}
          512  +  do_fts3query_test 4.$tn.1.5 t1 {one NEAR/3 five}
          513  +
          514  +  do_test 4.$tn.2 { 
          515  +    set limit [fts3_make_deferrable t1 five]
          516  +    execsql { INSERT INTO t1(t1) VALUES('optimize') }
          517  +    expr {[fts3_zero_long_segments t1 $limit]>0}
          518  +  } {1}
   480    519   
   481         -  foreach {x y} {
   482         -    {one two five four five} {}
   483         -    {} {one two five four five}
   484         -    {one two} {five four five}
   485         -  } {
   486         -    execsql {INSERT INTO t1 VALUES($x, $y)}
   487         -  }
          520  +  do_fts3query_test 4.$tn.3.1 -deferred five t1 {one AND five}
          521  +  do_fts3query_test 4.$tn.3.2 -deferred five t1 {one NEAR five}
          522  +  do_fts3query_test 4.$tn.3.3 -deferred five t1 {one NEAR/1 five}
          523  +  do_fts3query_test 4.$tn.3.4 -deferred five t1 {one NEAR/2 five}
          524  +  do_fts3query_test 4.$tn.3.5 -deferred five t1 {one NEAR/3 five}
   488    525   
   489         -  foreach {tn2 expr} {
   490         -    1     {one AND five}
   491         -    2     {one NEAR five}
   492         -    3     {one NEAR/1 five}
   493         -    4     {one NEAR/2 five}
   494         -    5     {one NEAR/3 five}
   495         -  } {
   496         -    do_fts3query_test 4.$tn.2.$tn2 t1 $expr
   497         -  }
          526  +  do_fts3query_test 4.$tn.4.1 -deferred fi* t1 {on* AND fi*}
          527  +  do_fts3query_test 4.$tn.4.2 -deferred fi* t1 {on* NEAR fi*}
          528  +  do_fts3query_test 4.$tn.4.3 -deferred fi* t1 {on* NEAR/1 fi*}
          529  +  do_fts3query_test 4.$tn.4.4 -deferred fi* t1 {on* NEAR/2 fi*}
          530  +  do_fts3query_test 4.$tn.4.5 -deferred fi* t1 {on* NEAR/3 fi*}
   498    531   }
   499    532   
   500    533   set sqlite_fts3_enable_parentheses $sfep
   501    534   finish_test
   502    535