1
0

fts4aa.test 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. # 2010 February 02
  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. # This file implements regression tests for SQLite library. The
  12. # focus of this script is testing the FTS4 module.
  13. #
  14. #
  15. set testdir [file dirname $argv0]
  16. source $testdir/tester.tcl
  17. # If SQLITE_ENABLE_FTS3 is defined, omit this file.
  18. ifcapable !fts3 {
  19. finish_test
  20. return
  21. }
  22. # Create the fts_kjv_genesis procedure which fills and FTS3/4 table with
  23. # the complete text of the Book of Genesis.
  24. #
  25. source $testdir/genesis.tcl
  26. # The following is a list of queries to perform against the above
  27. # FTS3/FTS4 database. We will be trying these queries in various
  28. # configurations to ensure that they always return the same answers.
  29. #
  30. set fts4aa_queries {
  31. {abraham}
  32. {the king}
  33. {"the king"}
  34. {abraham OR joseph}
  35. {ab* OR jos*}
  36. {lived t*}
  37. {spake hebrew}
  38. {melchizedek}
  39. {t* melchizedek}
  40. {melchizedek t*}
  41. }
  42. unset -nocomplain fts4aa_res
  43. # Set up the baseline results
  44. #
  45. do_test fts4aa-1.0 {
  46. db eval {
  47. CREATE VIRTUAL TABLE t1 USING fts4(words, tokenize porter);
  48. }
  49. fts_kjv_genesis
  50. foreach q $::fts4aa_queries {
  51. set r [db eval {SELECT docid FROM t1 WHERE words MATCH $q ORDER BY docid}]
  52. set ::fts4aa_res($q) $r
  53. }
  54. } {}
  55. # Legacy test cases
  56. #
  57. do_test fts4aa-1.1 {
  58. db eval {
  59. SELECT docid FROM t1 EXCEPT SELECT docid FROM t1_docsize
  60. }
  61. } {}
  62. do_test fts4aa-1.2 {
  63. db eval {
  64. SELECT docid FROM t1_docsize EXCEPT SELECT docid FROM t1
  65. }
  66. } {}
  67. proc mit {blob} {
  68. set scan(littleEndian) i*
  69. set scan(bigEndian) I*
  70. binary scan $blob $scan($::tcl_platform(byteOrder)) r
  71. return $r
  72. }
  73. db func mit mit
  74. do_test fts4aa-1.3 {
  75. db eval {
  76. SELECT docid, mit(matchinfo(t1, 'pcxnal')) FROM t1 WHERE t1 MATCH 'melchizedek';
  77. }
  78. } {1014018 {1 1 1 1 1 1533 25 20}}
  79. do_test fts4aa-1.4 {
  80. db eval {
  81. SELECT docid, mit(matchinfo(t1, 'pcxnal')) FROM t1
  82. WHERE t1 MATCH 'spake hebrew'
  83. ORDER BY docid;
  84. }
  85. } {1039014 {2 1 1 40 40 1 6 6 1533 25 42} 1039017 {2 1 1 40 40 1 6 6 1533 25 26}}
  86. do_test fts4aa-1.5 {
  87. db eval {
  88. SELECT docid, mit(matchinfo(t1, 'pcxnal')) FROM t1
  89. WHERE t1 MATCH 'laban overtook jacob'
  90. ORDER BY docid;
  91. }
  92. } {1031025 {3 1 2 54 46 1 3 3 2 181 160 1533 25 24}}
  93. do_test fts4aa-1.6 {
  94. db eval {
  95. DELETE FROM t1 WHERE docid!=1050026;
  96. SELECT hex(size) FROM t1_docsize;
  97. SELECT hex(value) FROM t1_stat;
  98. }
  99. } {17 01176F}
  100. do_test fts4aa-1.7 {
  101. db eval {
  102. SELECT docid FROM t1 EXCEPT SELECT docid FROM t1_docsize
  103. }
  104. } {}
  105. do_test fts4aa-1.8 {
  106. db eval {
  107. SELECT docid FROM t1_docsize EXCEPT SELECT docid FROM t1
  108. }
  109. } {}
  110. ifcapable fts4_deferred {
  111. do_test fts4aa-1.9 {
  112. # Note: Token 'in' is being deferred in the following query.
  113. db eval {
  114. SELECT docid, mit(matchinfo(t1, 'pcxnal')) FROM t1
  115. WHERE t1 MATCH 'joseph died in egypt'
  116. ORDER BY docid;
  117. }
  118. } {1050026 {4 1 1 1 1 1 1 1 2 1 1 1 1 1 1 23 23}}
  119. }
  120. # Should get the same search results from FTS3
  121. #
  122. do_test fts4aa-2.0 {
  123. db eval {
  124. DROP TABLE t1;
  125. CREATE VIRTUAL TABLE t1 USING fts3(words, tokenize porter);
  126. }
  127. fts_kjv_genesis
  128. } {}
  129. unset -nocomplain ii
  130. set ii 0
  131. foreach {q r} [array get fts4aa_res] {
  132. incr ii
  133. do_test fts4aa-2.$ii {
  134. db eval {SELECT docid FROM t1 WHERE words MATCH $::q ORDER BY docid}
  135. } $r
  136. }
  137. # Should get the same search results when the page size is very large
  138. #
  139. do_test fts4aa-3.0 {
  140. db close
  141. forcedelete test.db
  142. sqlite3 db test.db
  143. db eval {
  144. PRAGMA page_size=65536;
  145. CREATE VIRTUAL TABLE t1 USING fts4(words, tokenize porter);
  146. }
  147. fts_kjv_genesis
  148. } {}
  149. unset -nocomplain ii
  150. set ii 0
  151. foreach {q r} [array get fts4aa_res] {
  152. incr ii
  153. do_test fts4aa-3.$ii {
  154. db eval {SELECT docid FROM t1 WHERE words MATCH $::q ORDER BY docid}
  155. } $r
  156. }
  157. # Should get the same search results when an authorizer prevents
  158. # all PRAGMA statements.
  159. #
  160. proc no_pragma_auth {code arg1 arg2 arg3 arg4} {
  161. if {$code=="SQLITE_PRAGMA"} {return SQLITE_DENY}
  162. return SQLITE_OK;
  163. }
  164. do_test fts4aa-4.0 {
  165. db auth ::no_pragma_auth
  166. db eval {
  167. DROP TABLE t1;
  168. CREATE VIRTUAL TABLE t1 USING fts4(words, tokenize porter);
  169. }
  170. fts_kjv_genesis
  171. } {}
  172. unset -nocomplain ii
  173. set ii 0
  174. foreach {q r} [array get fts4aa_res] {
  175. incr ii
  176. do_test fts4aa-4.$ii {
  177. db eval {SELECT docid FROM t1 WHERE words MATCH $::q ORDER BY docid}
  178. } $r
  179. }
  180. finish_test