fts5origintext3.test 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. # 2023 November 22
  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 fts5origintext3
  16. # If SQLITE_ENABLE_FTS5 is not defined, omit this file.
  17. ifcapable !fts5 {
  18. finish_test
  19. return
  20. }
  21. foreach_detail_mode $testprefix {
  22. foreach {tn insttoken} {
  23. 1 0
  24. 2 1
  25. } {
  26. reset_db
  27. sqlite3_fts5_register_origintext db
  28. fts5_aux_test_functions db
  29. proc insttoken {cmd iIdx iToken} {
  30. set txt [$cmd xInstToken $iIdx $iToken]
  31. string map [list "\0" "."] $txt
  32. }
  33. sqlite3_fts5_create_function db insttoken insttoken
  34. do_execsql_test $tn.1.0 {
  35. CREATE VIRTUAL TABLE ft USING fts5(
  36. x, tokenize="origintext unicode61", tokendata=1, detail=%DETAIL%
  37. );
  38. }
  39. do_execsql_test $tn.1.0.1 {
  40. INSERT INTO ft(ft, rank) VALUES('insttoken', 1);
  41. }
  42. do_execsql_test $tn.1.1 {
  43. INSERT INTO ft VALUES('Hello world HELLO WORLD hello');
  44. }
  45. do_execsql_test $tn.1.2 {
  46. SELECT fts5_test_poslist(ft) FROM ft('hello');
  47. } {{0.0.0 0.0.2 0.0.4}}
  48. do_execsql_test $tn.1.3 {
  49. SELECT
  50. insttoken(ft, 0, 0),
  51. insttoken(ft, 1, 0),
  52. insttoken(ft, 2, 0)
  53. FROM ft('hello');
  54. } {hello.Hello hello.HELLO hello}
  55. do_execsql_test $tn.1.3.1 {
  56. SELECT
  57. insttoken(ft, 0, 0),
  58. insttoken(ft, 1, 0),
  59. insttoken(ft, 2, 0)
  60. FROM ft('hel*');
  61. } {hello.Hello hello.HELLO hello}
  62. do_execsql_test $tn.1.4 {
  63. SELECT
  64. insttoken(ft, 0, 0),
  65. insttoken(ft, 1, 0),
  66. insttoken(ft, 2, 0)
  67. FROM ft('hello') ORDER BY rank;
  68. } {hello.Hello hello.HELLO hello}
  69. do_execsql_test $tn.1.5 {
  70. CREATE VIRTUAL TABLE ft2 USING fts5(
  71. x, tokenize="origintext unicode61", tokendata=1, detail=%DETAIL%
  72. );
  73. INSERT INTO ft2(rowid, x) VALUES(1, 'ONE one two three ONE');
  74. INSERT INTO ft2(rowid, x) VALUES(2, 'TWO one two three TWO');
  75. INSERT INTO ft2(rowid, x) VALUES(3, 'THREE one two three THREE');
  76. }
  77. do_execsql_test $tn.1.6 {
  78. SELECT insttoken(ft2, 0, 0), rowid FROM ft2('three') ORDER BY rank;
  79. } {three.THREE 3 three 1 three 2}
  80. do_execsql_test $tn.1.7 {
  81. INSERT INTO ft2(rowid, x) VALUES(10, 'aaa bbb BBB');
  82. INSERT INTO ft2(rowid, x) VALUES(12, 'bbb bbb bbb');
  83. INSERT INTO ft2(rowid, x) VALUES(13, 'bbb bbb bbb');
  84. INSERT INTO ft2(rowid, x) VALUES(14, 'bbb BBB bbb');
  85. INSERT INTO ft2(rowid, x) VALUES(15, 'bbb bbb bbb');
  86. INSERT INTO ft2(rowid, x) VALUES(16, 'bbb bbb bbb');
  87. INSERT INTO ft2(rowid, x) VALUES(17, 'bbb bbb bbb');
  88. INSERT INTO ft2(rowid, x) VALUES(18, 'bbb bbb bbb');
  89. INSERT INTO ft2(rowid, x) VALUES(19, 'bbb bbb bbb');
  90. INSERT INTO ft2(rowid, x) VALUES(20, 'bbb bbb bbb');
  91. INSERT INTO ft2(rowid, x) VALUES(21, 'bbb bbb bbb');
  92. INSERT INTO ft2(rowid, x) VALUES(22, 'bbb bbb bbb');
  93. INSERT INTO ft2(rowid, x) VALUES(23, 'bbb bbb bbb');
  94. INSERT INTO ft2(rowid, x) VALUES(24, 'aaa bbb BBB');
  95. }
  96. do_execsql_test $tn.1.8 { SELECT rowid FROM ft2('aaa AND bbb'); } {10 24}
  97. do_execsql_test $tn.1.9 { SELECT rowid FROM ft2('bbb AND aaa'); } {10 24}
  98. do_execsql_test $tn.2.0 {
  99. CREATE VIRTUAL TABLE ft3 USING fts5(
  100. x, tokenize="origintext unicode61", tokendata=1, detail=%DETAIL%,
  101. prefix=2
  102. );
  103. }
  104. do_execsql_test $tn.2.1 {
  105. INSERT INTO ft3(rowid, x) VALUES(1, 'one');
  106. INSERT INTO ft3(rowid, x) VALUES(2, 'ONE');
  107. INSERT INTO ft3(rowid, x) VALUES(3, 'ONT');
  108. INSERT INTO ft3(rowid, x) VALUES(4, 'on');
  109. INSERT INTO ft3(rowid, x) VALUES(5, 'On');
  110. }
  111. do_execsql_test $tn.2.2 {
  112. SELECT rowid FROM ft3('on*');
  113. } {1 2 3 4 5}
  114. do_execsql_test $tn.2.3 {
  115. SELECT rowid, insttoken(ft3, 0, 0) FROM ft3('on*');
  116. } {1 one 2 one.ONE 3 ont.ONT 4 on 5 on.On}
  117. }
  118. }
  119. finish_test