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