Skip to main content

Full-Text Search

Turso Extension: Full-text search (FTS) in Turso is powered by Tantivy, not SQLite’s FTS3/FTS4/FTS5 modules. The syntax and functions differ from SQLite FTS.
Turso provides full-text search through custom FTS indexes and three SQL functions: fts_match for filtering, fts_score for relevance ranking, and fts_highlight for displaying results with matched terms highlighted.

Creating FTS Indexes

FTS indexes are created with the USING fts clause on CREATE INDEX. Each indexed column participates in the full-text search.

Tokenizer Configuration

Each column can use a different tokenizer via the WITH clause.

Available Tokenizers

Tokenizer examples:

Field Weights

You can assign relative weights to indexed columns to influence the BM25 relevance score.

Functions

fts_match

Returns 1 if the row matches the full-text query, or 0 otherwise. Used in the WHERE clause to filter rows.
Returns: INTEGER — 1 if the row matches, 0 otherwise. The columns passed to fts_match must correspond to columns in an existing FTS index. When Turso’s query planner detects fts_match in a WHERE clause, it routes the query through the FTS index for efficient lookup.

fts_score

Computes the BM25 relevance score for each matching row. Lower scores indicate higher relevance.
Returns: REAL — the BM25 relevance score. Lower values mean higher relevance. Use ORDER BY score ASC or ORDER BY score DESC depending on your preference for result ordering. When used in SELECT, the FTS index automatically provides scored results.

fts_highlight

Returns text with matching query terms wrapped in custom tags. Useful for displaying search results with visual emphasis on matched terms.
Returns: TEXT — the input text with matching terms wrapped in the specified tags. Returns the original text if no matches are found. Returns NULL if the query, open_tag, or close_tag is NULL. When multiple columns are provided, their text is concatenated with spaces.

Query Syntax

The query string passed to fts_match and fts_score supports Tantivy’s query parser syntax.

Basic queries

Advanced queries

Examples


Complete Example

This example walks through creating a table, adding an FTS index, inserting data, and running queries with scoring and highlighting.

Index Maintenance

OPTIMIZE INDEX

Merges all Tantivy segments into a single optimized segment. This improves query performance and reduces storage overhead, particularly after bulk inserts.
When to use:
  • After bulk data imports with many INSERT statements
  • When query performance degrades over time
  • During scheduled maintenance windows
What it does:
  • Flushes any pending documents to disk
  • Merges all segments into a single segment
  • Removes deleted document tombstones
  • Invalidates internal caches for fresh reads

DML and Index Updates

FTS indexes are updated automatically when you modify the underlying table.

Comparison with SQLite FTS5


Current Limitations

  • No snippet function: Use fts_highlight for term emphasis; context snippets are not yet available.
  • No automatic segment merging: Use OPTIMIZE INDEX periodically after bulk writes.
  • No read-your-writes in a transaction: FTS changes within a transaction are not visible to queries until the transaction is committed. ROLLBACK correctly discards both table and FTS changes.
  • No MATCH operator syntax: Use fts_match() function calls instead of WHERE table MATCH 'query'.

See Also