fts3e.test 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. # 2008 July 29
  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. # These tests exercise the various types of fts3 cursors.
  12. #
  13. # $Id: fts3e.test,v 1.1 2008/07/29 20:24:46 shess Exp $
  14. #
  15. set testdir [file dirname $argv0]
  16. source $testdir/tester.tcl
  17. # If SQLITE_ENABLE_FTS3 is not defined, omit this file.
  18. ifcapable !fts3 {
  19. finish_test
  20. return
  21. }
  22. #*************************************************************************
  23. # Test table scan (QUERY_GENERIC). This kind of query happens for
  24. # queries with no WHERE clause, or for WHERE clauses which cannot be
  25. # satisfied by an index.
  26. db eval {
  27. DROP TABLE IF EXISTS t1;
  28. CREATE VIRTUAL TABLE t1 USING fts3(c);
  29. INSERT INTO t1 (docid, c) VALUES (1, 'This is a test');
  30. INSERT INTO t1 (docid, c) VALUES (2, 'That was a test');
  31. INSERT INTO t1 (docid, c) VALUES (3, 'This is a test');
  32. }
  33. do_test fts3e-1.1 {
  34. execsql {
  35. SELECT docid FROM t1 ORDER BY docid;
  36. }
  37. } {1 2 3}
  38. do_test fts3e-1.2 {
  39. execsql {
  40. SELECT docid FROM t1 WHERE c LIKE '%test' ORDER BY docid;
  41. }
  42. } {1 2 3}
  43. do_test fts3e-1.3 {
  44. execsql {
  45. SELECT docid FROM t1 WHERE c LIKE 'That%' ORDER BY docid;
  46. }
  47. } {2}
  48. #*************************************************************************
  49. # Test lookup by docid (QUERY_DOCID). This kind of query happens for
  50. # queries which select by the docid/rowid implicit index.
  51. db eval {
  52. DROP TABLE IF EXISTS t1;
  53. DROP TABLE IF EXISTS t2;
  54. CREATE VIRTUAL TABLE t1 USING fts3(c);
  55. CREATE TABLE t2(id INTEGER PRIMARY KEY AUTOINCREMENT, weight INTEGER UNIQUE);
  56. INSERT INTO t2 VALUES (null, 10);
  57. INSERT INTO t1 (docid, c) VALUES (last_insert_rowid(), 'This is a test');
  58. INSERT INTO t2 VALUES (null, 5);
  59. INSERT INTO t1 (docid, c) VALUES (last_insert_rowid(), 'That was a test');
  60. INSERT INTO t2 VALUES (null, 20);
  61. INSERT INTO t1 (docid, c) VALUES (last_insert_rowid(), 'This is a test');
  62. }
  63. # TODO(shess): This actually is doing QUERY_GENERIC? I'd have
  64. # expected QUERY_DOCID in this case, as for a very large table the
  65. # full scan is less efficient.
  66. do_test fts3e-2.1 {
  67. execsql {
  68. SELECT docid FROM t1 WHERE docid in (1, 2, 10);
  69. SELECT rowid FROM t1 WHERE rowid in (1, 2, 10);
  70. }
  71. } {1 2 1 2}
  72. do_test fts3e-2.2 {
  73. execsql {
  74. SELECT docid, weight FROM t1, t2 WHERE t2.id = t1.docid ORDER BY weight;
  75. SELECT t1.rowid, weight FROM t1, t2 WHERE t2.id = t1.rowid ORDER BY weight;
  76. }
  77. } {2 5 1 10 3 20 2 5 1 10 3 20}
  78. do_test fts3e-2.3 {
  79. execsql {
  80. SELECT docid, weight FROM t1, t2
  81. WHERE t2.weight>5 AND t2.id = t1.docid ORDER BY weight;
  82. SELECT t1.rowid, weight FROM t1, t2
  83. WHERE t2.weight>5 AND t2.id = t1.rowid ORDER BY weight;
  84. }
  85. } {1 10 3 20 1 10 3 20}
  86. #*************************************************************************
  87. # Test lookup by MATCH (QUERY_FULLTEXT). This is the fulltext index.
  88. db eval {
  89. DROP TABLE IF EXISTS t1;
  90. DROP TABLE IF EXISTS t2;
  91. CREATE VIRTUAL TABLE t1 USING fts3(c);
  92. CREATE TABLE t2(id INTEGER PRIMARY KEY AUTOINCREMENT, weight INTEGER UNIQUE);
  93. INSERT INTO t2 VALUES (null, 10);
  94. INSERT INTO t1 (docid, c) VALUES (last_insert_rowid(), 'This is a test');
  95. INSERT INTO t2 VALUES (null, 5);
  96. INSERT INTO t1 (docid, c) VALUES (last_insert_rowid(), 'That was a test');
  97. INSERT INTO t2 VALUES (null, 20);
  98. INSERT INTO t1 (docid, c) VALUES (last_insert_rowid(), 'This is a test');
  99. }
  100. do_test fts3e-3.1 {
  101. execsql {
  102. SELECT docid FROM t1 WHERE t1 MATCH 'this' ORDER BY docid;
  103. }
  104. } {1 3}
  105. do_test fts3e-3.2 {
  106. execsql {
  107. SELECT docid, weight FROM t1, t2
  108. WHERE t1 MATCH 'this' AND t1.docid = t2.id ORDER BY weight;
  109. }
  110. } {1 10 3 20}
  111. finish_test