fts3snippet.test 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. # 2010 January 07
  2. #
  3. # The author disclaims copyright to this source code. In place of
  4. # a legal notice, here is a blessing:
  5. #
  6. # May you do good and not evil.
  7. # May you find forgiveness for yourself and forgive others.
  8. # May you share freely, never taking more than you give.
  9. #
  10. #*************************************************************************
  11. #
  12. # The tests in this file test the FTS3 auxillary functions offsets(),
  13. # snippet() and matchinfo() work. At time of writing, running this file
  14. # provides full coverage of fts3_snippet.c.
  15. #
  16. set testdir [file dirname $argv0]
  17. source $testdir/tester.tcl
  18. set testprefix fts3snippet
  19. # If SQLITE_ENABLE_FTS3 is not defined, omit this file.
  20. ifcapable !fts3 { finish_test ; return }
  21. source $testdir/fts3_common.tcl
  22. set sqlite_fts3_enable_parentheses 1
  23. set DO_MALLOC_TEST 0
  24. # Transform the list $L to its "normal" form. So that it can be compared to
  25. # another list with the same set of elements using [string compare].
  26. #
  27. proc normalize {L} {
  28. set ret [list]
  29. foreach l $L {lappend ret $l}
  30. return $ret
  31. }
  32. proc do_offsets_test {name expr args} {
  33. set result [list]
  34. foreach a $args {
  35. lappend result [normalize $a]
  36. }
  37. do_select_test $name {
  38. SELECT offsets(ft) FROM ft WHERE ft MATCH $expr
  39. } $result
  40. }
  41. # Document text used by a few tests. Contains the English names of all
  42. # integers between 1 and 300.
  43. #
  44. set numbers [normalize {
  45. one two three four five six seven eight nine ten eleven twelve thirteen
  46. fourteen fifteen sixteen seventeen eighteen nineteen twenty twentyone
  47. twentytwo twentythree twentyfour twentyfive twentysix twentyseven
  48. twentyeight twentynine thirty thirtyone thirtytwo thirtythree thirtyfour
  49. thirtyfive thirtysix thirtyseven thirtyeight thirtynine forty fortyone
  50. fortytwo fortythree fortyfour fortyfive fortysix fortyseven fortyeight
  51. fortynine fifty fiftyone fiftytwo fiftythree fiftyfour fiftyfive fiftysix
  52. fiftyseven fiftyeight fiftynine sixty sixtyone sixtytwo sixtythree sixtyfour
  53. sixtyfive sixtysix sixtyseven sixtyeight sixtynine seventy seventyone
  54. seventytwo seventythree seventyfour seventyfive seventysix seventyseven
  55. seventyeight seventynine eighty eightyone eightytwo eightythree eightyfour
  56. eightyfive eightysix eightyseven eightyeight eightynine ninety ninetyone
  57. ninetytwo ninetythree ninetyfour ninetyfive ninetysix ninetyseven
  58. ninetyeight ninetynine onehundred onehundredone onehundredtwo
  59. onehundredthree onehundredfour onehundredfive onehundredsix onehundredseven
  60. onehundredeight onehundrednine onehundredten onehundredeleven
  61. onehundredtwelve onehundredthirteen onehundredfourteen onehundredfifteen
  62. onehundredsixteen onehundredseventeen onehundredeighteen onehundrednineteen
  63. onehundredtwenty onehundredtwentyone onehundredtwentytwo
  64. onehundredtwentythree onehundredtwentyfour onehundredtwentyfive
  65. onehundredtwentysix onehundredtwentyseven onehundredtwentyeight
  66. onehundredtwentynine onehundredthirty onehundredthirtyone
  67. onehundredthirtytwo onehundredthirtythree onehundredthirtyfour
  68. onehundredthirtyfive onehundredthirtysix onehundredthirtyseven
  69. onehundredthirtyeight onehundredthirtynine onehundredforty
  70. onehundredfortyone onehundredfortytwo onehundredfortythree
  71. onehundredfortyfour onehundredfortyfive onehundredfortysix
  72. onehundredfortyseven onehundredfortyeight onehundredfortynine
  73. onehundredfifty onehundredfiftyone onehundredfiftytwo onehundredfiftythree
  74. onehundredfiftyfour onehundredfiftyfive onehundredfiftysix
  75. onehundredfiftyseven onehundredfiftyeight onehundredfiftynine
  76. onehundredsixty onehundredsixtyone onehundredsixtytwo onehundredsixtythree
  77. onehundredsixtyfour onehundredsixtyfive onehundredsixtysix
  78. onehundredsixtyseven onehundredsixtyeight onehundredsixtynine
  79. onehundredseventy onehundredseventyone onehundredseventytwo
  80. onehundredseventythree onehundredseventyfour onehundredseventyfive
  81. onehundredseventysix onehundredseventyseven onehundredseventyeight
  82. onehundredseventynine onehundredeighty onehundredeightyone
  83. onehundredeightytwo onehundredeightythree onehundredeightyfour
  84. onehundredeightyfive onehundredeightysix onehundredeightyseven
  85. onehundredeightyeight onehundredeightynine onehundredninety
  86. onehundredninetyone onehundredninetytwo onehundredninetythree
  87. onehundredninetyfour onehundredninetyfive onehundredninetysix
  88. onehundredninetyseven onehundredninetyeight onehundredninetynine twohundred
  89. twohundredone twohundredtwo twohundredthree twohundredfour twohundredfive
  90. twohundredsix twohundredseven twohundredeight twohundrednine twohundredten
  91. twohundredeleven twohundredtwelve twohundredthirteen twohundredfourteen
  92. twohundredfifteen twohundredsixteen twohundredseventeen twohundredeighteen
  93. twohundrednineteen twohundredtwenty twohundredtwentyone twohundredtwentytwo
  94. twohundredtwentythree twohundredtwentyfour twohundredtwentyfive
  95. twohundredtwentysix twohundredtwentyseven twohundredtwentyeight
  96. twohundredtwentynine twohundredthirty twohundredthirtyone
  97. twohundredthirtytwo twohundredthirtythree twohundredthirtyfour
  98. twohundredthirtyfive twohundredthirtysix twohundredthirtyseven
  99. twohundredthirtyeight twohundredthirtynine twohundredforty
  100. twohundredfortyone twohundredfortytwo twohundredfortythree
  101. twohundredfortyfour twohundredfortyfive twohundredfortysix
  102. twohundredfortyseven twohundredfortyeight twohundredfortynine
  103. twohundredfifty twohundredfiftyone twohundredfiftytwo twohundredfiftythree
  104. twohundredfiftyfour twohundredfiftyfive twohundredfiftysix
  105. twohundredfiftyseven twohundredfiftyeight twohundredfiftynine
  106. twohundredsixty twohundredsixtyone twohundredsixtytwo twohundredsixtythree
  107. twohundredsixtyfour twohundredsixtyfive twohundredsixtysix
  108. twohundredsixtyseven twohundredsixtyeight twohundredsixtynine
  109. twohundredseventy twohundredseventyone twohundredseventytwo
  110. twohundredseventythree twohundredseventyfour twohundredseventyfive
  111. twohundredseventysix twohundredseventyseven twohundredseventyeight
  112. twohundredseventynine twohundredeighty twohundredeightyone
  113. twohundredeightytwo twohundredeightythree twohundredeightyfour
  114. twohundredeightyfive twohundredeightysix twohundredeightyseven
  115. twohundredeightyeight twohundredeightynine twohundredninety
  116. twohundredninetyone twohundredninetytwo twohundredninetythree
  117. twohundredninetyfour twohundredninetyfive twohundredninetysix
  118. twohundredninetyseven twohundredninetyeight twohundredninetynine
  119. threehundred
  120. }]
  121. foreach {DO_MALLOC_TEST enc} {
  122. 0 utf8
  123. 1 utf8
  124. 1 utf16
  125. } {
  126. db close
  127. forcedelete test.db
  128. sqlite3 db test.db
  129. sqlite3_db_config_lookaside db 0 0 0
  130. db eval "PRAGMA encoding = \"$enc\""
  131. # Set variable $T to the test name prefix for this iteration of the loop.
  132. #
  133. set T "fts3snippet-1.$enc"
  134. ##########################################################################
  135. # Test the offset function.
  136. #
  137. do_test $T.1.1 {
  138. execsql {
  139. CREATE VIRTUAL TABLE ft USING fts3;
  140. INSERT INTO ft VALUES('xxx xxx xxx xxx');
  141. }
  142. } {}
  143. do_offsets_test $T.1.2 {xxx} {0 0 0 3 0 0 4 3 0 0 8 3 0 0 12 3}
  144. do_offsets_test $T.1.3 {"xxx xxx"} {
  145. 0 0 0 3 0 0 4 3 0 1 4 3 0 0 8 3
  146. 0 1 8 3 0 1 12 3
  147. }
  148. do_offsets_test $T.1.4 {"xxx xxx" xxx} {
  149. 0 0 0 3 0 2 0 3 0 0 4 3 0 1 4 3
  150. 0 2 4 3 0 0 8 3 0 1 8 3 0 2 8 3
  151. 0 1 12 3 0 2 12 3
  152. }
  153. do_offsets_test $T.1.5 {xxx "xxx xxx"} {
  154. 0 0 0 3 0 1 0 3 0 0 4 3 0 1 4 3
  155. 0 2 4 3 0 0 8 3 0 1 8 3 0 2 8 3
  156. 0 0 12 3 0 2 12 3
  157. }
  158. do_test $T.2.1 {
  159. set v1 [lrange $numbers 0 99]
  160. execsql {
  161. DROP TABLE IF EXISTS ft;
  162. CREATE VIRTUAL TABLE ft USING fts3(a, b);
  163. INSERT INTO ft VALUES($v1, $numbers);
  164. INSERT INTO ft VALUES($v1, NULL);
  165. }
  166. } {}
  167. set off [string first "twohundred " $numbers]
  168. do_offsets_test $T.2.1 {twohundred} [list 1 0 $off 10]
  169. set off [string first "onehundred " $numbers]
  170. do_offsets_test $T.2.2 {onehundred} \
  171. [list 0 0 $off 10 1 0 $off 10] [list 0 0 $off 10]
  172. # Test a corruption case:
  173. execsql { UPDATE ft_content SET c1b = 'hello world' WHERE c1b = $numbers }
  174. do_error_test $T.2.3 {
  175. SELECT offsets(ft) FROM ft WHERE ft MATCH 'onehundred'
  176. } {database disk image is malformed}
  177. ##########################################################################
  178. # Test the snippet function.
  179. #
  180. proc do_snippet_test {name expr iCol nTok args} {
  181. set res [list]
  182. foreach a $args { lappend res [string trim $a] }
  183. do_select_test $name {
  184. SELECT snippet(ft,'{','}','...',$iCol,$nTok) FROM ft WHERE ft MATCH $expr
  185. } $res
  186. }
  187. do_test $T.3.1 {
  188. execsql {
  189. DROP TABLE IF EXISTS ft;
  190. CREATE VIRTUAL TABLE ft USING fts3;
  191. INSERT INTO ft VALUES('one two three four five six seven eight nine ten');
  192. }
  193. } {}
  194. do_snippet_test $T.3.2 one 0 5 "{one} two three four five..."
  195. do_snippet_test $T.3.3 two 0 5 "one {two} three four five..."
  196. do_snippet_test $T.3.4 three 0 5 "one two {three} four five..."
  197. do_snippet_test $T.3.5 four 0 5 "...two three {four} five six..."
  198. do_snippet_test $T.3.6 five 0 5 "...three four {five} six seven..."
  199. do_snippet_test $T.3.7 six 0 5 "...four five {six} seven eight..."
  200. do_snippet_test $T.3.8 seven 0 5 "...five six {seven} eight nine..."
  201. do_snippet_test $T.3.9 eight 0 5 "...six seven {eight} nine ten"
  202. do_snippet_test $T.3.10 nine 0 5 "...six seven eight {nine} ten"
  203. do_snippet_test $T.3.11 ten 0 5 "...six seven eight nine {ten}"
  204. do_test $T.4.1 {
  205. execsql {
  206. INSERT INTO ft VALUES(
  207. 'one two three four five '
  208. || 'six seven eight nine ten '
  209. || 'eleven twelve thirteen fourteen fifteen '
  210. || 'sixteen seventeen eighteen nineteen twenty '
  211. || 'one two three four five '
  212. || 'six seven eight nine ten '
  213. || 'eleven twelve thirteen fourteen fifteen '
  214. || 'sixteen seventeen eighteen nineteen twenty'
  215. );
  216. }
  217. } {}
  218. do_snippet_test $T.4.2 {one nine} 0 5 {
  219. {one} two three...eight {nine} ten
  220. } {
  221. {one} two three...eight {nine} ten...
  222. }
  223. do_snippet_test $T.4.3 {one nine} 0 -5 {
  224. {one} two three four five...six seven eight {nine} ten
  225. } {
  226. {one} two three four five...seven eight {nine} ten eleven...
  227. }
  228. do_snippet_test $T.4.3 {one nineteen} 0 -5 {
  229. ...eighteen {nineteen} twenty {one} two...
  230. }
  231. do_snippet_test $T.4.4 {two nineteen} 0 -5 {
  232. ...eighteen {nineteen} twenty one {two}...
  233. }
  234. do_snippet_test $T.4.5 {three nineteen} 0 -5 {
  235. ...{nineteen} twenty one two {three}...
  236. }
  237. do_snippet_test $T.4.6 {four nineteen} 0 -5 {
  238. ...two three {four} five six...seventeen eighteen {nineteen} twenty one...
  239. }
  240. do_snippet_test $T.4.7 {four NEAR nineteen} 0 -5 {
  241. ...seventeen eighteen {nineteen} twenty one...two three {four} five six...
  242. }
  243. do_snippet_test $T.4.8 {four nineteen} 0 5 {
  244. ...three {four} five...eighteen {nineteen} twenty...
  245. }
  246. do_snippet_test $T.4.9 {four NEAR nineteen} 0 5 {
  247. ...eighteen {nineteen} twenty...three {four} five...
  248. }
  249. do_snippet_test $T.4.10 {four NEAR nineteen} 0 -5 {
  250. ...seventeen eighteen {nineteen} twenty one...two three {four} five six...
  251. }
  252. do_snippet_test $T.4.11 {four NOT (nineteen twentyone)} 0 5 {
  253. ...two three {four} five six...
  254. } {
  255. ...two three {four} five six...
  256. }
  257. do_snippet_test $T.4.12 {four OR nineteen NEAR twentyone} 0 5 {
  258. ...two three {four} five six...
  259. } {
  260. ...two three {four} five six...
  261. }
  262. do_test $T.5.1 {
  263. execsql {
  264. DROP TABLE IF EXISTS ft;
  265. CREATE VIRTUAL TABLE ft USING fts3(a, b, c);
  266. INSERT INTO ft VALUES(
  267. 'one two three four five',
  268. 'four five six seven eight',
  269. 'seven eight nine ten eleven'
  270. );
  271. }
  272. } {}
  273. do_snippet_test $T.5.2 {five} -1 3 {...three four {five}}
  274. do_snippet_test $T.5.3 {five} 0 3 {...three four {five}}
  275. do_snippet_test $T.5.4 {five} 1 3 {four {five} six...}
  276. do_snippet_test $T.5.5 {five} 2 3 {seven eight nine...}
  277. do_test $T.5.6 {
  278. execsql { UPDATE ft SET b = NULL }
  279. } {}
  280. do_snippet_test $T.5.7 {five} -1 3 {...three four {five}}
  281. do_snippet_test $T.5.8 {five} 0 3 {...three four {five}}
  282. do_snippet_test $T.5.9 {five} 1 3 {}
  283. do_snippet_test $T.5.10 {five} 2 3 {seven eight nine...}
  284. do_snippet_test $T.5.11 {one "seven eight nine"} -1 -3 {
  285. {one} two three...{seven} {eight} {nine}...
  286. }
  287. do_test $T.6.1 {
  288. execsql {
  289. DROP TABLE IF EXISTS ft;
  290. CREATE VIRTUAL TABLE ft USING fts3(x);
  291. INSERT INTO ft VALUES($numbers);
  292. }
  293. } {}
  294. do_snippet_test $T.6.2 {
  295. one fifty onehundred onehundredfifty twohundredfifty threehundred
  296. } -1 4 {
  297. {one}...{fifty}...{onehundred}...{onehundredfifty}...
  298. }
  299. do_snippet_test $T.6.3 {
  300. one fifty onehundred onehundredfifty twohundredfifty threehundred
  301. } -1 -4 {
  302. {one} two three four...fortyeight fortynine {fifty} fiftyone...ninetyeight ninetynine {onehundred} onehundredone...onehundredfortyeight onehundredfortynine {onehundredfifty} onehundredfiftyone...
  303. }
  304. do_test $T.7.1 {
  305. execsql {
  306. BEGIN;
  307. DROP TABLE IF EXISTS ft;
  308. CREATE VIRTUAL TABLE ft USING fts3(x);
  309. }
  310. set testresults [list]
  311. for {set i 1} {$i < 150} {incr i} {
  312. set commas [string repeat , $i]
  313. execsql {INSERT INTO ft VALUES('one' || $commas || 'two')}
  314. lappend testresults "{one}$commas{two}"
  315. }
  316. execsql COMMIT
  317. } {}
  318. eval [list do_snippet_test $T.7.2 {one two} -1 3] $testresults
  319. ##########################################################################
  320. # Test the matchinfo function.
  321. #
  322. proc mit {blob} {
  323. set scan(littleEndian) i*
  324. set scan(bigEndian) I*
  325. binary scan $blob $scan($::tcl_platform(byteOrder)) r
  326. return $r
  327. }
  328. db func mit mit
  329. proc do_matchinfo_test {name expr args} {
  330. set res [list]
  331. foreach a $args { lappend res [normalize $a] }
  332. do_select_test $name {
  333. SELECT mit(matchinfo(ft)) FROM ft WHERE ft MATCH $expr
  334. } $res
  335. }
  336. do_test $T.8.1 {
  337. set ten {one two three four five six seven eight nine ten}
  338. execsql {
  339. DROP TABLE IF EXISTS ft;
  340. CREATE VIRTUAL TABLE ft USING fts3;
  341. INSERT INTO ft VALUES($ten);
  342. INSERT INTO ft VALUES($ten || ' ' || $ten);
  343. }
  344. } {}
  345. do_matchinfo_test $T.8.2 "one" {1 1 1 3 2} {1 1 2 3 2}
  346. do_matchinfo_test $T.8.3 "one NEAR/3 ten" {2 1 1 1 1 1 1 1}
  347. do_matchinfo_test $T.8.4 "five NEAR/4 ten" \
  348. {2 1 1 3 2 1 3 2} {2 1 2 3 2 2 3 2}
  349. do_matchinfo_test $T.8.5 "six NEAR/3 ten NEAR/3 two" \
  350. {3 1 1 1 1 1 1 1 1 1 1}
  351. do_matchinfo_test $T.8.6 "five NEAR/4 ten NEAR/3 two" \
  352. {3 1 2 2 1 1 1 1 1 1 1}
  353. do_test $T.9.1 {
  354. execsql {
  355. DROP TABLE IF EXISTS ft;
  356. CREATE VIRTUAL TABLE ft USING fts3(x, y);
  357. }
  358. foreach n {1 2 3} {
  359. set v1 [lrange $numbers 0 [expr $n*100]]
  360. set v2 [string trim [string repeat "$numbers " $n]]
  361. set docid [expr $n * 1000000]
  362. execsql { INSERT INTO ft(docid, x, y) VALUES($docid, $v1, $v2) }
  363. }
  364. } {}
  365. do_matchinfo_test $T.9.2 {two*} \
  366. { 1 2 1 105 3 101 606 3} \
  367. { 1 2 3 105 3 202 606 3} \
  368. { 1 2 101 105 3 303 606 3}
  369. do_matchinfo_test $T.9.4 {"one* two*"} \
  370. { 1 2 1 5 3 2 12 3} \
  371. { 1 2 2 5 3 4 12 3} \
  372. { 1 2 2 5 3 6 12 3}
  373. do_matchinfo_test $T.9.5 {twohundredfifty} \
  374. { 1 2 0 1 1 1 6 3} \
  375. { 1 2 0 1 1 2 6 3} \
  376. { 1 2 1 1 1 3 6 3}
  377. do_matchinfo_test $T.9.6 {"threehundred one"} \
  378. { 1 2 0 0 0 1 3 2} \
  379. { 1 2 0 0 0 2 3 2}
  380. do_matchinfo_test $T.9.7 {one OR fivehundred} \
  381. { 2 2 1 3 3 1 6 3 0 0 0 0 0 0 } \
  382. { 2 2 1 3 3 2 6 3 0 0 0 0 0 0 } \
  383. { 2 2 1 3 3 3 6 3 0 0 0 0 0 0 }
  384. do_matchinfo_test $T.9.8 {two OR "threehundred one"} \
  385. { 2 2 1 3 3 1 6 3 0 0 0 0 3 2 } \
  386. { 2 2 1 3 3 2 6 3 0 0 0 1 3 2 } \
  387. { 2 2 1 3 3 3 6 3 0 0 0 2 3 2 }
  388. do_select_test $T.9.9 {
  389. SELECT mit(matchinfo(ft)), mit(matchinfo(ft))
  390. FROM ft WHERE ft MATCH 'two OR "threehundred one"'
  391. } [normalize {
  392. {2 2 1 3 3 1 6 3 0 0 0 0 3 2}
  393. {2 2 1 3 3 1 6 3 0 0 0 0 3 2}
  394. {2 2 1 3 3 2 6 3 0 0 0 1 3 2}
  395. {2 2 1 3 3 2 6 3 0 0 0 1 3 2}
  396. {2 2 1 3 3 3 6 3 0 0 0 2 3 2}
  397. {2 2 1 3 3 3 6 3 0 0 0 2 3 2}
  398. }]
  399. # EVIDENCE-OF: R-40630-02268 If used within a SELECT that uses the
  400. # "query by rowid" or "linear scan" strategies, then the snippet and
  401. # offsets both return an empty string, and the matchinfo function
  402. # returns a blob value zero bytes in size.
  403. #
  404. set r 1000000 ;# A rowid that exists in table ft
  405. do_select_test $T.10.0 { SELECT rowid FROM ft WHERE rowid = $r } $r
  406. do_select_test $T.10.1 {
  407. SELECT length(offsets(ft)), typeof(offsets(ft)) FROM ft;
  408. } {0 text 0 text 0 text}
  409. do_select_test $T.10.2 {
  410. SELECT length(offsets(ft)), typeof(offsets(ft)) FROM ft WHERE rowid = $r
  411. } {0 text}
  412. do_select_test $T.10.3 {
  413. SELECT length(snippet(ft)), typeof(snippet(ft)) FROM ft;
  414. } {0 text 0 text 0 text}
  415. do_select_test $T.10.4 {
  416. SELECT length(snippet(ft)), typeof(snippet(ft)) FROM ft WHERE rowid = $r;
  417. } {0 text}
  418. do_select_test $T.10.5 {
  419. SELECT length(matchinfo(ft)), typeof(matchinfo(ft)) FROM ft;
  420. } {0 blob 0 blob 0 blob}
  421. do_select_test $T.10.6 {
  422. SELECT length(matchinfo(ft)), typeof(matchinfo(ft)) FROM ft WHERE rowid = $r
  423. } {0 blob}
  424. }
  425. #-------------------------------------------------------------------------
  426. # Test an interaction between the snippet() function and OR clauses.
  427. #
  428. do_execsql_test 2.1 {
  429. CREATE VIRTUAL TABLE t2 USING fts4;
  430. INSERT INTO t2 VALUES('one two three four five');
  431. INSERT INTO t2 VALUES('two three four five one');
  432. INSERT INTO t2 VALUES('three four five one two');
  433. INSERT INTO t2 VALUES('four five one two three');
  434. INSERT INTO t2 VALUES('five one two three four');
  435. }
  436. do_execsql_test 2.2 {
  437. SELECT snippet(t2, '[', ']') FROM t2 WHERE t2 MATCH 'one OR (four AND six)'
  438. } {
  439. {[one] two three [four] five}
  440. {two three [four] five [one]}
  441. {three [four] five [one] two}
  442. {[four] five [one] two three}
  443. {five [one] two three [four]}
  444. }
  445. do_execsql_test 2.3 {
  446. SELECT snippet(t2, '[', ']') FROM t2
  447. WHERE t2 MATCH 'one OR (four AND six)'
  448. ORDER BY docid DESC
  449. } {
  450. {five [one] two three [four]}
  451. {[four] five [one] two three}
  452. {three [four] five [one] two}
  453. {two three [four] five [one]}
  454. {[one] two three [four] five}
  455. }
  456. do_execsql_test 2.4 {
  457. INSERT INTO t2 VALUES('six');
  458. }
  459. do_execsql_test 2.5 {
  460. SELECT snippet(t2, '[', ']') FROM t2 WHERE t2 MATCH 'one OR (four AND six)'
  461. } {
  462. {[one] two three [four] five}
  463. {two three [four] five [one]}
  464. {three [four] five [one] two}
  465. {[four] five [one] two three}
  466. {five [one] two three [four]}
  467. }
  468. do_execsql_test 2.6 {
  469. SELECT snippet(t2, '[', ']') FROM t2
  470. WHERE t2 MATCH 'one OR (four AND six)'
  471. ORDER BY docid DESC
  472. } {
  473. {five [one] two three [four]}
  474. {[four] five [one] two three}
  475. {three [four] five [one] two}
  476. {two three [four] five [one]}
  477. {[one] two three [four] five}
  478. }
  479. set sqlite_fts3_enable_parentheses 0
  480. finish_test