From 44b59eea5873bd7b022abf23ce10c213966f78d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Mon, 10 Oct 2016 20:54:35 +0200 Subject: [PATCH] Documentation --- GRDB/FTS/FTS5WrapperTokenizer.swift | 31 +++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/GRDB/FTS/FTS5WrapperTokenizer.swift b/GRDB/FTS/FTS5WrapperTokenizer.swift index d3b7ac789..023530891 100644 --- a/GRDB/FTS/FTS5WrapperTokenizer.swift +++ b/GRDB/FTS/FTS5WrapperTokenizer.swift @@ -19,6 +19,31 @@ public typealias FTS5WrapperTokenCallback = (_ token: String, _ flags: FTS5TokenFlags) throws -> () /// The protocol for custom FTS5 tokenizers that wrap another tokenizer. + /// + /// Types that adopt FTS5WrapperTokenizer don't have to implement the + /// low-level FTS5Tokenizer.tokenize(context:flags:pText:nText:tokenCallback:). + /// + /// Instead, they process regular Swift strings. + /// + /// Here is the implementation for a trivial tokenizer that wraps the + /// built-in ascii tokenizer without any custom processing: + /// + /// class TrivialAsciiTokenizer : FTS5WrapperTokenizer { + /// static let name = "trivial" + /// let wrappedTokenizer: FTS5Tokenizer + /// + /// init(db: Database, arguments: [String]) throws { + /// wrappedTokenizer = try db.makeTokenizer(.ascii()) + /// } + /// + /// func customizesWrappedTokenizer(flags: FTS5TokenizeFlags) -> Bool { + /// return true + /// } + /// + /// func accept(token: String, flags: FTS5TokenFlags, tokenCallback: FTS5WrapperTokenCallback) throws { + /// try tokenCallback(token, flags) + /// } + /// } public protocol FTS5WrapperTokenizer : FTS5CustomTokenizer { /// The wrapped tokenizer var wrappedTokenizer: FTS5Tokenizer { get } @@ -37,10 +62,12 @@ /// /// func accept(token: String, flags: FTS5TokenFlags, tokenCallback: FTS5WrapperTokenCallback) throws { /// // pass through: - /// tokenCallback(token, flags) + /// try tokenCallback(token, flags) /// } /// - /// Union flags with `.colocated` when your tokenizer produces synonyms + /// Errors thrown by `tokenCallback` must not be caught. + /// + /// Union `flags` with `.colocated` when your tokenizer produces synonyms /// (see https://www.sqlite.org/fts5.html#synonym_support): /// /// func accept(token: String, flags: FTS5TokenFlags, tokenCallback: FTS5WrapperTokenCallback) throws {