fts3aa.test 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. # 2006 September 9
  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 FTS3 module.
  13. #
  14. # $Id: fts3aa.test,v 1.1 2007/08/20 17:38:42 shess Exp $
  15. #
  16. set testdir [file dirname $argv0]
  17. source $testdir/tester.tcl
  18. # If SQLITE_ENABLE_FTS3 is defined, omit this file.
  19. ifcapable !fts3 {
  20. finish_test
  21. return
  22. }
  23. # Construct a full-text search table containing five keywords:
  24. # one, two, three, four, and five, in various combinations. The
  25. # rowid for each will be a bitmask for the elements it contains.
  26. #
  27. db eval {
  28. CREATE VIRTUAL TABLE t1 USING fts3(content);
  29. INSERT INTO t1(content) VALUES('one');
  30. INSERT INTO t1(content) VALUES('two');
  31. INSERT INTO t1(content) VALUES('one two');
  32. INSERT INTO t1(content) VALUES('three');
  33. INSERT INTO t1(content) VALUES('one three');
  34. INSERT INTO t1(content) VALUES('two three');
  35. INSERT INTO t1(content) VALUES('one two three');
  36. INSERT INTO t1(content) VALUES('four');
  37. INSERT INTO t1(content) VALUES('one four');
  38. INSERT INTO t1(content) VALUES('two four');
  39. INSERT INTO t1(content) VALUES('one two four');
  40. INSERT INTO t1(content) VALUES('three four');
  41. INSERT INTO t1(content) VALUES('one three four');
  42. INSERT INTO t1(content) VALUES('two three four');
  43. INSERT INTO t1(content) VALUES('one two three four');
  44. INSERT INTO t1(content) VALUES('five');
  45. INSERT INTO t1(content) VALUES('one five');
  46. INSERT INTO t1(content) VALUES('two five');
  47. INSERT INTO t1(content) VALUES('one two five');
  48. INSERT INTO t1(content) VALUES('three five');
  49. INSERT INTO t1(content) VALUES('one three five');
  50. INSERT INTO t1(content) VALUES('two three five');
  51. INSERT INTO t1(content) VALUES('one two three five');
  52. INSERT INTO t1(content) VALUES('four five');
  53. INSERT INTO t1(content) VALUES('one four five');
  54. INSERT INTO t1(content) VALUES('two four five');
  55. INSERT INTO t1(content) VALUES('one two four five');
  56. INSERT INTO t1(content) VALUES('three four five');
  57. INSERT INTO t1(content) VALUES('one three four five');
  58. INSERT INTO t1(content) VALUES('two three four five');
  59. INSERT INTO t1(content) VALUES('one two three four five');
  60. }
  61. do_test fts3aa-1.1 {
  62. execsql {SELECT rowid FROM t1 WHERE content MATCH 'one'}
  63. } {1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31}
  64. do_test fts3aa-1.2 {
  65. execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two'}
  66. } {3 7 11 15 19 23 27 31}
  67. do_test fts3aa-1.3 {
  68. execsql {SELECT rowid FROM t1 WHERE content MATCH 'two one'}
  69. } {3 7 11 15 19 23 27 31}
  70. do_test fts3aa-1.4 {
  71. execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two three'}
  72. } {7 15 23 31}
  73. do_test fts3aa-1.5 {
  74. execsql {SELECT rowid FROM t1 WHERE content MATCH 'one three two'}
  75. } {7 15 23 31}
  76. do_test fts3aa-1.6 {
  77. execsql {SELECT rowid FROM t1 WHERE content MATCH 'two three one'}
  78. } {7 15 23 31}
  79. do_test fts3aa-1.7 {
  80. execsql {SELECT rowid FROM t1 WHERE content MATCH 'two one three'}
  81. } {7 15 23 31}
  82. do_test fts3aa-1.8 {
  83. execsql {SELECT rowid FROM t1 WHERE content MATCH 'three one two'}
  84. } {7 15 23 31}
  85. do_test fts3aa-1.9 {
  86. execsql {SELECT rowid FROM t1 WHERE content MATCH 'three two one'}
  87. } {7 15 23 31}
  88. do_test fts3aa-1.10 {
  89. execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two THREE'}
  90. } {7 15 23 31}
  91. do_test fts3aa-1.11 {
  92. execsql {SELECT rowid FROM t1 WHERE content MATCH ' ONE Two three '}
  93. } {7 15 23 31}
  94. do_test fts3aa-2.1 {
  95. execsql {SELECT rowid FROM t1 WHERE content MATCH '"one"'}
  96. } {1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31}
  97. do_test fts3aa-2.2 {
  98. execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two"'}
  99. } {3 7 11 15 19 23 27 31}
  100. do_test fts3aa-2.3 {
  101. execsql {SELECT rowid FROM t1 WHERE content MATCH '"two one"'}
  102. } {}
  103. do_test fts3aa-2.4 {
  104. execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two three"'}
  105. } {7 15 23 31}
  106. do_test fts3aa-2.5 {
  107. execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three two"'}
  108. } {}
  109. do_test fts3aa-2.6 {
  110. execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two three four"'}
  111. } {15 31}
  112. do_test fts3aa-2.7 {
  113. execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three two four"'}
  114. } {}
  115. do_test fts3aa-2.8 {
  116. execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three five"'}
  117. } {21}
  118. do_test fts3aa-2.9 {
  119. execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three" five'}
  120. } {21 29}
  121. do_test fts3aa-2.10 {
  122. execsql {SELECT rowid FROM t1 WHERE content MATCH 'five "one three"'}
  123. } {21 29}
  124. do_test fts3aa-2.11 {
  125. execsql {SELECT rowid FROM t1 WHERE content MATCH 'five "one three" four'}
  126. } {29}
  127. do_test fts3aa-2.12 {
  128. execsql {SELECT rowid FROM t1 WHERE content MATCH 'five four "one three"'}
  129. } {29}
  130. do_test fts3aa-2.13 {
  131. execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three" four five'}
  132. } {29}
  133. do_test fts3aa-3.1 {
  134. execsql {SELECT rowid FROM t1 WHERE content MATCH 'one'}
  135. } {1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31}
  136. do_test fts3aa-3.2 {
  137. execsql {SELECT rowid FROM t1 WHERE content MATCH 'one -two'}
  138. } {1 5 9 13 17 21 25 29}
  139. do_test fts3aa-3.3 {
  140. execsql {SELECT rowid FROM t1 WHERE content MATCH '-two one'}
  141. } {1 5 9 13 17 21 25 29}
  142. breakpoint
  143. do_test fts3aa-4.1 {
  144. execsql {SELECT rowid FROM t1 WHERE content MATCH 'one OR two'}
  145. } {1 2 3 5 6 7 9 10 11 13 14 15 17 18 19 21 22 23 25 26 27 29 30 31}
  146. do_test fts3aa-4.2 {
  147. execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two" OR three'}
  148. } {3 4 5 6 7 11 12 13 14 15 19 20 21 22 23 27 28 29 30 31}
  149. do_test fts3aa-4.3 {
  150. execsql {SELECT rowid FROM t1 WHERE content MATCH 'three OR "one two"'}
  151. } {3 4 5 6 7 11 12 13 14 15 19 20 21 22 23 27 28 29 30 31}
  152. do_test fts3aa-4.4 {
  153. execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two OR three'}
  154. } {3 5 7 11 13 15 19 21 23 27 29 31}
  155. do_test fts3aa-4.5 {
  156. execsql {SELECT rowid FROM t1 WHERE content MATCH 'three OR two one'}
  157. } {3 5 7 11 13 15 19 21 23 27 29 31}
  158. do_test fts3aa-4.6 {
  159. execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two OR three OR four'}
  160. } {3 5 7 9 11 13 15 19 21 23 25 27 29 31}
  161. do_test fts3aa-4.7 {
  162. execsql {SELECT rowid FROM t1 WHERE content MATCH 'two OR three OR four one'}
  163. } {3 5 7 9 11 13 15 19 21 23 25 27 29 31}
  164. # Test the ability to handle NULL content
  165. #
  166. do_test fts3aa-5.1 {
  167. execsql {INSERT INTO t1(content) VALUES(NULL)}
  168. } {}
  169. do_test fts3aa-5.2 {
  170. set rowid [db last_insert_rowid]
  171. execsql {SELECT content FROM t1 WHERE rowid=$rowid}
  172. } {{}}
  173. do_test fts3aa-5.3 {
  174. execsql {SELECT rowid FROM t1 WHERE content MATCH NULL}
  175. } {}
  176. # Test the ability to handle non-positive rowids
  177. #
  178. do_test fts3aa-6.0 {
  179. execsql {INSERT INTO t1(rowid, content) VALUES(0, 'four five')}
  180. } {}
  181. do_test fts3aa-6.1 {
  182. execsql {SELECT content FROM t1 WHERE rowid = 0}
  183. } {{four five}}
  184. do_test fts3aa-6.2 {
  185. execsql {INSERT INTO t1(rowid, content) VALUES(-1, 'three four')}
  186. } {}
  187. do_test fts3aa-6.3 {
  188. execsql {SELECT content FROM t1 WHERE rowid = -1}
  189. } {{three four}}
  190. do_test fts3aa-6.4 {
  191. execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'four'}
  192. } {-1 0 8 9 10 11 12 13 14 15 24 25 26 27 28 29 30 31}
  193. # Test creation of FTS3 and FTS4 tables with columns that contain
  194. # an "=" character.
  195. #
  196. do_execsql_test fts3aa-7.1 {
  197. CREATE VIRTUAL TABLE t2 USING fts3(xyz=abc);
  198. SELECT xyz FROM t2;
  199. } {}
  200. do_catchsql_test fts3aa-7.2 {
  201. CREATE VIRTUAL TABLE t3 USING fts4(xyz=abc);
  202. } {1 {unrecognized parameter: xyz=abc}}
  203. do_catchsql_test fts3aa-7.3 {
  204. CREATE VIRTUAL TABLE t3 USING fts4(xyz = abc);
  205. } {1 {unrecognized parameter: xyz = abc}}
  206. do_execsql_test fts3aa-7.4 {
  207. CREATE VIRTUAL TABLE t3 USING fts3(tokenize=simple, tokenize=simple);
  208. SELECT tokenize FROM t3;
  209. } {}
  210. do_catchsql_test fts3aa-7.5 {
  211. CREATE VIRTUAL TABLE t4 USING fts4(tokenize=simple, tokenize=simple);
  212. } {1 {unrecognized parameter: tokenize=simple}}
  213. finish_test