From ec460ff07aeac19a8505e8b7300bf0ca817e33af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Wed, 12 Oct 2016 08:00:32 +0200 Subject: [PATCH] Documentation --- Documentation/FTS5Tokenizers.md | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/Documentation/FTS5Tokenizers.md b/Documentation/FTS5Tokenizers.md index e253a2cc2..382dfff22 100644 --- a/Documentation/FTS5Tokenizers.md +++ b/Documentation/FTS5Tokenizers.md @@ -202,6 +202,22 @@ final class MyTokenizer : FTS5WrapperTokenizer { Wrapper tokenizers have to implement the `accept(token:flags:for:tokenCallback:)` method. +For example, a custom tokenizer that simply passes tokens through gives: + +```swift +final class MyTokenizer : FTS5WrapperTokenizer { + func accept( + token: String, + flags: FTS5TokenFlags, + for tokenization: FTS5Tokenization, + tokenCallback: FTS5WrapperTokenCallback) throws + { + // pass through + try tokenCallback(token, flags) + } +} +``` + The token argument is a token produced by the wrapped tokenizer, ready to be ignored, modified, or multiplied into several [synonyms](#example-synonyms). The tokenization parameter tells the reason why tokens are produced, if FTS5 is tokenizing a document, or a search pattern. Some tokenizers may produce different tokens depending on this parameter. @@ -213,17 +229,6 @@ There are a two rules to observe when implementing the accept method: 1. Errors thrown by the tokenCallback function must not be caught. 2. The flags parameter should be given unmodified to the tokenCallback function along with the custom token, unless you union it with the `.colocated` flag when the tokenizer produces [synonyms](#example-synonyms). -For example, a custom tokenizer that simply passes tokens through gives: - -```swift -final class MyTokenizer : FTS5WrapperTokenizer { - func accept(token: String, flags: FTS5TokenFlags, for tokenization: FTS5Tokenization, tokenCallback: FTS5WrapperTokenCallback) throws { - // pass through - try tokenCallback(token, flags) - } -} -``` - ### Choosing the Wrapped Tokenizer