fts5trigram2.test 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. # 2023 October 24
  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 for the fts5 "trigram" tokenizer.
  13. #
  14. source [file join [file dirname [info script]] fts5_common.tcl]
  15. ifcapable !fts5 { finish_test ; return }
  16. set ::testprefix fts5trigram2
  17. do_execsql_test 1.0 "
  18. CREATE VIRTUAL TABLE t1 USING fts5(y, tokenize='trigram remove_diacritics 1');
  19. INSERT INTO t1 VALUES('abc\u0303defghijklm');
  20. INSERT INTO t1 VALUES('a\u0303b\u0303c\u0303defghijklm');
  21. "
  22. do_catchsql_test 1.0.1 {
  23. CREATE VIRTUAL TABLE t2 USING fts5(z, tokenize='trigram remove_diacritics');
  24. } {1 {error in tokenizer constructor}}
  25. do_execsql_test 1.1 {
  26. SELECT highlight(t1, 0, '(', ')') FROM t1('abc');
  27. } [list \
  28. "(abc\u0303)defghijklm" \
  29. "(a\u0303b\u0303c\u0303)defghijklm" \
  30. ]
  31. do_execsql_test 1.2 {
  32. SELECT highlight(t1, 0, '(', ')') FROM t1('bcde');
  33. } [list \
  34. "a(bc\u0303de)fghijklm" \
  35. "a\u0303(b\u0303c\u0303de)fghijklm" \
  36. ]
  37. do_execsql_test 1.3 {
  38. SELECT highlight(t1, 0, '(', ')') FROM t1('cdef');
  39. } [list \
  40. "ab(c\u0303def)ghijklm" \
  41. "a\u0303b\u0303(c\u0303def)ghijklm" \
  42. ]
  43. do_execsql_test 1.4 {
  44. SELECT highlight(t1, 0, '(', ')') FROM t1('def');
  45. } [list \
  46. "abc\u0303(def)ghijklm" \
  47. "a\u0303b\u0303c\u0303(def)ghijklm" \
  48. ]
  49. #-------------------------------------------------------------------------
  50. do_catchsql_test 2.0 {
  51. CREATE VIRTUAL TABLE t2 USING fts5(
  52. z, tokenize='trigram case_sensitive 1 remove_diacritics 1'
  53. );
  54. } {1 {error in tokenizer constructor}}
  55. do_execsql_test 2.1 {
  56. CREATE VIRTUAL TABLE t2 USING fts5(
  57. z, tokenize='trigram case_sensitive 0 remove_diacritics 1'
  58. );
  59. }
  60. do_execsql_test 2.2 "
  61. INSERT INTO t2 VALUES('\u00E3bcdef');
  62. INSERT INTO t2 VALUES('b\u00E3cdef');
  63. INSERT INTO t2 VALUES('bc\u00E3def');
  64. INSERT INTO t2 VALUES('bcd\u00E3ef');
  65. "
  66. do_execsql_test 2.3 {
  67. SELECT highlight(t2, 0, '(', ')') FROM t2('abc');
  68. } "(\u00E3bc)def"
  69. do_execsql_test 2.4 {
  70. SELECT highlight(t2, 0, '(', ')') FROM t2('bac');
  71. } "(b\u00E3c)def"
  72. do_execsql_test 2.5 {
  73. SELECT highlight(t2, 0, '(', ')') FROM t2('bca');
  74. } "(bc\u00E3)def"
  75. do_execsql_test 2.6 "
  76. SELECT highlight(t2, 0, '(', ')') FROM t2('\u00E3bc');
  77. " "(\u00E3bc)def"
  78. #-------------------------------------------------------------------------
  79. do_execsql_test 3.0 {
  80. CREATE VIRTUAL TABLE t3 USING fts5(
  81. z, tokenize='trigram remove_diacritics 1'
  82. );
  83. } {}
  84. do_execsql_test 3.1 "
  85. INSERT INTO t3 VALUES ('\u0303abc\u0303');
  86. "
  87. do_execsql_test 3.2 {
  88. SELECT highlight(t3, 0, '(', ')') FROM t3('abc');
  89. } "\u0303(abc\u0303)"
  90. #-------------------------------------------------------------------------
  91. do_execsql_test 4.0 {
  92. CREATE VIRTUAL TABLE t4 USING fts5(z, tokenize=trigram);
  93. } {}
  94. do_execsql_test 4.1 {
  95. INSERT INTO t4 VALUES('ABCD');
  96. INSERT INTO t4 VALUES('DEFG');
  97. } {}
  98. db close
  99. sqlite3 db test.db
  100. do_eqp_test 4.1 {
  101. SELECT rowid FROM t4 WHERE z LIKE '%abc%'
  102. } {VIRTUAL TABLE INDEX 0:L0}
  103. do_execsql_test 4.2 {
  104. SELECT rowid FROM t4 WHERE z LIKE '%abc%'
  105. } {1}
  106. #-------------------------------------------------------------------------
  107. reset_db
  108. do_execsql_test 5.0 {
  109. CREATE VIRTUAL TABLE t5 USING fts5(
  110. c1, tokenize='trigram', detail='none'
  111. );
  112. INSERT INTO t5(rowid, c1) VALUES(1, 'abc_____xyx_yxz');
  113. INSERT INTO t5(rowid, c1) VALUES(2, 'abc_____xyxz');
  114. INSERT INTO t5(rowid, c1) VALUES(3, 'ac_____xyxz');
  115. } {}
  116. do_execsql_test 5.1 {
  117. SELECT rowid FROM t5 WHERE c1 LIKE 'abc%xyxz'
  118. } {2}
  119. finish_test