File tree Expand file tree Collapse file tree 2 files changed +17
-2
lines changed
Sources/SQLite/Extensions Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -95,10 +95,10 @@ extension VirtualTable {
9595public struct Tokenizer {
9696
9797 public static let Simple = Tokenizer ( " simple " )
98-
9998 public static let Porter = Tokenizer ( " porter " )
10099
101- public static func Unicode61( removeDiacritics: Bool ? = nil , tokenchars: Set < Character > = [ ] ,
100+ public static func Unicode61( removeDiacritics: Bool ? = nil ,
101+ tokenchars: Set < Character > = [ ] ,
102102 separators: Set < Character > = [ ] ) -> Tokenizer {
103103 var arguments = [ String] ( )
104104
@@ -119,6 +119,11 @@ public struct Tokenizer {
119119 return Tokenizer ( " unicode61 " , arguments)
120120 }
121121
122+ // https://sqlite.org/fts5.html#the_experimental_trigram_tokenizer
123+ public static func Trigram( caseSensitive: Bool = false ) -> Tokenizer {
124+ return Tokenizer ( " trigram " , [ " case_sensitive " , caseSensitive ? " 1 " : " 0 " ] )
125+ }
126+
122127 public static func Custom( _ name: String ) -> Tokenizer {
123128 Tokenizer ( Tokenizer . moduleName. quote ( ) , [ name. quote ( ) ] )
124129 }
Original file line number Diff line number Diff line change @@ -81,6 +81,16 @@ class FTS5Tests: XCTestCase {
8181 sql ( config. tokenizer ( . Unicode61( removeDiacritics: true , tokenchars: [ " . " ] , separators: [ " X " ] ) ) ) )
8282 }
8383
84+ func test_tokenizer_trigram( ) {
85+ XCTAssertEqual (
86+ " CREATE VIRTUAL TABLE \" virtual_table \" USING fts5(tokenize=trigram case_sensitive 0) " ,
87+ sql ( config. tokenizer ( . Trigram( ) ) ) )
88+
89+ XCTAssertEqual (
90+ " CREATE VIRTUAL TABLE \" virtual_table \" USING fts5(tokenize=trigram case_sensitive 1) " ,
91+ sql ( config. tokenizer ( . Trigram( caseSensitive: true ) ) ) )
92+ }
93+
8494 func test_column_size( ) {
8595 XCTAssertEqual (
8696 " CREATE VIRTUAL TABLE \" virtual_table \" USING fts5(columnsize=1) " ,
You can’t perform that action at this time.
0 commit comments