PageRenderTime 25ms CodeModel.GetById 36ms RepoModel.GetById 1ms app.codeStats 0ms

/test/fts3auto.test

https://bitbucket.org/aware/sqlite
Unknown | 710 lines | 621 code | 89 blank | 0 comment | 0 complexity | ba33032f65f87a780d2626ce71cb3e30 MD5 | raw file
  1. # 2011 June 10
  2. #
  3. # May you do good and not evil.
  4. # May you find forgiveness for yourself and forgive others.
  5. # May you share freely, never taking more than you give.
  6. #
  7. #***********************************************************************
  8. #
  9. set testdir [file dirname $argv0]
  10. source $testdir/tester.tcl
  11. # If this build does not include FTS3, skip the tests in this file.
  12. #
  13. ifcapable !fts3 { finish_test ; return }
  14. source $testdir/fts3_common.tcl
  15. source $testdir/malloc_common.tcl
  16. set testprefix fts3auto
  17. set sfep $sqlite_fts3_enable_parentheses
  18. set sqlite_fts3_enable_parentheses 1
  19. #--------------------------------------------------------------------------
  20. # Start of Tcl infrastructure used by tests. The entry points are:
  21. #
  22. # do_fts3query_test
  23. # fts3_make_deferrable
  24. # fts3_zero_long_segments
  25. #
  26. #
  27. # do_fts3query_test TESTNAME ?OPTIONS? TABLE MATCHEXPR
  28. #
  29. # This proc runs several test cases on FTS3/4 table $TABLE using match
  30. # expression $MATCHEXPR. All documents in $TABLE must be formatted so that
  31. # they can be "tokenized" using the Tcl list commands (llength, lindex etc.).
  32. # The name and column names used by $TABLE must not require any quoting or
  33. # escaping when used in SQL statements.
  34. #
  35. # $MATCHINFO may be any expression accepted by the FTS4 MATCH operator,
  36. # except that the "<column-name>:token" syntax is not supported. Tcl list
  37. # commands are used to tokenize the expression. Any parenthesis must appear
  38. # either as separate list elements, or as the first (for opening) or last
  39. # (for closing) character of a list element. i.e. the expression "(a OR b)c"
  40. # will not be parsed correctly, but "( a OR b) c" will.
  41. #
  42. # Available OPTIONS are:
  43. #
  44. # -deferred TOKENLIST
  45. #
  46. # If the "deferred" option is supplied, it is passed a list of tokens that
  47. # are deferred by FTS and result in the relevant matchinfo() stats being an
  48. # approximation.
  49. #
  50. set sqlite_fts3_enable_parentheses 1
  51. proc do_fts3query_test {tn args} {
  52. set nArg [llength $args]
  53. if {$nArg < 2 || ($nArg % 2)} {
  54. set cmd do_fts3query_test
  55. error "wrong # args: should be \"$cmd ?-deferred LIST? TABLE MATCHEXPR\""
  56. }
  57. set tbl [lindex $args [expr $nArg-2]]
  58. set match [lindex $args [expr $nArg-1]]
  59. set deferred [list]
  60. foreach {k v} [lrange $args 0 [expr $nArg-3]] {
  61. switch -- $k {
  62. -deferred {
  63. ifcapable fts4_deferred { set deferred $v }
  64. }
  65. default {
  66. error "bad option \"$k\": must be -deferred"
  67. }
  68. }
  69. }
  70. get_near_results $tbl $match $deferred aHit
  71. get_near_results $tbl [string map {AND OR} $match] $deferred aMatchinfo
  72. set matchinfo_asc [list]
  73. foreach docid [lsort -integer -incr [array names aHit]] {
  74. lappend matchinfo_asc $docid $aMatchinfo($docid)
  75. }
  76. set matchinfo_desc [list]
  77. foreach docid [lsort -integer -decr [array names aHit]] {
  78. lappend matchinfo_desc $docid $aMatchinfo($docid)
  79. }
  80. set title "(\"$match\" -> [llength [array names aHit]] rows)"
  81. do_execsql_test $tn$title.1 "
  82. SELECT docid FROM $tbl WHERE $tbl MATCH '$match' ORDER BY docid ASC
  83. " [lsort -integer -incr [array names aHit]]
  84. do_execsql_test $tn$title.2 "
  85. SELECT docid FROM $tbl WHERE $tbl MATCH '$match' ORDER BY docid DESC
  86. " [lsort -integer -decr [array names aHit]]
  87. do_execsql_test $tn$title.3 "
  88. SELECT docid, mit(matchinfo($tbl, 'x')) FROM $tbl
  89. WHERE $tbl MATCH '$match' ORDER BY docid DESC
  90. " $matchinfo_desc
  91. do_execsql_test $tn$title.4 "
  92. SELECT docid, mit(matchinfo($tbl, 'x')) FROM $tbl
  93. WHERE $tbl MATCH '$match' ORDER BY docid ASC
  94. " $matchinfo_asc
  95. }
  96. # fts3_make_deferrable TABLE TOKEN ?NROW?
  97. #
  98. proc fts3_make_deferrable {tbl token {nRow 0}} {
  99. set stmt [sqlite3_prepare db "SELECT * FROM $tbl" -1 dummy]
  100. set name [sqlite3_column_name $stmt 0]
  101. sqlite3_finalize $stmt
  102. if {$nRow==0} {
  103. set nRow [db one "SELECT count(*) FROM $tbl"]
  104. }
  105. set pgsz [db one "PRAGMA page_size"]
  106. execsql BEGIN
  107. for {set i 0} {$i < ($nRow * $pgsz * 1.2)/100} {incr i} {
  108. set doc [string repeat "$token " 100]
  109. execsql "INSERT INTO $tbl ($name) VALUES(\$doc)"
  110. }
  111. execsql "INSERT INTO $tbl ($name) VALUES('aaaaaaa ${token}aaaaa')"
  112. execsql COMMIT
  113. return [expr $nRow*$pgsz]
  114. }
  115. # fts3_zero_long_segments TABLE ?LIMIT?
  116. #
  117. proc fts3_zero_long_segments {tbl limit} {
  118. execsql "
  119. UPDATE ${tbl}_segments
  120. SET block = zeroblob(length(block))
  121. WHERE length(block)>$limit
  122. "
  123. return [db changes]
  124. }
  125. proc mit {blob} {
  126. set scan(littleEndian) i*
  127. set scan(bigEndian) I*
  128. binary scan $blob $scan($::tcl_platform(byteOrder)) r
  129. return $r
  130. }
  131. db func mit mit
  132. proc fix_phrase_expr {cols expr colfiltervar} {
  133. upvar $colfiltervar iColFilter
  134. set out [list]
  135. foreach t $expr {
  136. if {[string match *:* $t]} {
  137. set col [lindex [split $t :] 0]
  138. set t [lindex [split $t :] 1]
  139. set iCol [lsearch $cols $col]
  140. if {$iCol<0} { error "unknown column: $col" }
  141. if {$iColFilter < 0} {
  142. set iColFilter $iCol
  143. } elseif {$iColFilter != $iCol} {
  144. set iColFilter [llength $cols]
  145. }
  146. }
  147. lappend out $t
  148. }
  149. return $out
  150. }
  151. proc fix_near_expr {cols expr colfiltervar} {
  152. upvar $colfiltervar iColFilter
  153. set iColFilter -1
  154. set out [list]
  155. lappend out [fix_phrase_expr $cols [lindex $expr 0] iColFilter]
  156. foreach {a b} [lrange $expr 1 end] {
  157. if {[string match -nocase near $a]} { set a 10 }
  158. if {[string match -nocase near/* $a]} { set a [string range $a 5 end] }
  159. lappend out $a
  160. lappend out [fix_phrase_expr $cols $b iColFilter]
  161. }
  162. return $out
  163. }
  164. proc get_single_near_results {tbl expr deferred arrayvar nullvar} {
  165. upvar $arrayvar aMatchinfo
  166. upvar $nullvar nullentry
  167. catch {array unset aMatchinfo}
  168. set cols [list]
  169. set miss [list]
  170. db eval "PRAGMA table_info($tbl)" A { lappend cols $A(name) ; lappend miss 0 }
  171. set expr [fix_near_expr $cols $expr iColFilter]
  172. # Calculate the expected results using [fts3_near_match]. The following
  173. # loop populates the "hits" and "counts" arrays as follows:
  174. #
  175. # 1. For each document in the table that matches the NEAR expression,
  176. # hits($docid) is set to 1. The set of docids that match the expression
  177. # can therefore be found using [array names hits].
  178. #
  179. # 2. For each column of each document in the table, counts($docid,$iCol)
  180. # is set to the -phrasecountvar output.
  181. #
  182. set res [list]
  183. catch { array unset hits }
  184. db eval "SELECT docid, * FROM $tbl" d {
  185. set iCol 0
  186. foreach col [lrange $d(*) 1 end] {
  187. set docid $d(docid)
  188. if {$iColFilter<0 || $iCol==$iColFilter} {
  189. set hit [fts3_near_match $d($col) $expr -p counts($docid,$iCol)]
  190. if {$hit} { set hits($docid) 1 }
  191. } else {
  192. set counts($docid,$iCol) $miss
  193. }
  194. incr iCol
  195. }
  196. }
  197. set nPhrase [expr ([llength $expr]+1)/2]
  198. set nCol $iCol
  199. # This block populates the nHit and nDoc arrays. For each phrase/column
  200. # in the query/table, array elements are set as follows:
  201. #
  202. # nHit($iPhrase,$iCol) - Total number of hits for phrase $iPhrase in
  203. # column $iCol.
  204. #
  205. # nDoc($iPhrase,$iCol) - Number of documents with at least one hit for
  206. # phrase $iPhrase in column $iCol.
  207. #
  208. for {set iPhrase 0} {$iPhrase < $nPhrase} {incr iPhrase} {
  209. for {set iCol 0} {$iCol < $nCol} {incr iCol} {
  210. set nHit($iPhrase,$iCol) 0
  211. set nDoc($iPhrase,$iCol) 0
  212. }
  213. }
  214. foreach key [array names counts] {
  215. set iCol [lindex [split $key ,] 1]
  216. set iPhrase 0
  217. foreach c $counts($key) {
  218. if {$c>0} { incr nDoc($iPhrase,$iCol) 1 }
  219. incr nHit($iPhrase,$iCol) $c
  220. incr iPhrase
  221. }
  222. }
  223. if {[llength $deferred] && [llength $expr]==1} {
  224. set phrase [lindex $expr 0]
  225. set rewritten [list]
  226. set partial 0
  227. foreach tok $phrase {
  228. if {[lsearch $deferred $tok]>=0} {
  229. lappend rewritten *
  230. } else {
  231. lappend rewritten $tok
  232. set partial 1
  233. }
  234. }
  235. if {$partial==0} {
  236. set tblsize [db one "SELECT count(*) FROM $tbl"]
  237. for {set iCol 0} {$iCol < $nCol} {incr iCol} {
  238. set nHit(0,$iCol) $tblsize
  239. set nDoc(0,$iCol) $tblsize
  240. }
  241. } elseif {$rewritten != $phrase} {
  242. while {[lindex $rewritten end] == "*"} {
  243. set rewritten [lrange $rewritten 0 end-1]
  244. }
  245. while {[lindex $rewritten 0] == "*"} {
  246. set rewritten [lrange $rewritten 1 end]
  247. }
  248. get_single_near_results $tbl [list $rewritten] {} aRewrite nullentry
  249. foreach docid [array names hits] {
  250. set aMatchinfo($docid) $aRewrite($docid)
  251. }
  252. return
  253. }
  254. }
  255. # Set up the aMatchinfo array. For each document, set aMatchinfo($docid) to
  256. # contain the output of matchinfo('x') for the document.
  257. #
  258. foreach docid [array names hits] {
  259. set mi [list]
  260. for {set iPhrase 0} {$iPhrase<$nPhrase} {incr iPhrase} {
  261. for {set iCol 0} {$iCol<$nCol} {incr iCol} {
  262. lappend mi [lindex $counts($docid,$iCol) $iPhrase]
  263. lappend mi $nHit($iPhrase,$iCol)
  264. lappend mi $nDoc($iPhrase,$iCol)
  265. }
  266. }
  267. set aMatchinfo($docid) $mi
  268. }
  269. # Set up the nullentry output.
  270. #
  271. set nullentry [list]
  272. for {set iPhrase 0} {$iPhrase<$nPhrase} {incr iPhrase} {
  273. for {set iCol 0} {$iCol<$nCol} {incr iCol} {
  274. lappend nullentry 0 $nHit($iPhrase,$iCol) $nDoc($iPhrase,$iCol)
  275. }
  276. }
  277. }
  278. proc matching_brackets {expr} {
  279. if {[string range $expr 0 0]!="(" || [string range $expr end end] !=")"} {
  280. return 0
  281. }
  282. set iBracket 1
  283. set nExpr [string length $expr]
  284. for {set i 1} {$iBracket && $i < $nExpr} {incr i} {
  285. set c [string range $expr $i $i]
  286. if {$c == "("} {incr iBracket}
  287. if {$c == ")"} {incr iBracket -1}
  288. }
  289. return [expr ($iBracket==0 && $i==$nExpr)]
  290. }
  291. proc get_near_results {tbl expr deferred arrayvar {nullvar ""}} {
  292. upvar $arrayvar aMatchinfo
  293. if {$nullvar != ""} { upvar $nullvar nullentry }
  294. set expr [string trim $expr]
  295. while { [matching_brackets $expr] } {
  296. set expr [string trim [string range $expr 1 end-1]]
  297. }
  298. set prec(NOT) 1
  299. set prec(AND) 2
  300. set prec(OR) 3
  301. set currentprec 0
  302. set iBracket 0
  303. set expr_length [llength $expr]
  304. for {set i 0} {$i < $expr_length} {incr i} {
  305. set op [lindex $expr $i]
  306. if {$iBracket==0 && [info exists prec($op)] && $prec($op)>=$currentprec } {
  307. set opidx $i
  308. set currentprec $prec($op)
  309. } else {
  310. for {set j 0} {$j < [string length $op]} {incr j} {
  311. set c [string range $op $j $j]
  312. if {$c == "("} { incr iBracket +1 }
  313. if {$c == ")"} { incr iBracket -1 }
  314. }
  315. }
  316. }
  317. if {$iBracket!=0} { error "mismatched brackets in: $expr" }
  318. if {[info exists opidx]==0} {
  319. get_single_near_results $tbl $expr $deferred aMatchinfo nullentry
  320. } else {
  321. set eLeft [lrange $expr 0 [expr $opidx-1]]
  322. set eRight [lrange $expr [expr $opidx+1] end]
  323. get_near_results $tbl $eLeft $deferred aLeft nullleft
  324. get_near_results $tbl $eRight $deferred aRight nullright
  325. switch -- [lindex $expr $opidx] {
  326. "NOT" {
  327. foreach hit [array names aLeft] {
  328. if {0==[info exists aRight($hit)]} {
  329. set aMatchinfo($hit) $aLeft($hit)
  330. }
  331. }
  332. set nullentry $nullleft
  333. }
  334. "AND" {
  335. foreach hit [array names aLeft] {
  336. if {[info exists aRight($hit)]} {
  337. set aMatchinfo($hit) [concat $aLeft($hit) $aRight($hit)]
  338. }
  339. }
  340. set nullentry [concat $nullleft $nullright]
  341. }
  342. "OR" {
  343. foreach hit [array names aLeft] {
  344. if {[info exists aRight($hit)]} {
  345. set aMatchinfo($hit) [concat $aLeft($hit) $aRight($hit)]
  346. unset aRight($hit)
  347. } else {
  348. set aMatchinfo($hit) [concat $aLeft($hit) $nullright]
  349. }
  350. }
  351. foreach hit [array names aRight] {
  352. set aMatchinfo($hit) [concat $nullleft $aRight($hit)]
  353. }
  354. set nullentry [concat $nullleft $nullright]
  355. }
  356. }
  357. }
  358. }
  359. # End of test procs. Actual tests are below this line.
  360. #--------------------------------------------------------------------------
  361. #--------------------------------------------------------------------------
  362. # The following test cases - fts3auto-1.* - focus on testing the Tcl
  363. # command [fts3_near_match], which is used by other tests in this file.
  364. #
  365. proc test_fts3_near_match {tn doc expr res} {
  366. fts3_near_match $doc $expr -phrasecountvar p
  367. uplevel do_test [list $tn] [list [list set {} $p]] [list $res]
  368. }
  369. test_fts3_near_match 1.1.1 {a b c a b} a {2}
  370. test_fts3_near_match 1.1.2 {a b c a b} {a 5 b 6 c} {2 2 1}
  371. test_fts3_near_match 1.1.3 {a b c a b} {"a b"} {2}
  372. test_fts3_near_match 1.1.4 {a b c a b} {"b c"} {1}
  373. test_fts3_near_match 1.1.5 {a b c a b} {"c c"} {0}
  374. test_fts3_near_match 1.2.1 "a b c d e f g" {b 2 f} {0 0}
  375. test_fts3_near_match 1.2.2 "a b c d e f g" {b 3 f} {1 1}
  376. test_fts3_near_match 1.2.3 "a b c d e f g" {f 2 b} {0 0}
  377. test_fts3_near_match 1.2.4 "a b c d e f g" {f 3 b} {1 1}
  378. test_fts3_near_match 1.2.5 "a b c d e f g" {"a b" 2 "f g"} {0 0}
  379. test_fts3_near_match 1.2.6 "a b c d e f g" {"a b" 3 "f g"} {1 1}
  380. set A "a b c d e f g h i j k l m n o p q r s t u v w x y z"
  381. test_fts3_near_match 1.3.1 $A {"c d" 5 "i j" 1 "e f"} {0 0 0}
  382. test_fts3_near_match 1.3.2 $A {"c d" 5 "i j" 2 "e f"} {1 1 1}
  383. #--------------------------------------------------------------------------
  384. # Test cases fts3auto-2.* run some simple tests using the
  385. # [do_fts3query_test] proc.
  386. #
  387. foreach {tn create} {
  388. 1 "fts4(a, b)"
  389. 2 "fts4(a, b, order=DESC)"
  390. 3 "fts4(a, b, order=ASC)"
  391. 4 "fts4(a, b, prefix=1)"
  392. 5 "fts4(a, b, order=DESC, prefix=1)"
  393. 6 "fts4(a, b, order=ASC, prefix=1)"
  394. } {
  395. do_test 2.$tn.1 {
  396. catchsql { DROP TABLE t1 }
  397. execsql "CREATE VIRTUAL TABLE t1 USING $create"
  398. for {set i 0} {$i<32} {incr i} {
  399. set doc [list]
  400. if {$i&0x01} {lappend doc one}
  401. if {$i&0x02} {lappend doc two}
  402. if {$i&0x04} {lappend doc three}
  403. if {$i&0x08} {lappend doc four}
  404. if {$i&0x10} {lappend doc five}
  405. execsql { INSERT INTO t1 VALUES($doc, null) }
  406. }
  407. } {}
  408. foreach {tn2 expr} {
  409. 1 {one}
  410. 2 {one NEAR/1 five}
  411. 3 {t*}
  412. 4 {t* NEAR/0 five}
  413. 5 {o* NEAR/1 f*}
  414. 6 {one NEAR five NEAR two NEAR four NEAR three}
  415. 7 {one NEAR xyz}
  416. 8 {one OR two}
  417. 9 {one AND two}
  418. 10 {one NOT two}
  419. 11 {one AND two OR three}
  420. 12 {three OR one AND two}
  421. 13 {(three OR one) AND two}
  422. 14 {(three OR one) AND two NOT (five NOT four)}
  423. 15 {"one two"}
  424. 16 {"one two" NOT "three four"}
  425. } {
  426. do_fts3query_test 2.$tn.2.$tn2 t1 $expr
  427. }
  428. }
  429. #--------------------------------------------------------------------------
  430. # Some test cases involving deferred tokens.
  431. #
  432. foreach {tn create} {
  433. 1 "fts4(x)"
  434. 2 "fts4(x, order=DESC)"
  435. } {
  436. catchsql { DROP TABLE t1 }
  437. execsql "CREATE VIRTUAL TABLE t1 USING $create"
  438. do_execsql_test 3.$tn.1 {
  439. INSERT INTO t1(docid, x) VALUES(-2, 'a b c d e f g h i j k');
  440. INSERT INTO t1(docid, x) VALUES(-1, 'b c d e f g h i j k a');
  441. INSERT INTO t1(docid, x) VALUES(0, 'c d e f g h i j k a b');
  442. INSERT INTO t1(docid, x) VALUES(1, 'd e f g h i j k a b c');
  443. INSERT INTO t1(docid, x) VALUES(2, 'e f g h i j k a b c d');
  444. INSERT INTO t1(docid, x) VALUES(3, 'f g h i j k a b c d e');
  445. INSERT INTO t1(docid, x) VALUES(4, 'a c e g i k');
  446. INSERT INTO t1(docid, x) VALUES(5, 'a d g j');
  447. INSERT INTO t1(docid, x) VALUES(6, 'c a b');
  448. }
  449. set limit [fts3_make_deferrable t1 c]
  450. do_fts3query_test 3.$tn.2.1 t1 {a OR c}
  451. ifcapable fts4_deferred {
  452. do_test 3.$tn.3 { fts3_zero_long_segments t1 $limit } {1}
  453. }
  454. foreach {tn2 expr def} {
  455. 1 {a NEAR c} {}
  456. 2 {a AND c} c
  457. 3 {"a c"} c
  458. 4 {"c a"} c
  459. 5 {"a c" NEAR/1 g} {}
  460. 6 {"a c" NEAR/0 g} {}
  461. } {
  462. do_fts3query_test 3.$tn.4.$tn2 -deferred $def t1 $expr
  463. }
  464. }
  465. #--------------------------------------------------------------------------
  466. #
  467. foreach {tn create} {
  468. 1 "fts4(x, y)"
  469. 2 "fts4(x, y, order=DESC)"
  470. 3 "fts4(x, y, order=DESC, prefix=2)"
  471. } {
  472. execsql [subst {
  473. DROP TABLE t1;
  474. CREATE VIRTUAL TABLE t1 USING $create;
  475. INSERT INTO t1 VALUES('one two five four five', '');
  476. INSERT INTO t1 VALUES('', 'one two five four five');
  477. INSERT INTO t1 VALUES('one two', 'five four five');
  478. }]
  479. do_fts3query_test 4.$tn.1.1 t1 {one AND five}
  480. do_fts3query_test 4.$tn.1.2 t1 {one NEAR five}
  481. do_fts3query_test 4.$tn.1.3 t1 {one NEAR/1 five}
  482. do_fts3query_test 4.$tn.1.4 t1 {one NEAR/2 five}
  483. do_fts3query_test 4.$tn.1.5 t1 {one NEAR/3 five}
  484. do_test 4.$tn.2 {
  485. set limit [fts3_make_deferrable t1 five]
  486. execsql { INSERT INTO t1(t1) VALUES('optimize') }
  487. ifcapable fts4_deferred {
  488. expr {[fts3_zero_long_segments t1 $limit]>0}
  489. } else {
  490. expr 1
  491. }
  492. } {1}
  493. do_fts3query_test 4.$tn.3.1 -deferred five t1 {one AND five}
  494. do_fts3query_test 4.$tn.3.2 -deferred five t1 {one NEAR five}
  495. do_fts3query_test 4.$tn.3.3 -deferred five t1 {one NEAR/1 five}
  496. do_fts3query_test 4.$tn.3.4 -deferred five t1 {one NEAR/2 five}
  497. do_fts3query_test 4.$tn.3.5 -deferred five t1 {one NEAR/3 five}
  498. do_fts3query_test 4.$tn.4.1 -deferred fi* t1 {on* AND fi*}
  499. do_fts3query_test 4.$tn.4.2 -deferred fi* t1 {on* NEAR fi*}
  500. do_fts3query_test 4.$tn.4.3 -deferred fi* t1 {on* NEAR/1 fi*}
  501. do_fts3query_test 4.$tn.4.4 -deferred fi* t1 {on* NEAR/2 fi*}
  502. do_fts3query_test 4.$tn.4.5 -deferred fi* t1 {on* NEAR/3 fi*}
  503. }
  504. #--------------------------------------------------------------------------
  505. # The following test cases - fts3auto-5.* - focus on using prefix indexes.
  506. #
  507. set chunkconfig [fts3_configure_incr_load 1 1]
  508. foreach {tn create pending} {
  509. 1 "fts4(a, b)" 1
  510. 2 "fts4(a, b, order=ASC, prefix=1)" 1
  511. 3 "fts4(a, b, order=ASC, prefix=\"1,3\")" 0
  512. 4 "fts4(a, b, order=DESC, prefix=\"2,4\")" 0
  513. 5 "fts4(a, b, order=DESC, prefix=\"1\")" 0
  514. 6 "fts4(a, b, order=ASC, prefix=\"1,3\")" 0
  515. } {
  516. execsql [subst {
  517. DROP TABLE IF EXISTS t1;
  518. CREATE VIRTUAL TABLE t1 USING $create;
  519. }]
  520. if {$pending} {execsql BEGIN}
  521. foreach {a b} {
  522. "the song of songs which is solomons"
  523. "let him kiss me with the kisses of his mouth for thy love is better than wine"
  524. "because of the savour of thy good ointments thy name is as ointment poured forth therefore do the virgins love thee"
  525. "draw me we will run after thee the king hath brought me into his chambers we will be glad and rejoice in thee we will remember thy love more than wine the upright love thee"
  526. "i am black but comely o ye daughters of jerusalem as the tents of kedar as the curtains of solomon"
  527. "look not upon me because i am black because the sun hath looked upon me my mothers children were angry with me they made me the keeper of the vineyards but mine own vineyard have i not kept"
  528. "tell me o thou whom my soul loveth where thou feedest where thou makest thy flock to rest at noon for why should i be as one that turneth aside by the flocks of thy companions?"
  529. "if thou know not o thou fairest among women go thy way forth by the footsteps of the flock and feed thy kids beside the shepherds tents"
  530. "i have compared thee o my love to a company of horses in pharaohs chariots"
  531. "thy cheeks are comely with rows of jewels thy neck with chains of gold"
  532. "we will make thee borders of gold with studs of silver"
  533. "while the king sitteth at his table my spikenard sendeth forth the smell thereof"
  534. "a bundle of myrrh is my wellbeloved unto me he shall lie all night betwixt my breasts"
  535. "my beloved is unto me as a cluster of camphire in the vineyards of en gedi"
  536. "behold thou art fair my love behold thou art fair thou hast doves eyes"
  537. "behold thou art fair my beloved yea pleasant also our bed is green"
  538. "the beams of our house are cedar and our rafters of fir"
  539. } {
  540. execsql {INSERT INTO t1(a, b) VALUES($a, $b)}
  541. }
  542. do_fts3query_test 5.$tn.1.1 t1 {s*}
  543. do_fts3query_test 5.$tn.1.2 t1 {so*}
  544. do_fts3query_test 5.$tn.1.3 t1 {"s* o*"}
  545. do_fts3query_test 5.$tn.1.4 t1 {b* NEAR/3 a*}
  546. do_fts3query_test 5.$tn.1.5 t1 {a*}
  547. do_fts3query_test 5.$tn.1.6 t1 {th* NEAR/5 a* NEAR/5 w*}
  548. do_fts3query_test 5.$tn.1.7 t1 {"b* th* art* fair*"}
  549. if {$pending} {execsql COMMIT}
  550. }
  551. eval fts3_configure_incr_load $chunkconfig
  552. foreach {tn pending create} {
  553. 1 0 "fts4(a, b, c, d)"
  554. 2 1 "fts4(a, b, c, d)"
  555. 3 0 "fts4(a, b, c, d, order=DESC)"
  556. 4 1 "fts4(a, b, c, d, order=DESC)"
  557. } {
  558. execsql [subst {
  559. DROP TABLE IF EXISTS t1;
  560. CREATE VIRTUAL TABLE t1 USING $create;
  561. }]
  562. if {$pending} { execsql BEGIN }
  563. foreach {a b c d} {
  564. "A B C" "D E F" "G H I" "J K L"
  565. "B C D" "E F G" "H I J" "K L A"
  566. "C D E" "F G H" "I J K" "L A B"
  567. "D E F" "G H I" "J K L" "A B C"
  568. "E F G" "H I J" "K L A" "B C D"
  569. "F G H" "I J K" "L A B" "C D E"
  570. } {
  571. execsql { INSERT INTO t1 VALUES($a, $b, $c, $d) }
  572. }
  573. do_fts3query_test 6.$tn.1 t1 {b:G}
  574. do_fts3query_test 6.$tn.2 t1 {b:G AND c:I}
  575. do_fts3query_test 6.$tn.3 t1 {b:G NEAR c:I}
  576. do_fts3query_test 6.$tn.4 t1 {a:C OR b:G OR c:K OR d:C}
  577. do_fts3query_test 6.$tn.5 t1 {a:G OR b:G}
  578. catchsql { COMMIT }
  579. }
  580. foreach {tn create} {
  581. 1 "fts4(x)"
  582. 2 "fts4(x, order=DESC)"
  583. } {
  584. execsql [subst {
  585. DROP TABLE IF EXISTS t1;
  586. CREATE VIRTUAL TABLE t1 USING $create;
  587. }]
  588. foreach {x} {
  589. "F E N O T K X V A X I E X A P G Q V H U"
  590. "R V A E T C V Q N I E L O N U G J K L U"
  591. "U Y I G W M V F J L X I D C H F P J Q B"
  592. "S G D Z X R P G S S Y B K A S G A I L L"
  593. "L S I C H T Z S R Q P R N K J X L F M J"
  594. "C C C D P X B Z C M A D A C X S B T X V"
  595. "W Y J M D R G V R K B X S A W R I T N C"
  596. "P K L W T M S P O Y Y V V O E H Q A I R"
  597. "C D Y I C Z F H J C O Y A Q F L S B D K"
  598. "P G S C Y C Y V I M B D S Z D D Y W I E"
  599. "Z K Z U E E S F Y X T U A L W O U J C Q"
  600. "P A T Z S W L P L Q V Y Y I P W U X S S"
  601. "I U I H U O F Z F R H R F T N D X A G M"
  602. "N A B M S H K X S O Y D T X S B R Y H Z"
  603. "L U D A S K I L S V Z J P U B E B Y H M"
  604. } {
  605. execsql { INSERT INTO t1 VALUES($x) }
  606. }
  607. # Add extra documents to the database such that token "B" will be considered
  608. # deferrable if considering the other tokens means that 2 or fewer documents
  609. # will be loaded into memory.
  610. #
  611. fts3_make_deferrable t1 B 2
  612. # B is not deferred in either of the first two tests below, since filtering
  613. # on "M" or "D" returns 10 documents or so. But filtering on "M * D" only
  614. # returns 2, so B is deferred in this case.
  615. #
  616. do_fts3query_test 7.$tn.1 t1 {"M B"}
  617. do_fts3query_test 7.$tn.2 t1 {"B D"}
  618. do_fts3query_test 7.$tn.3 -deferred B t1 {"M B D"}
  619. }
  620. set sqlite_fts3_enable_parentheses $sfep
  621. finish_test