mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-27 04:14:21 +00:00
Documentation
This commit is contained in:
1 parent
b0e68366d4
commit
ec460ff07a
1 file changed
+16
-11
@@ -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
|
||||
|
||||
|
||||
Reference in new issue
Block a user