PageRenderTime 37ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/src/sqlite/test/fts1a.test

#
Unknown | 186 lines | 175 code | 11 blank | 0 comment | 0 complexity | 72ef73c709b6d67722a9f0b8bd3717ad MD5 | raw file
Possible License(s): BSD-3-Clause
  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 FTS1 module.
  13. #
  14. # $Id: fts1a.test,v 1.4 2006/09/28 19:43:32 drh Exp $
  15. #
  16. set testdir [file dirname $argv0]
  17. source $testdir/tester.tcl
  18. # If SQLITE_ENABLE_FTS1 is defined, omit this file.
  19. ifcapable !fts1 {
  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 fts1(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 fts1a-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 fts1a-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 fts1a-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 fts1a-1.4 {
  71. execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two three'}
  72. } {7 15 23 31}
  73. do_test fts1a-1.5 {
  74. execsql {SELECT rowid FROM t1 WHERE content MATCH 'one three two'}
  75. } {7 15 23 31}
  76. do_test fts1a-1.6 {
  77. execsql {SELECT rowid FROM t1 WHERE content MATCH 'two three one'}
  78. } {7 15 23 31}
  79. do_test fts1a-1.7 {
  80. execsql {SELECT rowid FROM t1 WHERE content MATCH 'two one three'}
  81. } {7 15 23 31}
  82. do_test fts1a-1.8 {
  83. execsql {SELECT rowid FROM t1 WHERE content MATCH 'three one two'}
  84. } {7 15 23 31}
  85. do_test fts1a-1.9 {
  86. execsql {SELECT rowid FROM t1 WHERE content MATCH 'three two one'}
  87. } {7 15 23 31}
  88. do_test fts1a-1.10 {
  89. execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two THREE'}
  90. } {7 15 23 31}
  91. do_test fts1a-1.11 {
  92. execsql {SELECT rowid FROM t1 WHERE content MATCH ' ONE Two three '}
  93. } {7 15 23 31}
  94. do_test fts1a-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 fts1a-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 fts1a-2.3 {
  101. execsql {SELECT rowid FROM t1 WHERE content MATCH '"two one"'}
  102. } {}
  103. do_test fts1a-2.4 {
  104. execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two three"'}
  105. } {7 15 23 31}
  106. do_test fts1a-2.5 {
  107. execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three two"'}
  108. } {}
  109. do_test fts1a-2.6 {
  110. execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two three four"'}
  111. } {15 31}
  112. do_test fts1a-2.7 {
  113. execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three two four"'}
  114. } {}
  115. do_test fts1a-2.8 {
  116. execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three five"'}
  117. } {21}
  118. do_test fts1a-2.9 {
  119. execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three" five'}
  120. } {21 29}
  121. do_test fts1a-2.10 {
  122. execsql {SELECT rowid FROM t1 WHERE content MATCH 'five "one three"'}
  123. } {21 29}
  124. do_test fts1a-2.11 {
  125. execsql {SELECT rowid FROM t1 WHERE content MATCH 'five "one three" four'}
  126. } {29}
  127. do_test fts1a-2.12 {
  128. execsql {SELECT rowid FROM t1 WHERE content MATCH 'five four "one three"'}
  129. } {29}
  130. do_test fts1a-2.13 {
  131. execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three" four five'}
  132. } {29}
  133. do_test fts1a-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 fts1a-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 fts1a-3.3 {
  140. execsql {SELECT rowid FROM t1 WHERE content MATCH '-two one'}
  141. } {1 5 9 13 17 21 25 29}
  142. do_test fts1a-4.1 {
  143. execsql {SELECT rowid FROM t1 WHERE content MATCH 'one OR two'}
  144. } {1 2 3 5 6 7 9 10 11 13 14 15 17 18 19 21 22 23 25 26 27 29 30 31}
  145. do_test fts1a-4.2 {
  146. execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two" OR three'}
  147. } {3 4 5 6 7 11 12 13 14 15 19 20 21 22 23 27 28 29 30 31}
  148. do_test fts1a-4.3 {
  149. execsql {SELECT rowid FROM t1 WHERE content MATCH 'three OR "one two"'}
  150. } {3 4 5 6 7 11 12 13 14 15 19 20 21 22 23 27 28 29 30 31}
  151. do_test fts1a-4.4 {
  152. execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two OR three'}
  153. } {3 5 7 11 13 15 19 21 23 27 29 31}
  154. do_test fts1a-4.5 {
  155. execsql {SELECT rowid FROM t1 WHERE content MATCH 'three OR two one'}
  156. } {3 5 7 11 13 15 19 21 23 27 29 31}
  157. do_test fts1a-4.6 {
  158. execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two OR three OR four'}
  159. } {3 5 7 9 11 13 15 19 21 23 25 27 29 31}
  160. do_test fts1a-4.7 {
  161. execsql {SELECT rowid FROM t1 WHERE content MATCH 'two OR three OR four one'}
  162. } {3 5 7 9 11 13 15 19 21 23 25 27 29 31}
  163. # Test the ability to handle NULL content
  164. #
  165. do_test fts1a-5.1 {
  166. execsql {INSERT INTO t1(content) VALUES(NULL)}
  167. } {}
  168. do_test fts1a-5.2 {
  169. set rowid [db last_insert_rowid]
  170. execsql {SELECT content FROM t1 WHERE rowid=$rowid}
  171. } {{}}
  172. do_test fts1a-5.3 {
  173. execsql {SELECT rowid FROM t1 WHERE content MATCH NULL}
  174. } {}
  175. finish_test