Skip to main content

Module fts

Module fts 

Source
Expand description

FTS5 full-text search with BM25 ranking.

This module provides search helpers on top of the items_fts FTS5 virtual table defined in super::schema. The FTS5 table is automatically kept in sync with the items table via INSERT/UPDATE/DELETE triggers.

§Column Weights (BM25)

ColumnWeightRationale
title3.0Most specific, short, high signal
description2.0Detailed context, moderate signal
labels1.0Namespace tags, low cardinality

§Tokenizer

Porter stemmer + unicode61 tokenizer with prefix indexes on 2 and 3 characters. This supports:

  • Stemming: searching “running” matches “run”, “runs”, “runner”
  • Prefix search: “auth*” matches “authentication”, “authorize”
  • Unicode: full Unicode word-breaking

§Performance

Sub-1ms query time at Tier S (≤1k items). FTS5 lookups are O(log N) via the b-tree index and prefix tables.

Constants§

BM25_WEIGHT_DESCRIPTION
BM25_WEIGHT_LABELS
BM25_WEIGHT_TITLE
Default BM25 column weights: title=3, description=2, labels=1.

Functions§

fts_in_sync
Validate that the FTS5 index is in sync with the items table.
fts_row_count
Return the number of rows in the FTS5 index.
rebuild_fts_index
Rebuild the FTS5 index from the current items table.
search_bm25
Search the FTS5 index with BM25 ranking and column weights.