From c81284754f4cd5ff1fec842608ed187311b47fae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Fri, 7 Oct 2016 14:34:12 +0200 Subject: [PATCH] FTS documentation --- README.md | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5377598fa..7ad9ced1a 100644 --- a/README.md +++ b/README.md @@ -3113,10 +3113,25 @@ let books = Book.fetchAll(db, let books = Book.matching(pattern).fetchAll(db) ``` -- **Create full-text virtual tables**: store your indexed text ([FTS3/4](#create-fts3-and-fts4-virtual-tables), [FTS5](#create-fts5-virtual-tables)) -- **Tokenizers**: choose what "matching" means ([FTS3/4](#fts3tokenizer), [FTS5](#fts5tokenizer)) -- **Patterns**: build valid search patterns ([FTS3/4](#fts3pattern), [FTS5](#fts5pattern)) -- **[Unicode Full-Text Gotchas](#unicode-full-text-gotchas)**: unicorns don't exist +- **Create full-text virtual tables** [FTS3/4](#create-fts3-and-fts4-virtual-tables) • [FTS5](#create-fts5-virtual-tables) + + Store your indexed text. + +- **Tokenizers**: [FTS3/4](#fts3tokenizer) • [FTS5](#fts5tokenizer) + + Choose what "matching" means + +- **Patterns**: [FTS3/4](#fts3pattern) • [FTS5](#fts5pattern) + + Build valid search patterns + +- **Sorting by Relevance**: [FTS5](#fts5-sorting-by-relevance) + + GRDB does not provide any ranking for FTS3 and FTS4. See SQLite's [Search Application Tips](https://www.sqlite.org/fts3.html#appendix_a) if you really need it. + +- **[Unicode Full-Text Gotchas](#unicode-full-text-gotchas)** + + Unicorns don't exist. ### Create FTS3 and FTS4 Virtual Tables @@ -3526,6 +3541,23 @@ Use them in the [query interface](#the-query-interface): let documents = Document.matching(pattern).fetchAll(db) ``` +### FTS5: Sorting by Relevance + +**FTS5 can sort results by relevance** (most to least relevant): + +```swift +// SQL +let documents = Document.fetchAll(db, + "SELECT * FROM documents WHERE documents MATCH ? ORDER BY rank", + arguments: [pattern]) + +// Query Interface +let documents = Document.matching(pattern).order(Column("rank")).fetchAll(db) +``` + +For more information about the ranking algorithm, as well as extra options, read [Sorting by Auxiliary Function Results](https://www.sqlite.org/fts5.html#sorting_by_auxiliary_function_results) + + ### Unicode Full-Text Gotchas SQLite tokenizers for [FTS3, FTS4](#fts3tokenizer) and [FTS5](#fts5tokenizer) are generally unicode-aware, with a few caveats, and limitations.