fts5origintext2.test 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. # 2014 Jan 08
  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. # Tests focused on phrase queries.
  13. #
  14. source [file join [file dirname [info script]] fts5_common.tcl]
  15. set testprefix fts5origintext2
  16. # If SQLITE_ENABLE_FTS5 is not defined, omit this file.
  17. ifcapable !fts5 {
  18. finish_test
  19. return
  20. }
  21. sqlite3_fts5_register_origintext db
  22. do_execsql_test 1.0 {
  23. CREATE VIRTUAL TABLE ft USING fts5(
  24. x, tokenize="origintext unicode61", tokendata=1
  25. );
  26. }
  27. do_execsql_test 1.1 {
  28. BEGIN;
  29. INSERT INTO ft VALUES('Hello');
  30. INSERT INTO ft VALUES('hello');
  31. INSERT INTO ft VALUES('HELLO');
  32. INSERT INTO ft VALUES('today');
  33. INSERT INTO ft VALUES('today');
  34. INSERT INTO ft VALUES('today');
  35. INSERT INTO ft VALUES('World');
  36. INSERT INTO ft VALUES('world');
  37. INSERT INTO ft VALUES('WORLD');
  38. COMMIT;
  39. }
  40. do_execsql_test 1.2 { SELECT rowid FROM ft('hello'); } {1 2 3}
  41. do_execsql_test 1.3 { SELECT rowid FROM ft('today'); } {4 5 6}
  42. do_execsql_test 1.4 { SELECT rowid FROM ft('world'); } {7 8 9}
  43. do_execsql_test 1.5 {
  44. SELECT count(*) FROM ft_data
  45. } 3
  46. do_execsql_test 1.6 {
  47. DELETE FROM ft;
  48. INSERT INTO ft(ft, rank) VALUES('pgsz', 64);
  49. BEGIN;
  50. WITH s(i) AS (
  51. SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<100
  52. )
  53. INSERT INTO ft SELECT 'Hello Hello Hello Hello Hello Hello Hello' FROM s;
  54. INSERT INTO ft VALUES ('hELLO hELLO hELLO');
  55. INSERT INTO ft VALUES('today today today today today today today');
  56. INSERT INTO ft VALUES('today today today today today today today');
  57. INSERT INTO ft VALUES('today today today today today today today');
  58. INSERT INTO ft VALUES('today today today today today today today');
  59. INSERT INTO ft VALUES('today today today today today today today');
  60. INSERT INTO ft VALUES('today today today today today today today');
  61. INSERT INTO ft VALUES('World World World World World World World');
  62. INSERT INTO ft VALUES('world world world world world world world');
  63. INSERT INTO ft VALUES('WORLD WORLD WORLD WORLD WORLD WORLD WORLD');
  64. INSERT INTO ft VALUES('World World World World World World World');
  65. INSERT INTO ft VALUES('world world world world world world world');
  66. INSERT INTO ft VALUES('WORLD WORLD WORLD WORLD WORLD WORLD WORLD');
  67. COMMIT;
  68. }
  69. do_execsql_test 1.7 {
  70. SELECT count(*) FROM ft_data;
  71. } 23
  72. do_execsql_test 1.8 { SELECT rowid FROM ft('hello') WHERE rowid>100; } {101}
  73. do_execsql_test 1.9 {
  74. DELETE FROM ft;
  75. INSERT INTO ft(ft) VALUES('optimize');
  76. SELECT count(*) FROM ft_data;
  77. } {2}
  78. do_execsql_test 1.10 {
  79. BEGIN;
  80. INSERT INTO ft VALUES('Hello');
  81. INSERT INTO ft VALUES('hello');
  82. INSERT INTO ft VALUES('HELLO');
  83. INSERT INTO ft VALUES('today');
  84. INSERT INTO ft VALUES('today');
  85. INSERT INTO ft VALUES('today');
  86. INSERT INTO ft VALUES('World');
  87. INSERT INTO ft VALUES('world');
  88. INSERT INTO ft VALUES('WORLD');
  89. }
  90. do_execsql_test 1.11 { SELECT rowid FROM ft('hello'); } {1 2 3}
  91. do_execsql_test 1.12 { SELECT rowid FROM ft('today'); } {4 5 6}
  92. do_execsql_test 1.13 { SELECT rowid FROM ft('world'); } {7 8 9}
  93. do_execsql_test 1.14 { SELECT rowid FROM ft('hello') ORDER BY rank; } {1 2 3}
  94. #------------------------------------------------------------------------
  95. reset_db
  96. sqlite3_fts5_register_origintext db
  97. proc tokens {cmd} {
  98. set ret [list]
  99. for {set iTok 0} {$iTok < [$cmd xInstCount]} {incr iTok} {
  100. set txt [$cmd xInstToken $iTok 0]
  101. set txt [string map [list "\0" "."] $txt]
  102. lappend ret $txt
  103. }
  104. set ret
  105. }
  106. sqlite3_fts5_create_function db tokens tokens
  107. do_execsql_test 2.0 {
  108. CREATE VIRTUAL TABLE x1 USING fts5(
  109. v, tokenize="origintext unicode61", tokendata=1, detail=none
  110. );
  111. INSERT INTO x1 VALUES('xxx Xxx XXX yyy YYY yyy');
  112. INSERT INTO x1 VALUES('xxx yyy xxx yyy yyy yyy');
  113. }
  114. do_execsql_test 2.1 {
  115. SELECT tokens(x1) FROM x1('xxx');
  116. } {
  117. {xxx xxx.Xxx xxx.XXX} {xxx xxx}
  118. }
  119. do_execsql_test 2.2 {
  120. UPDATE x1_content SET c0 = 'xxx xxX xxx yyy yyy yyy' WHERE id=1;
  121. }
  122. do_execsql_test 2.3 {
  123. SELECT tokens(x1) FROM x1('xxx');
  124. } {
  125. {xxx {} xxx} {xxx xxx}
  126. }
  127. finish_test