Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Remove the fts5_test() aux function. Test aux functions using the tcl interface instead. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | fts5 |
Files: | files | file ages | folders |
SHA1: |
67e3ffd950c5347d219a06b33ad51949 |
User & Date: | dan 2014-12-19 20:53:51.092 |
Context
2014-12-22
| ||
21:01 | Fixes and simplifications for the snippet() and highlight() functions. (check-in: ca5d44042a user: dan tags: fts5) | |
2014-12-19
| ||
20:53 | Remove the fts5_test() aux function. Test aux functions using the tcl interface instead. (check-in: 67e3ffd950 user: dan tags: fts5) | |
2014-12-18
| ||
20:01 | Fix a problem with prefix queries and the AND operator. (check-in: 38b3c65e3e user: dan tags: fts5) | |
Changes
Changes to ext/fts5/fts5_aux.c.
︙ | ︙ | |||
837 838 839 840 841 842 843 | } if( rc!=SQLITE_OK ){ sqlite3_result_error_code(pCtx, rc); } } | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 | } if( rc!=SQLITE_OK ){ sqlite3_result_error_code(pCtx, rc); } } int sqlite3Fts5AuxInit(fts5_api *pApi){ struct Builtin { const char *zFunc; /* Function name (nul-terminated) */ void *pUserData; /* User-data pointer */ fts5_extension_function xFunc;/* Callback function */ void (*xDestroy)(void*); /* Destructor function */ } aBuiltin [] = { { "bm25debug", (void*)1, fts5Bm25Function, 0 }, { "snippet", 0, fts5SnippetFunction, 0 }, { "highlight", 0, fts5HighlightFunction, 0 }, { "bm25", 0, fts5Bm25Function, 0 }, }; int rc = SQLITE_OK; /* Return code */ int i; /* To iterate through builtin functions */ |
︙ | ︙ |
Changes to ext/fts5/fts5_tcl.c.
︙ | ︙ | |||
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | }; typedef struct F5tApi F5tApi; struct F5tApi { const Fts5ExtensionApi *pApi; Fts5Context *pFts; }; /* ** api sub-command... ** ** Description... */ static int xF5tApi( void * clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[] ){ struct Sub { const char *zName; int nArg; const char *zMsg; } aSub[] = { | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > > | | > | | > > > > > > > > > > > > | | > > | > > > > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | < > > > > | | < | > > > > > > > > > > > > > > > | 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 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 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | }; typedef struct F5tApi F5tApi; struct F5tApi { const Fts5ExtensionApi *pApi; Fts5Context *pFts; }; static int xTokenizeCb( void *pCtx, const char *zToken, int nToken, int iStart, int iEnd, int iPos ){ F5tFunction *p = (F5tFunction*)pCtx; Tcl_Obj *pEval = Tcl_DuplicateObj(p->pScript); int rc; Tcl_IncrRefCount(pEval); Tcl_ListObjAppendElement(p->interp, pEval, Tcl_NewStringObj(zToken, nToken)); Tcl_ListObjAppendElement(p->interp, pEval, Tcl_NewIntObj(iStart)); Tcl_ListObjAppendElement(p->interp, pEval, Tcl_NewIntObj(iEnd)); Tcl_ListObjAppendElement(p->interp, pEval, Tcl_NewIntObj(iPos)); rc = Tcl_EvalObjEx(p->interp, pEval, 0); Tcl_DecrRefCount(pEval); return rc; } static int xF5tApi(void*, Tcl_Interp*, int, Tcl_Obj *CONST []); static int xQueryPhraseCb( const Fts5ExtensionApi *pApi, Fts5Context *pFts, void *pCtx ){ F5tFunction *p = (F5tFunction*)pCtx; static sqlite3_int64 iCmd = 0; Tcl_Obj *pEval; int rc; char zCmd[64]; F5tApi sApi; sApi.pApi = pApi; sApi.pFts = pFts; sprintf(zCmd, "f5t_2_%lld", iCmd++); Tcl_CreateObjCommand(p->interp, zCmd, xF5tApi, &sApi, 0); pEval = Tcl_DuplicateObj(p->pScript); Tcl_IncrRefCount(pEval); Tcl_ListObjAppendElement(p->interp, pEval, Tcl_NewStringObj(zCmd, -1)); rc = Tcl_EvalObjEx(p->interp, pEval, 0); Tcl_DecrRefCount(pEval); Tcl_DeleteCommand(p->interp, zCmd); return rc; } /* ** api sub-command... ** ** Description... */ static int xF5tApi( void * clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[] ){ struct Sub { const char *zName; int nArg; const char *zMsg; } aSub[] = { { "xColumnCount", 0, "" }, { "xRowCount", 0, "" }, { "xColumnTotalSize", 1, "COL" }, { "xTokenize", 2, "TEXT SCRIPT" }, { "xPhraseCount", 0, "" }, { "xPhraseSize", 1, "PHRASE" }, { "xInstCount", 0, "" }, { "xInst", 1, "IDX" }, { "xRowid", 0, "" }, { "xColumnText", 1, "COL" }, { "xColumnSize", 1, "COL" }, { "xQueryPhrase", 2, "PHRASE SCRIPT" }, { 0, 0, 0} }; int rc; int iSub = 0; F5tApi *p = (F5tApi*)clientData; if( objc<2 ){ Tcl_WrongNumArgs(interp, 1, objv, "SUB-COMMAND"); return TCL_ERROR; } rc = Tcl_GetIndexFromObjStruct( interp, objv[1], aSub, sizeof(aSub[0]), "SUB-COMMAND", 0, &iSub ); if( rc!=TCL_OK ) return rc; if( aSub[iSub].nArg!=objc-2 ){ Tcl_WrongNumArgs(interp, 1, objv, aSub[iSub].zMsg); return TCL_ERROR; } #define CASE(i,str) case i: assert( strcmp(aSub[i].zName, str)==0 ); switch( iSub ){ CASE(0, "xColumnCount") { int nCol; nCol = p->pApi->xColumnCount(p->pFts); if( rc==SQLITE_OK ){ Tcl_SetObjResult(interp, Tcl_NewIntObj(nCol)); } break; } CASE(1, "xRowCount") { sqlite3_int64 nRow; rc = p->pApi->xRowCount(p->pFts, &nRow); if( rc==SQLITE_OK ){ Tcl_SetObjResult(interp, Tcl_NewWideIntObj(nRow)); } break; } CASE(2, "xColumnTotalSize") { int iCol; sqlite3_int64 nSize; if( Tcl_GetIntFromObj(interp, objv[2], &iCol) ) return TCL_ERROR; rc = p->pApi->xColumnTotalSize(p->pFts, iCol, &nSize); if( rc==SQLITE_OK ){ Tcl_SetObjResult(interp, Tcl_NewWideIntObj(nSize)); } break; } CASE(3, "xTokenize") { int nText; char *zText = Tcl_GetStringFromObj(objv[2], &nText); F5tFunction ctx; ctx.interp = interp; ctx.pScript = objv[3]; rc = p->pApi->xTokenize(p->pFts, zText, nText, &ctx, xTokenizeCb); if( rc==SQLITE_OK ){ Tcl_ResetResult(interp); } return rc; } CASE(4, "xPhraseCount") { int nPhrase; nPhrase = p->pApi->xPhraseCount(p->pFts); if( rc==SQLITE_OK ){ Tcl_SetObjResult(interp, Tcl_NewIntObj(nPhrase)); } break; } CASE(5, "xPhraseSize") { int iPhrase; int sz; if( Tcl_GetIntFromObj(interp, objv[2], &iPhrase) ){ return TCL_ERROR; } sz = p->pApi->xPhraseSize(p->pFts, iPhrase); if( rc==SQLITE_OK ){ Tcl_SetObjResult(interp, Tcl_NewIntObj(sz)); } break; } CASE(6, "xInstCount") { int nInst; rc = p->pApi->xInstCount(p->pFts, &nInst); if( rc==SQLITE_OK ){ Tcl_SetObjResult(interp, Tcl_NewIntObj(nInst)); } break; } CASE(7, "xInst") { int iIdx, ip, ic, io; if( Tcl_GetIntFromObj(interp, objv[2], &iIdx) ){ return TCL_ERROR; } rc = p->pApi->xInst(p->pFts, iIdx, &ip, &ic, &io); if( rc==SQLITE_OK ){ Tcl_Obj *pList = Tcl_NewObj(); Tcl_ListObjAppendElement(interp, pList, Tcl_NewIntObj(ip)); Tcl_ListObjAppendElement(interp, pList, Tcl_NewIntObj(ic)); Tcl_ListObjAppendElement(interp, pList, Tcl_NewIntObj(io)); Tcl_SetObjResult(interp, pList); } break; } CASE(8, "xRowid") { sqlite3_int64 iRowid = p->pApi->xRowid(p->pFts); Tcl_SetObjResult(interp, Tcl_NewWideIntObj(iRowid)); break; } CASE(9, "xColumnText") { const char *z = 0; int n = 0; int iCol; if( Tcl_GetIntFromObj(interp, objv[2], &iCol) ){ return TCL_ERROR; } rc = p->pApi->xColumnText(p->pFts, iCol, &z, &n); if( rc==SQLITE_OK ){ Tcl_SetObjResult(interp, Tcl_NewStringObj(z, n)); } break; } CASE(10, "xColumnSize") { int n = 0; int iCol; if( Tcl_GetIntFromObj(interp, objv[2], &iCol) ){ return TCL_ERROR; } rc = p->pApi->xColumnSize(p->pFts, iCol, &n); if( rc==SQLITE_OK ){ Tcl_SetObjResult(interp, Tcl_NewIntObj(n)); } break; } CASE(11, "xQueryPhrase") { int iPhrase; F5tFunction ctx; if( Tcl_GetIntFromObj(interp, objv[2], &iPhrase) ){ return TCL_ERROR; } ctx.interp = interp; ctx.pScript = objv[3]; rc = p->pApi->xQueryPhrase(p->pFts, iPhrase, &ctx, xQueryPhraseCb); if( rc==SQLITE_OK ){ Tcl_ResetResult(interp); } break; } default: assert( 0 ); break; } #undef CASE if( rc!=SQLITE_OK ){ Tcl_AppendResult(interp, "error in api call", 0); return TCL_ERROR; } return TCL_OK; |
︙ | ︙ |
Added test/fts5_common.tcl.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | # 2014 Dec 19 # # The author disclaims copyright to this source code. In place of # a legal notice, here is a blessing: # # May you do good and not evil. # May you find forgiveness for yourself and forgive others. # May you share freely, never taking more than you give. # #*********************************************************************** # proc fts5_test_poslist {cmd} { set res [list] for {set i 0} {$i < [$cmd xInstCount]} {incr i} { lappend res [string map {{ } .} [$cmd xInst $i]] } set res } proc fts5_test_columnsize {cmd} { set res [list] for {set i 0} {$i < [$cmd xColumnCount]} {incr i} { lappend res [$cmd xColumnSize $i] } set res } proc fts5_test_columntext {cmd} { set res [list] for {set i 0} {$i < [$cmd xColumnCount]} {incr i} { lappend res [$cmd xColumnText $i] } set res } proc fts5_test_columntotalsize {cmd} { set res [list] for {set i 0} {$i < [$cmd xColumnCount]} {incr i} { lappend res [$cmd xColumnTotalSize $i] } set res } proc test_append_token {varname token iStart iEnd iPos} { upvar $varname var lappend var $token } proc fts5_test_tokenize {cmd} { set res [list] for {set i 0} {$i < [$cmd xColumnCount]} {incr i} { set tokens [list] $cmd xTokenize [$cmd xColumnText $i] [list test_append_token tokens] lappend res $tokens } set res } proc fts5_test_rowcount {cmd} { $cmd xRowCount } proc test_queryphrase_cb {cnt cmd} { upvar $cnt L for {set i 0} {$i < [$cmd xInstCount]} {incr i} { foreach {ip ic io} [$cmd xInst $i] break set A($ic) 1 } foreach ic [array names A] { lset L $ic [expr {[lindex $L $ic] + 1}] } } proc fts5_test_queryphrase {cmd} { set res [list] for {set i 0} {$i < [$cmd xPhraseCount]} {incr i} { set cnt [list] for {set j 0} {$j < [$cmd xColumnCount]} {incr j} { lappend cnt 0 } $cmd xQueryPhrase $i [list test_queryphrase_cb cnt] lappend res $cnt } set res } proc fts5_test_all {cmd} { set res [list] lappend res columnsize [fts5_test_columnsize $cmd] lappend res columntext [fts5_test_columntext $cmd] lappend res columntotalsize [fts5_test_columntotalsize $cmd] lappend res poslist [fts5_test_poslist $cmd] lappend res tokenize [fts5_test_tokenize $cmd] lappend res rowcount [fts5_test_rowcount $cmd] set res } proc fts5_aux_test_functions {db} { foreach f { fts5_test_columnsize fts5_test_columntext fts5_test_columntotalsize fts5_test_poslist fts5_test_tokenize fts5_test_rowcount fts5_test_all fts5_test_queryphrase } { sqlite3_fts5_create_function $db $f $f } } |
Changes to test/fts5ac.test.
︙ | ︙ | |||
135 136 137 138 139 140 141 | foreach {id x y} $data { execsql { INSERT INTO xx(rowid, x, y) VALUES($id, $x, $y) } } } {} # Usage: # | | > > > > > > > | 135 136 137 138 139 140 141 142 143 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 | foreach {id x y} $data { execsql { INSERT INTO xx(rowid, x, y) VALUES($id, $x, $y) } } } {} # Usage: # # poslist aCol ?-pc VARNAME? ?-near N? ?-col C? -- phrase1 phrase2... # proc poslist {aCol args} { set O(-near) 10 set O(-col) -1 set O(-pc) "" set nOpt [lsearch -exact $args --] if {$nOpt<0} { error "no -- option" } foreach {k v} [lrange $args 0 [expr $nOpt-1]] { if {[info exists O($k)]==0} { error "unrecognized option $k" } set O($k) $v } if {$O(-pc) == ""} { set counter 0 } else { upvar $O(-pc) counter } # Set $phraselist to be a list of phrases. $nPhrase its length. set phraselist [lrange $args [expr $nOpt+1] end] set nPhrase [llength $phraselist] for {set j 0} {$j < [llength $aCol]} {incr j} { for {set i 0} {$i < $nPhrase} {incr i} { |
︙ | ︙ | |||
193 194 195 196 197 198 199 200 | set A($iCol,$iPhrase) [lsort -integer -uniq $A($iCol,$iPhrase)] } } } } set res [list] for {set iPhrase 0} {$iPhrase<$nPhrase} {incr iPhrase} { | > > < | < > > > > > > > > > > > > | 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | set A($iCol,$iPhrase) [lsort -integer -uniq $A($iCol,$iPhrase)] } } } } set res [list] #puts [array names A] for {set iPhrase 0} {$iPhrase<$nPhrase} {incr iPhrase} { for {set iCol 0} {$iCol < [llength $aCol]} {incr iCol} { foreach a $A($iCol,$iPhrase) { lappend res "$counter.$iCol.$a" } } incr counter } #puts $res return $res } # Usage: # # nearset aCol ?-near N? ?-col C? -- phrase1 phrase2... # proc nearset {args} { set plist [poslist {*}$args] return [expr [llength [lindex $plist 0]]>0] } proc instcompare {lhs rhs} { foreach {p1 c1 o1} [split $lhs .] {} foreach {p2 c2 o2} [split $rhs .] {} set res [expr $c1 - $c2] if {$res==0} { set res [expr $o1 - $o2] } if {$res==0} { set res [expr $p1 - $p2] } return $res } # Argument $expr is an FTS5 match expression designed to be executed against # an FTS5 table with the following schema: # # CREATE VIRTUAL TABLE xy USING fts5(x, y); # # Assuming the table contains the same records as stored int the global |
︙ | ︙ | |||
243 244 245 246 247 248 249 250 | #puts $tclexpr foreach {id x y} $::data { set cols [list $x $y] if $tclexpr { if {$bPos} { set N [regexp -all -inline {\[nearset [^\]]*\]} $tclexpr] set rowres [list] foreach phrase $N { | > | > > > > > > > > > > > > | | 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | #puts $tclexpr foreach {id x y} $::data { set cols [list $x $y] if $tclexpr { if {$bPos} { set N [regexp -all -inline {\[nearset [^\]]*\]} $tclexpr] set rowres [list] set cnt 0 foreach phrase $N { set arglist [string range $phrase 9 end-1] set cmd "poslist [lindex $arglist 0] -pc cnt [lrange $arglist 1 end]" set pos [eval $cmd] set rowres [concat $rowres $pos] } set rowres [lsort -command instcompare $rowres] lappend res [list $id $rowres] } else { lappend res $id } } } if {$bAsc} { set res [lsort -integer -increasing -index 0 $res] } else { set res [lsort -integer -decreasing -index 0 $res] } return [concat {*}$res] } # # End of test code #------------------------------------------------------------------------- proc fts5_test_poslist {cmd} { set res [list] for {set i 0} {$i < [$cmd xInstCount]} {incr i} { lappend res [string map {{ } .} [$cmd xInst $i]] } set res } sqlite3_fts5_create_function db fts5_test_poslist fts5_test_poslist #------------------------------------------------------------------------- # Test phrase queries. # foreach {tn phrase} { 1 "o" 2 "b q" 3 "e a e" 4 "m d g q q b k b w f q q p p" 5 "l o o l v v k" 6 "a" 7 "b" 8 "c" 9 "no" 10 "L O O L V V K" } { set expr "\"$phrase\"" set res [matchdata 1 $expr] do_execsql_test 1.2.$tn.[llength $res] { SELECT rowid, fts5_test_poslist(xx) FROM xx WHERE xx match $expr } $res } #------------------------------------------------------------------------- # Test some AND and OR queries. # foreach {tn expr} { |
︙ | ︙ | |||
309 310 311 312 313 314 315 | 2.3 "d+c OR u" 2.4 "d+c OR u+d" 3.1 { a AND b AND c } } { set res [matchdata 1 $expr] do_execsql_test 2.$tn.[llength $res] { | | | | | | | 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 | 2.3 "d+c OR u" 2.4 "d+c OR u+d" 3.1 { a AND b AND c } } { set res [matchdata 1 $expr] do_execsql_test 2.$tn.[llength $res] { SELECT rowid, fts5_test_poslist(xx) FROM xx WHERE xx match $expr } $res } #------------------------------------------------------------------------- # Queries on a specific column. # foreach {tn expr} { 1 "x:a" 2 "y:a" 3 "x:b" 4 "y:b" } { set res [matchdata 1 $expr] do_execsql_test 3.$tn.[llength $res] { SELECT rowid, fts5_test_poslist(xx) FROM xx WHERE xx match $expr } $res } #------------------------------------------------------------------------- # Some NEAR queries. # foreach {tn expr} { 1 "NEAR(a b)" 2 "NEAR(r c)" 2 { NEAR(r c, 5) } 3 { NEAR(r c, 3) } 4 { NEAR(r c, 2) } 5 { NEAR(r c, 0) } 6 { NEAR(a b c) } 7 { NEAR(a b c, 8) } 8 { x : NEAR(r c) } 9 { y : NEAR(r c) } } { set res [matchdata 1 $expr] do_execsql_test 4.1.$tn.[llength $res] { SELECT rowid, fts5_test_poslist(xx) FROM xx WHERE xx match $expr } $res } do_test 4.1 { poslist {{a b c}} -- a } {0.0.0} do_test 4.2 { poslist {{a b c}} -- c } {0.0.2} foreach {tn expr tclexpr} { 1 {a b} {[N $x -- {a}] && [N $x -- {b}]} } { do_execsql_test 5.$tn {SELECT fts5_expr_tcl($expr, 'N $x')} [list $tclexpr] } |
︙ | ︙ |
Changes to test/fts5ae.test.
︙ | ︙ | |||
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | INSERT INTO t1 VALUES('hello', 'hello'); } do_execsql_test 1.4.2 { SELECT rowid FROM t1 WHERE t1 MATCH 'hello' ORDER BY rowid ASC; } {1 2 4} #------------------------------------------------------------------------- # do_execsql_test 2.0 { CREATE VIRTUAL TABLE t2 USING fts5(x, y); INSERT INTO t2 VALUES('u t l w w m s', 'm f m o l t k o p e'); INSERT INTO t2 VALUES('f g q e l n d m z x q', 'z s i i i m f w w f n g p'); } do_execsql_test 2.1 { | > | | | | | | | | | | | | | | | | | < > > | | | | > | > | 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 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 205 206 207 208 209 | INSERT INTO t1 VALUES('hello', 'hello'); } do_execsql_test 1.4.2 { SELECT rowid FROM t1 WHERE t1 MATCH 'hello' ORDER BY rowid ASC; } {1 2 4} fts5_aux_test_functions db #------------------------------------------------------------------------- # do_execsql_test 2.0 { CREATE VIRTUAL TABLE t2 USING fts5(x, y); INSERT INTO t2 VALUES('u t l w w m s', 'm f m o l t k o p e'); INSERT INTO t2 VALUES('f g q e l n d m z x q', 'z s i i i m f w w f n g p'); } do_execsql_test 2.1 { SELECT rowid, fts5_test_poslist(t2) FROM t2 WHERE t2 MATCH 'm' ORDER BY rowid; } { 1 {0.0.5 0.1.0 0.1.2} 2 {0.0.7 0.1.5} } do_execsql_test 2.2 { SELECT rowid, fts5_test_poslist(t2) FROM t2 WHERE t2 MATCH 'u OR q' ORDER BY rowid; } { 1 {0.0.0} 2 {1.0.2 1.0.10} } do_execsql_test 2.3 { SELECT rowid, fts5_test_poslist(t2) FROM t2 WHERE t2 MATCH 'y:o' ORDER BY rowid; } { 1 {0.1.3 0.1.7} } #------------------------------------------------------------------------- # do_execsql_test 3.0 { CREATE VIRTUAL TABLE t3 USING fts5(x, y); INSERT INTO t3 VALUES( 'j f h o x x a z g b a f a m i b', 'j z c z y x w t'); INSERT INTO t3 VALUES( 'r c', ''); } do_execsql_test 3.1 { SELECT rowid, fts5_test_poslist(t3) FROM t3 WHERE t3 MATCH 'NEAR(a b)'; } { 1 {0.0.6 1.0.9 0.0.10 0.0.12 1.0.15} } do_execsql_test 3.2 { SELECT rowid, fts5_test_poslist(t3) FROM t3 WHERE t3 MATCH 'NEAR(r c)'; } { 2 {0.0.0 1.0.1} } do_execsql_test 3.3 { INSERT INTO t3 VALUES('k x j r m a d o i z j', 'r t t t f e b r x i v j v g o'); SELECT rowid, fts5_test_poslist(t3) FROM t3 WHERE t3 MATCH 'a OR b AND c'; } { 3 0.0.5 1 {0.0.6 1.0.9 0.0.10 0.0.12 1.0.15 2.1.2} } #------------------------------------------------------------------------- # do_execsql_test 4.0 { CREATE VIRTUAL TABLE t4 USING fts5(x, y); INSERT INTO t4 VALUES('k x j r m a d o i z j', 'r t t t f e b r x i v j v g o'); } do_execsql_test 4.1 { SELECT rowid, fts5_test_poslist(t4) FROM t4 WHERE t4 MATCH 'a OR b AND c'; } { 1 0.0.5 } #------------------------------------------------------------------------- # Test that the xColumnSize() and xColumnAvgsize() APIs work. # reset_db fts5_aux_test_functions db do_execsql_test 5.1 { CREATE VIRTUAL TABLE t5 USING fts5(x, y); INSERT INTO t5 VALUES('a b c d', 'e f g h i j'); INSERT INTO t5 VALUES('', 'a'); INSERT INTO t5 VALUES('a', ''); } do_execsql_test 5.2 { SELECT rowid, fts5_test_columnsize(t5) FROM t5 WHERE t5 MATCH 'a' ORDER BY rowid DESC; } { 3 {1 0} 2 {0 1} 1 {4 6} } do_execsql_test 5.2 { SELECT rowid, fts5_test_columntext(t5) FROM t5 WHERE t5 MATCH 'a' ORDER BY rowid DESC; } { 3 {a {}} 2 {{} a} 1 {{a b c d} {e f g h i j}} } do_execsql_test 5.3 { SELECT rowid, fts5_test_columntotalsize(t5) FROM t5 WHERE t5 MATCH 'a' ORDER BY rowid DESC; } { 3 {5 7} 2 {5 7} 1 {5 7} } do_execsql_test 5.4 { INSERT INTO t5 VALUES('x y z', 'v w x y z'); SELECT rowid, fts5_test_columntotalsize(t5) FROM t5 WHERE t5 MATCH 'a' ORDER BY rowid DESC; } { 3 {8 12} 2 {8 12} 1 {8 12} } #------------------------------------------------------------------------- # Test the xTokenize() API # reset_db fts5_aux_test_functions db do_execsql_test 6.1 { CREATE VIRTUAL TABLE t6 USING fts5(x, y); INSERT INTO t6 VALUES('There are more', 'things in heaven and earth'); INSERT INTO t6 VALUES(', Horatio, Than are', 'dreamt of in your philosophy.'); } do_execsql_test 6.2 { SELECT rowid, fts5_test_tokenize(t6) FROM t6 WHERE t6 MATCH 't*' } { 2 {{horatio than are} {dreamt of in your philosophy}} 1 {{there are more} {things in heaven and earth}} } #------------------------------------------------------------------------- # Test the xQueryPhrase() API # reset_db fts5_aux_test_functions db do_execsql_test 7.1 { CREATE VIRTUAL TABLE t7 USING fts5(x, y); } do_test 7.2 { foreach {x y} { {q i b w s a a e l o} {i b z a l f p t e u} {b a z t a l o x d i} {b p a d b f h d w y} |
︙ | ︙ | |||
217 218 219 220 221 222 223 | 2 b {{3 4}} 3 c {{2 1}} 4 d {{2 2}} 5 {a AND b} {{4 2} {3 4}} 6 {a OR b OR c OR d} {{4 2} {3 4} {2 1} {2 2}} } { do_execsql_test 7.3.$tn { | | | | 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | 2 b {{3 4}} 3 c {{2 1}} 4 d {{2 2}} 5 {a AND b} {{4 2} {3 4}} 6 {a OR b OR c OR d} {{4 2} {3 4} {2 1} {2 2}} } { do_execsql_test 7.3.$tn { SELECT fts5_test_queryphrase(t7) FROM t7 WHERE t7 MATCH $q LIMIT 1 } [list $res] } do_execsql_test 7.4 { SELECT fts5_test_rowcount(t7) FROM t7 WHERE t7 MATCH 'a'; } {5 5 5 5} #do_execsql_test 7.4 { # SELECT rowid, bm25debug(t7) FROM t7 WHERE t7 MATCH 'a'; #} {5 5 5 5} # |
︙ | ︙ |
Changes to test/fts5ag.test.
︙ | ︙ | |||
91 92 93 94 95 96 97 98 99 | {l j s g k j k h z l} {p v d a t x d e q u} {r l u z b m g k s j} {i e y d u x d i n l} {p f z k m m w p u l} {z l p m r q w n d a} } { execsql { INSERT INTO t1 VALUES($x, $y, $z) } } set {} {} } {} proc do_fts5ag_test {tn E} { | > > | | | 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | {l j s g k j k h z l} {p v d a t x d e q u} {r l u z b m g k s j} {i e y d u x d i n l} {p f z k m m w p u l} {z l p m r q w n d a} } { execsql { INSERT INTO t1 VALUES($x, $y, $z) } } set {} {} } {} fts5_aux_test_functions db proc do_fts5ag_test {tn E} { set q1 {SELECT fts5_test_all(t1) FROM t1 WHERE t1 MATCH $E ORDER BY rank} set q2 {SELECT fts5_test_all(t1) FROM t1 WHERE t1 MATCH $E ORDER BY bm25(t1)} set res [execsql $q1] set expected [execsql $q2] uplevel [list do_test $tn.1 [list set {} $res] $expected] append q1 " DESC" append q2 " DESC" |
︙ | ︙ |
Changes to test/tester.tcl.
︙ | ︙ | |||
1914 1915 1916 1917 1918 1919 1920 | # few test cases that deliberately corrupt database files should rescind # this setting by invoking "database_can_be_corrupt" # database_never_corrupt source $testdir/thread_common.tcl source $testdir/malloc_common.tcl | > | 1914 1915 1916 1917 1918 1919 1920 1921 | # few test cases that deliberately corrupt database files should rescind # this setting by invoking "database_can_be_corrupt" # database_never_corrupt source $testdir/thread_common.tcl source $testdir/malloc_common.tcl source $testdir/fts5_common.tcl |