/ Check-in [d138b0e6]
Login

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

Overview
Comment:Add tests for the "column:term" query syntax to fts3auto.test.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: d138b0e65953c529619d64e662bdb5478d7d79c3
User & Date: dan 2011-06-20 10:46:49
Context
2011-06-20
11:15
Fix a problem where FTS test code was not being included in the testfixture build when SQLITE_ENABLE_FTS4 was defined. check-in: e539d08a user: dan tags: trunk
10:46
Add tests for the "column:term" query syntax to fts3auto.test. check-in: d138b0e6 user: dan tags: trunk
2011-06-19
21:17
Do not run test tkt-2d1a5c67d.test in the inmemory_journal permutation since that test requires WAL mode which does not work with inmemory_journal. check-in: 228c43c7 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to test/fts3auto.test.

   144    144     set scan(littleEndian) i*
   145    145     set scan(bigEndian) I*
   146    146     binary scan $blob $scan($::tcl_platform(byteOrder)) r
   147    147     return $r
   148    148   }
   149    149   db func mit mit
   150    150   
   151         -proc fix_near_expr {expr} { 
          151  +proc fix_phrase_expr {cols expr colfiltervar} {
          152  +  upvar $colfiltervar iColFilter
          153  +
          154  +  set out [list]
          155  +  foreach t $expr {
          156  +    if {[string match *:* $t]} {
          157  +      set col [lindex [split $t :] 0]
          158  +      set t   [lindex [split $t :] 1]
          159  +      set iCol [lsearch $cols $col]
          160  +      if {$iCol<0} { error "unknown column: $col" }
          161  +      if {$iColFilter < 0} {
          162  +        set iColFilter $iCol
          163  +      } elseif {$iColFilter != $iCol} {
          164  +        set iColFilter [llength $cols]
          165  +      }
          166  +    }
          167  +    lappend out $t
          168  +  }
          169  +
          170  +  return $out
          171  +}
          172  +
          173  +proc fix_near_expr {cols expr colfiltervar} { 
          174  +  upvar $colfiltervar iColFilter
          175  + 
          176  +  set iColFilter -1
          177  +
   152    178     set out [list]
   153         -  lappend out [lindex $expr 0]
          179  +  lappend out [fix_phrase_expr $cols [lindex $expr 0] iColFilter]
   154    180     foreach {a b} [lrange $expr 1 end] {
   155    181       if {[string match -nocase near $a]}   { set a 10 }
   156    182       if {[string match -nocase near/* $a]} { set a [string range $a 5 end] }
   157    183       lappend out $a
   158         -    lappend out $b
          184  +    lappend out [fix_phrase_expr $cols $b iColFilter]
   159    185     }
   160    186     return $out
   161    187   }
   162    188   
   163    189   proc get_single_near_results {tbl expr deferred arrayvar nullvar} {
   164    190     upvar $arrayvar aMatchinfo
   165    191     upvar $nullvar nullentry
   166    192     catch {array unset aMatchinfo}
   167    193   
   168         -  set expr [fix_near_expr $expr]
          194  +  set cols [list]
          195  +  set miss [list]
          196  +  db eval "PRAGMA table_info($tbl)" A { lappend cols $A(name) ; lappend miss 0 }
          197  +  set expr [fix_near_expr $cols $expr iColFilter]
   169    198   
   170    199     # Calculate the expected results using [fts3_near_match]. The following
   171    200     # loop populates the "hits" and "counts" arrays as follows:
   172    201     # 
   173    202     #   1. For each document in the table that matches the NEAR expression,
   174    203     #      hits($docid) is set to 1. The set of docids that match the expression
   175    204     #      can therefore be found using [array names hits].
................................................................................
   179    208     #
   180    209     set res [list]
   181    210     catch { array unset hits }
   182    211     db eval "SELECT docid, * FROM $tbl" d {
   183    212       set iCol 0
   184    213       foreach col [lrange $d(*) 1 end] {
   185    214         set docid $d(docid)
   186         -      set hit [fts3_near_match $d($col) $expr -p counts($docid,$iCol)]
   187         -      if {$hit} { set hits($docid) 1 }
          215  +      if {$iColFilter<0 || $iCol==$iColFilter} {
          216  +        set hit [fts3_near_match $d($col) $expr -p counts($docid,$iCol)]
          217  +        if {$hit} { set hits($docid) 1 }
          218  +      } else {
          219  +        set counts($docid,$iCol) $miss
          220  +      }
   188    221         incr iCol
   189    222       }
   190    223     }
   191    224     set nPhrase [expr ([llength $expr]+1)/2]
   192    225     set nCol $iCol
   193    226   
   194    227     # This block populates the nHit and nDoc arrays. For each phrase/column
................................................................................
   532    565   }
   533    566   
   534    567   #--------------------------------------------------------------------------
   535    568   # The following test cases - fts3auto-5.* - focus on using prefix indexes.
   536    569   #
   537    570   set chunkconfig [fts3_configure_incr_load 1 1]
   538    571   foreach {tn create pending} {
   539         -  2    "fts4(a, b, order=ASC, prefix=1)"             1
   540         -
   541    572     1    "fts4(a, b)"                                  1
          573  +  2    "fts4(a, b, order=ASC, prefix=1)"             1
   542    574     3    "fts4(a, b, order=ASC,  prefix=1,3)"          0
   543    575     4    "fts4(a, b, order=DESC, prefix=2,4)"          0
   544    576     5    "fts4(a, b, order=DESC, prefix=1)"            0
   545    577     6    "fts4(a, b, order=ASC,  prefix=1,3)"          0
   546    578   } {
   547    579   
   548    580     execsql [subst {
................................................................................
   582    614     do_fts3query_test 5.$tn.1.5 t1 {a*}
   583    615     do_fts3query_test 5.$tn.1.6 t1 {th* NEAR/5 a* NEAR/5 w*}
   584    616     do_fts3query_test 5.$tn.1.7 t1 {"b* th* art* fair*"}
   585    617   
   586    618     if {$pending} {execsql COMMIT}
   587    619   }
   588    620   eval fts3_configure_incr_load $chunkconfig
          621  +
          622  +foreach {tn pending create} {
          623  +  1    0 "fts4(a, b, c, d)"
          624  +  2    1 "fts4(a, b, c, d)"
          625  +  3    0 "fts4(a, b, c, d, order=DESC)"
          626  +  4    1 "fts4(a, b, c, d, order=DESC)"
          627  +} {
          628  +  execsql [subst {
          629  +    DROP TABLE IF EXISTS t1;
          630  +    CREATE VIRTUAL TABLE t1 USING $create;
          631  +  }]
          632  +
          633  +
          634  +  if {$pending} { execsql BEGIN }
          635  +
          636  +  foreach {a b c d} {
          637  +    "A B C" "D E F" "G H I" "J K L"
          638  +    "B C D" "E F G" "H I J" "K L A"
          639  +    "C D E" "F G H" "I J K" "L A B"
          640  +    "D E F" "G H I" "J K L" "A B C"
          641  +    "E F G" "H I J" "K L A" "B C D"
          642  +    "F G H" "I J K" "L A B" "C D E"
          643  +  } {
          644  +    execsql { INSERT INTO t1 VALUES($a, $b, $c, $d) }
          645  +  }
          646  +
          647  +  do_fts3query_test 6.$tn.1 t1 {b:G}
          648  +  do_fts3query_test 6.$tn.2 t1 {b:G AND c:I}
          649  +  do_fts3query_test 6.$tn.3 t1 {b:G NEAR c:I}
          650  +  do_fts3query_test 6.$tn.4 t1 {a:C OR b:G OR c:K OR d:C}
          651  +  do_fts3query_test 6.$tn.5 t1 {a:G OR b:G}
          652  +
          653  +  catchsql { COMMIT }
          654  +}
   589    655   
   590    656   set sqlite_fts3_enable_parentheses $sfep
   591    657   finish_test
   592    658