Full-Text BM25 Search

Transactional BM25 full-text indexes, match() filters, /v1/search highlights, suggest, and cross-cluster search.

2 min read SpydQL & Data Modeling

Every SpydDB collection can declare transactional BM25 full-text indexes. Updates to indexed text commit in the exact same ACID transaction as the row itself — eliminating external search sync workers, Elasticsearch clusters, and stale search indexes.

Declaring a Full-Text Index#

spydql
create collection kb_articles {
  id: u64 primary auto_increment,
  category: string(64) not null,
  title: text not null,
  body: text not null,
  published: bool not null default true,
  updated_at: timestamp default now(),

  index idx_kb_fts on (title, body) using fulltext
}

Inline Search & Rich Relevance Functions#

Combine BM25 text relevance, natural/fuzzy/phrase/partial/synonym matching, and custom-tagged snippets directly inside SpydQL pipelines:

spydql
kb_articles
| where published == true and match(body, "rust snapshot isolation")
| pick id,
       category,
       title,
       score(body, "rust snapshot isolation") as bm25,
       snippet(body, "rust snapshot isolation", 140) as preview,
       highlight(title, "snapshot", "<mark>", "</mark>") as highlighted_title
| sort bm25 desc
| take 20
Search FunctionSignatureCapability
match / searchmatch(text, query)All-term BM25 boolean match
scorescore(text, query)BM25 relevance score (f64)
should_matchshould_match(text, query, min_should_match)Requires at least min_should_match positive clauses
multi_match / multi_scoremulti_match(query, f1, boost1, f2, boost2, ...)Field-weighted multi-column match & aggregate score
fuzzy_matchfuzzy_match(text, query [, max_distance])Edit-distance typo-tolerant matching
phrase_matchphrase_match(text, phrase [, slop])Ordered proximity phrase matching with optional word slop
partial_match / partial_scorepartial_match(text, query)Exact/stem, edge-prefix, substring infix, and */? wildcard matching
synonym_matchsynonym_match(text, query, rules)Query expansion from a => b, c synonym rule strings
contains_tokencontains_token(text, token)Case-insensitive alphanumeric token check
highlighthighlight(text, query [, open, close])Wrap exact/stem matches in <em>...</em> or custom tags
highlight_natural / snippet_naturalhighlight_natural(text, query [, open, close]) / snippet_natural(text, query, chars)Highlight/excerpt for natural, fuzzy, prefix & phrase hits
highlight_partial / snippet_partialhighlight_partial(text, query [, open, close]) / snippet_partial(text, query, chars)Highlight/excerpt for stem, prefix, substring & wildcard hits
snippetsnippet(text, query, chars)Contextual window around first match truncated to chars
rrfrrf(rank1, rank2 [, k=60])Reciprocal Rank Fusion over two candidate rank lists
hybrid_scorehybrid_score(text_score, vector_sim [, alpha=0.5])Normalized weighted text + vector hybrid score (alpha in [0.0, 1.0])

Cross-Collection Search & Highlights (/v1/search)#

Query one or many collections simultaneously over HTTP with BM25 scores, highlighted fragments, and category facets (take, skip, boost, min_match):

sh
curl -sS --cacert tls/ca.crt https://localhost:8080/v1/search \
  -H "Authorization: Bearer $SPYD_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "serializable snapshot encryption",
    "collections": ["kb_articles", "runbooks"],
    "boost": { "title": 2.5, "body": 1.0 },
    "min_match": 1,
    "take": 10,
    "skip": 0
  }'

Or execute global search directly in SpydQL:

spydql
search "serializable snapshot"
  in (kb_articles, runbooks)
  boost (title: 2.5, body: 1.0)
  min_match 1
  take 10
  skip 0

Autocomplete Suggestions (suggest / /v1/suggest)#

Power low-latency prefix search boxes over full-text indexes (supports wildcard collection patterns such as docs*):

spydql
suggest "serial" in (kb_articles, docs*) take 8

Via HTTP:

sh
curl -sS --cacert tls/ca.crt https://localhost:8080/v1/suggest \
  -H "Authorization: Bearer $SPYD_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "prefix": "encryp",
    "collections": ["kb_articles"],
    "take": 5
  }'

In clustered deployments, /v1/search supports fan-out scatter/gather scoring across shards and remote Cross-Cluster Search (CCS) links:

json
{
  "query": "payment timeout",
  "collections": ["otel_logs", "incidents"],
  "distributed": true,
  "clusters": ["eu-west", "us-east"],
  "take": 25
}

Every hit honors the caller's exact session RBAC, tenant boundary, row-level filters, and role-scoped field masks automatically.