/ Check-in [699b8843]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Merge trunk changes with sessions branch.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | sessions
Files: files | file ages | folders
SHA1: 699b884383f735fb9630d87d25dab61c97dc4485
User & Date: dan 2011-06-20 11:17:11
Original Comment: (no comment)
Context
2011-06-21
01:29
Merge the latest trunk changes into the sessions branch. check-in: f3d148e0 user: drh tags: sessions
2011-06-20
11:17
Merge trunk changes with sessions branch. check-in: 699b8843 user: dan tags: sessions
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:44
Merge the latest trunk changes into the sessions branch. check-in: 4c5e276c user: drh tags: sessions
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ext/fts3/fts3_test.c.

14
15
16
17
18
19
20



21
22
23
24
25
26
27
** testing. It contains a Tcl command that can be used to test if a document
** matches an FTS NEAR expression.
*/

#include <tcl.h>
#include <string.h>
#include <assert.h>




#define NM_MAX_TOKEN 12

typedef struct NearPhrase NearPhrase;
typedef struct NearDocument NearDocument;
typedef struct NearToken NearToken;








>
>
>







14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
** testing. It contains a Tcl command that can be used to test if a document
** matches an FTS NEAR expression.
*/

#include <tcl.h>
#include <string.h>
#include <assert.h>

/* Required so that the "ifdef SQLITE_ENABLE_FTS3" below works */
#include "fts3Int.h"

#define NM_MAX_TOKEN 12

typedef struct NearPhrase NearPhrase;
typedef struct NearDocument NearDocument;
typedef struct NearToken NearToken;

Changes to src/tclsqlite.c.

3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
....
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
    extern int SqliteSuperlock_Init(Tcl_Interp*);
    extern int SqlitetestSyscall_Init(Tcl_Interp*);
    extern int Sqlitetestfuzzer_Init(Tcl_Interp*);
    extern int Sqlitetestwholenumber_Init(Tcl_Interp*);
#if defined(SQLITE_ENABLE_SESSION) && defined(SQLITE_ENABLE_PREUPDATE_HOOK)
    extern int TestSession_Init(Tcl_Interp*);
#endif
#ifdef SQLITE_ENABLE_FTS3
    extern int Sqlitetestfts3_Init(Tcl_Interp *interp);
#endif

#ifdef SQLITE_ENABLE_ZIPVFS
    extern int Zipvfs_Init(Tcl_Interp*);
    Zipvfs_Init(interp);
#endif
................................................................................
    SqliteSuperlock_Init(interp);
    SqlitetestSyscall_Init(interp);
    Sqlitetestfuzzer_Init(interp);
    Sqlitetestwholenumber_Init(interp);
#if defined(SQLITE_ENABLE_SESSION) && defined(SQLITE_ENABLE_PREUPDATE_HOOK)
    TestSession_Init(interp);
#endif
#ifdef SQLITE_ENABLE_FTS3
    Sqlitetestfts3_Init(interp);
#endif

    Tcl_CreateObjCommand(interp,"load_testfixture_extensions",init_all_cmd,0,0);

#ifdef SQLITE_SSE
    Sqlitetestsse_Init(interp);







|







 







|







3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
....
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
    extern int SqliteSuperlock_Init(Tcl_Interp*);
    extern int SqlitetestSyscall_Init(Tcl_Interp*);
    extern int Sqlitetestfuzzer_Init(Tcl_Interp*);
    extern int Sqlitetestwholenumber_Init(Tcl_Interp*);
#if defined(SQLITE_ENABLE_SESSION) && defined(SQLITE_ENABLE_PREUPDATE_HOOK)
    extern int TestSession_Init(Tcl_Interp*);
#endif
#if defined(SQLITE_ENABLE_FTS3) || defined(SQLITE_ENABLE_FTS4)
    extern int Sqlitetestfts3_Init(Tcl_Interp *interp);
#endif

#ifdef SQLITE_ENABLE_ZIPVFS
    extern int Zipvfs_Init(Tcl_Interp*);
    Zipvfs_Init(interp);
#endif
................................................................................
    SqliteSuperlock_Init(interp);
    SqlitetestSyscall_Init(interp);
    Sqlitetestfuzzer_Init(interp);
    Sqlitetestwholenumber_Init(interp);
#if defined(SQLITE_ENABLE_SESSION) && defined(SQLITE_ENABLE_PREUPDATE_HOOK)
    TestSession_Init(interp);
#endif
#if defined(SQLITE_ENABLE_FTS3) || defined(SQLITE_ENABLE_FTS4)
    Sqlitetestfts3_Init(interp);
#endif

    Tcl_CreateObjCommand(interp,"load_testfixture_extensions",init_all_cmd,0,0);

#ifdef SQLITE_SSE
    Sqlitetestsse_Init(interp);

Changes to test/fts3auto.test.

144
145
146
147
148
149
150
151


152












153












154
155
156
157
158
159
160
161
162
163
164
165
166
167



168
169
170
171
172
173
174
175
...
179
180
181
182
183
184
185

186
187



188
189
190
191
192
193
194
...
532
533
534
535
536
537
538
539
540
541

542
543
544
545
546
547
548
...
582
583
584
585
586
587
588
589


































590
591
592
  set scan(littleEndian) i*
  set scan(bigEndian) I*
  binary scan $blob $scan($::tcl_platform(byteOrder)) r
  return $r
}
db func mit mit

proc fix_near_expr {expr} { 


  set out [list]












  lappend out [lindex $expr 0]












  foreach {a b} [lrange $expr 1 end] {
    if {[string match -nocase near $a]}   { set a 10 }
    if {[string match -nocase near/* $a]} { set a [string range $a 5 end] }
    lappend out $a
    lappend out $b
  }
  return $out
}

proc get_single_near_results {tbl expr deferred arrayvar nullvar} {
  upvar $arrayvar aMatchinfo
  upvar $nullvar nullentry
  catch {array unset aMatchinfo}




  set expr [fix_near_expr $expr]

  # Calculate the expected results using [fts3_near_match]. The following
  # loop populates the "hits" and "counts" arrays as follows:
  # 
  #   1. For each document in the table that matches the NEAR expression,
  #      hits($docid) is set to 1. The set of docids that match the expression
  #      can therefore be found using [array names hits].
................................................................................
  #
  set res [list]
  catch { array unset hits }
  db eval "SELECT docid, * FROM $tbl" d {
    set iCol 0
    foreach col [lrange $d(*) 1 end] {
      set docid $d(docid)

      set hit [fts3_near_match $d($col) $expr -p counts($docid,$iCol)]
      if {$hit} { set hits($docid) 1 }



      incr iCol
    }
  }
  set nPhrase [expr ([llength $expr]+1)/2]
  set nCol $iCol

  # This block populates the nHit and nDoc arrays. For each phrase/column
................................................................................
}

#--------------------------------------------------------------------------
# The following test cases - fts3auto-5.* - focus on using prefix indexes.
#
set chunkconfig [fts3_configure_incr_load 1 1]
foreach {tn create pending} {
  2    "fts4(a, b, order=ASC, prefix=1)"             1

  1    "fts4(a, b)"                                  1

  3    "fts4(a, b, order=ASC,  prefix=1,3)"          0
  4    "fts4(a, b, order=DESC, prefix=2,4)"          0
  5    "fts4(a, b, order=DESC, prefix=1)"            0
  6    "fts4(a, b, order=ASC,  prefix=1,3)"          0
} {

  execsql [subst {
................................................................................
  do_fts3query_test 5.$tn.1.5 t1 {a*}
  do_fts3query_test 5.$tn.1.6 t1 {th* NEAR/5 a* NEAR/5 w*}
  do_fts3query_test 5.$tn.1.7 t1 {"b* th* art* fair*"}

  if {$pending} {execsql COMMIT}
}
eval fts3_configure_incr_load $chunkconfig



































set sqlite_fts3_enable_parentheses $sfep
finish_test








|
>
>

>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>




|









>
>
>
|







 







>
|
|
>
>
>







 







<
<

>







 








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
...
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
...
565
566
567
568
569
570
571


572
573
574
575
576
577
578
579
580
...
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
  set scan(littleEndian) i*
  set scan(bigEndian) I*
  binary scan $blob $scan($::tcl_platform(byteOrder)) r
  return $r
}
db func mit mit

proc fix_phrase_expr {cols expr colfiltervar} {
  upvar $colfiltervar iColFilter

  set out [list]
  foreach t $expr {
    if {[string match *:* $t]} {
      set col [lindex [split $t :] 0]
      set t   [lindex [split $t :] 1]
      set iCol [lsearch $cols $col]
      if {$iCol<0} { error "unknown column: $col" }
      if {$iColFilter < 0} {
        set iColFilter $iCol
      } elseif {$iColFilter != $iCol} {
        set iColFilter [llength $cols]
      }
    }
    lappend out $t
  }

  return $out
}

proc fix_near_expr {cols expr colfiltervar} { 
  upvar $colfiltervar iColFilter
 
  set iColFilter -1

  set out [list]
  lappend out [fix_phrase_expr $cols [lindex $expr 0] iColFilter]
  foreach {a b} [lrange $expr 1 end] {
    if {[string match -nocase near $a]}   { set a 10 }
    if {[string match -nocase near/* $a]} { set a [string range $a 5 end] }
    lappend out $a
    lappend out [fix_phrase_expr $cols $b iColFilter]
  }
  return $out
}

proc get_single_near_results {tbl expr deferred arrayvar nullvar} {
  upvar $arrayvar aMatchinfo
  upvar $nullvar nullentry
  catch {array unset aMatchinfo}

  set cols [list]
  set miss [list]
  db eval "PRAGMA table_info($tbl)" A { lappend cols $A(name) ; lappend miss 0 }
  set expr [fix_near_expr $cols $expr iColFilter]

  # Calculate the expected results using [fts3_near_match]. The following
  # loop populates the "hits" and "counts" arrays as follows:
  # 
  #   1. For each document in the table that matches the NEAR expression,
  #      hits($docid) is set to 1. The set of docids that match the expression
  #      can therefore be found using [array names hits].
................................................................................
  #
  set res [list]
  catch { array unset hits }
  db eval "SELECT docid, * FROM $tbl" d {
    set iCol 0
    foreach col [lrange $d(*) 1 end] {
      set docid $d(docid)
      if {$iColFilter<0 || $iCol==$iColFilter} {
        set hit [fts3_near_match $d($col) $expr -p counts($docid,$iCol)]
        if {$hit} { set hits($docid) 1 }
      } else {
        set counts($docid,$iCol) $miss
      }
      incr iCol
    }
  }
  set nPhrase [expr ([llength $expr]+1)/2]
  set nCol $iCol

  # This block populates the nHit and nDoc arrays. For each phrase/column
................................................................................
}

#--------------------------------------------------------------------------
# The following test cases - fts3auto-5.* - focus on using prefix indexes.
#
set chunkconfig [fts3_configure_incr_load 1 1]
foreach {tn create pending} {


  1    "fts4(a, b)"                                  1
  2    "fts4(a, b, order=ASC, prefix=1)"             1
  3    "fts4(a, b, order=ASC,  prefix=1,3)"          0
  4    "fts4(a, b, order=DESC, prefix=2,4)"          0
  5    "fts4(a, b, order=DESC, prefix=1)"            0
  6    "fts4(a, b, order=ASC,  prefix=1,3)"          0
} {

  execsql [subst {
................................................................................
  do_fts3query_test 5.$tn.1.5 t1 {a*}
  do_fts3query_test 5.$tn.1.6 t1 {th* NEAR/5 a* NEAR/5 w*}
  do_fts3query_test 5.$tn.1.7 t1 {"b* th* art* fair*"}

  if {$pending} {execsql COMMIT}
}
eval fts3_configure_incr_load $chunkconfig

foreach {tn pending create} {
  1    0 "fts4(a, b, c, d)"
  2    1 "fts4(a, b, c, d)"
  3    0 "fts4(a, b, c, d, order=DESC)"
  4    1 "fts4(a, b, c, d, order=DESC)"
} {
  execsql [subst {
    DROP TABLE IF EXISTS t1;
    CREATE VIRTUAL TABLE t1 USING $create;
  }]


  if {$pending} { execsql BEGIN }

  foreach {a b c d} {
    "A B C" "D E F" "G H I" "J K L"
    "B C D" "E F G" "H I J" "K L A"
    "C D E" "F G H" "I J K" "L A B"
    "D E F" "G H I" "J K L" "A B C"
    "E F G" "H I J" "K L A" "B C D"
    "F G H" "I J K" "L A B" "C D E"
  } {
    execsql { INSERT INTO t1 VALUES($a, $b, $c, $d) }
  }

  do_fts3query_test 6.$tn.1 t1 {b:G}
  do_fts3query_test 6.$tn.2 t1 {b:G AND c:I}
  do_fts3query_test 6.$tn.3 t1 {b:G NEAR c:I}
  do_fts3query_test 6.$tn.4 t1 {a:C OR b:G OR c:K OR d:C}
  do_fts3query_test 6.$tn.5 t1 {a:G OR b:G}

  catchsql { COMMIT }
}

set sqlite_fts3_enable_parentheses $sfep
finish_test