3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #*************************************************************************
12 # Tests for the fts5 "trigram" tokenizer.
15 source [file join [file dirname [info script]] fts5_common.tcl]
16 ifcapable !fts5 { finish_test ; return }
17 set ::testprefix fts5trigram
20 CREATE VIRTUAL TABLE t1 USING fts5(y, tokenize=trigram);
21 INSERT INTO t1 VALUES('abcdefghijklm');
22 INSERT INTO t1 VALUES('กรุงเทพมหานคร');
26 1 abc "(abc)defghijklm"
27 2 defgh "abc(defgh)ijklm"
28 3 abcdefghijklm "(abcdefghijklm)"
29 4 กรุ "(กรุ)งเทพมหานคร"
30 5 งเทพมห "กรุ(งเทพมห)านคร"
31 6 กรุงเทพมหานคร "(กรุงเทพมหานคร)"
32 7 Abc "(abc)defghijklm"
33 8 deFgh "abc(defgh)ijklm"
34 9 aBcdefGhijKlm "(abcdefghijklm)"
36 do_execsql_test 1.1.$tn {
37 SELECT highlight(t1, 0, '(', ')') FROM t1($s)
41 do_execsql_test 1.2.0 {
42 SELECT fts5_expr('ABCD', 'tokenize=trigram')
45 do_execsql_test 1.2.1 {
46 SELECT * FROM t1 WHERE y LIKE ? ESCAPE 'a'
49 foreach {tn like res} {
60 do_execsql_test 1.3.$tn {
61 SELECT rowid FROM t1 WHERE y LIKE $like
65 #-------------------------------------------------------------------------
68 CREATE VIRTUAL TABLE t1 USING fts5(y, tokenize="trigram case_sensitive 1");
69 INSERT INTO t1 VALUES('abcdefghijklm');
70 INSERT INTO t1 VALUES('กรุงเทพมหานคร');
72 do_catchsql_test 2.0.1 {
73 CREATE VIRTUAL TABLE t2 USING fts5(z, tokenize='trigram case_sensitive');
74 } {1 {error in tokenizer constructor}}
77 1 abc "(abc)defghijklm"
78 2 defgh "abc(defgh)ijklm"
79 3 abcdefghijklm "(abcdefghijklm)"
80 4 กรุ "(กรุ)งเทพมหานคร"
81 5 งเทพมห "กรุ(งเทพมห)านคร"
82 6 กรุงเทพมหานคร "(กรุงเทพมหานคร)"
87 do_execsql_test 2.1.$tn {
88 SELECT highlight(t1, 0, '(', ')') FROM t1($s)
91 foreach {tn like res} {
101 do_execsql_test 2.2.$tn {
102 SELECT rowid FROM t1 WHERE y LIKE $like
105 foreach {tn like res} {
117 12 {abc[^]XYZ]efg*} 1
119 do_execsql_test 2.3.$tn {
120 SELECT rowid FROM t1 WHERE y GLOB $like
124 do_execsql_test 2.3.null.1 {
125 SELECT rowid FROM t1 WHERE y LIKE NULL
128 #-------------------------------------------------------------------------
130 do_catchsql_test 3.1 {
131 CREATE VIRTUAL TABLE ttt USING fts5(c, tokenize="trigram case_sensitive 2");
132 } {1 {error in tokenizer constructor}}
133 do_catchsql_test 3.2 {
134 CREATE VIRTUAL TABLE ttt USING fts5(c, tokenize="trigram case_sensitive 11");
135 } {1 {error in tokenizer constructor}}
136 do_catchsql_test 3.3 {
137 CREATE VIRTUAL TABLE ttt USING fts5(c, "tokenize=trigram case_sensitive 1");
140 #-------------------------------------------------------------------------
142 do_execsql_test 4.0 {
143 CREATE VIRTUAL TABLE t0 USING fts5(b, tokenize = "trigram");
145 do_execsql_test 4.1 {
146 INSERT INTO t0 VALUES (x'000b01');
148 do_execsql_test 4.2 {
149 INSERT INTO t0(t0) VALUES('integrity-check');
152 #-------------------------------------------------------------------------
154 foreach_detail_mode $::testprefix {
157 do_execsql_test 5.cs=$ci.0.1 "
158 CREATE VIRTUAL TABLE t1 USING fts5(
159 y, tokenize=\"trigram case_sensitive $ci\", detail=%DETAIL%
162 do_execsql_test 5.cs=$ci.0.2 {
163 INSERT INTO t1 VALUES('abcdefghijklm');
164 INSERT INTO t1 VALUES('กรุงเทพมหานคร');
167 foreach {tn like res} {
177 do_execsql_test 5.cs=$ci.1.$tn {
178 SELECT rowid FROM t1 WHERE y LIKE $like
184 do_execsql_test 6.0 {
185 CREATE VIRTUAL TABLE ci0 USING fts5(x, tokenize="trigram");
186 CREATE VIRTUAL TABLE ci1 USING fts5(x, tokenize="trigram case_sensitive 1");
189 # LIKE and GLOB both work with case-insensitive tokenizers. Only GLOB works
190 # with case-sensitive.
192 SELECT * FROM ci0 WHERE x LIKE ?
193 } {VIRTUAL TABLE INDEX 0:L0}
195 SELECT * FROM ci0 WHERE x GLOB ?
196 } {VIRTUAL TABLE INDEX 0:G0}
198 SELECT * FROM ci1 WHERE x LIKE ?
199 } {{SCAN ci1 VIRTUAL TABLE INDEX 0:}}
201 SELECT * FROM ci1 WHERE x GLOB ?
202 } {VIRTUAL TABLE INDEX 0:G0}
205 do_execsql_test 7.0 {
206 CREATE VIRTUAL TABLE f USING FTS5(filename, tokenize="trigram");
207 INSERT INTO f (rowid, filename) VALUES
212 (50, "misic-ðµ-.mp3");
214 do_execsql_test 7.1 {
215 SELECT rowid FROM f WHERE +filename GLOB '*ир*';
217 do_execsql_test 7.2 {
218 SELECT rowid FROM f WHERE filename GLOB '*ир*';
222 #-------------------------------------------------------------------------
224 do_execsql_test 8.0 {
225 CREATE VIRTUAL TABLE t1 USING fts5(y, tokenize=trigram);
226 INSERT INTO t1 VALUES('abcdefghijklm');
229 foreach {tn match res} {
230 1 "abc ghi" "(abc)def(ghi)jklm"
231 2 "def ghi" "abc(defghi)jklm"
232 3 "efg ghi" "abcd(efghi)jklm"
233 4 "efghi" "abcd(efghi)jklm"
234 5 "abcd jklm" "(abcd)efghi(jklm)"
235 6 "ijkl jklm" "abcdefgh(ijklm)"
236 7 "ijk ijkl hijk" "abcdefg(hijkl)m"
239 do_execsql_test 8.1.$tn {
240 SELECT highlight(t1, 0, '(', ')') FROM t1($match)
244 do_execsql_test 8.2 {
245 CREATE VIRTUAL TABLE ft2 USING fts5(a, tokenize="trigram");
246 INSERT INTO ft2 VALUES('abc x cde');
247 INSERT INTO ft2 VALUES('abc cde');
248 INSERT INTO ft2 VALUES('abcde');
251 do_execsql_test 8.3 {
252 SELECT highlight(ft2, 0, '[', ']') FROM ft2 WHERE ft2 MATCH 'abc AND cde';