Full-Text BM25 Search
Transactional BM25 full-text indexes, match() filters, /v1/search highlights, suggest, and cross-cluster search.
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#
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:
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 Function | Signature | Capability |
|---|---|---|
match / search | match(text, query) | All-term BM25 boolean match |
score | score(text, query) | BM25 relevance score (f64) |
should_match | should_match(text, query, min_should_match) | Requires at least min_should_match positive clauses |
multi_match / multi_score | multi_match(query, f1, boost1, f2, boost2, ...) | Field-weighted multi-column match & aggregate score |
fuzzy_match | fuzzy_match(text, query [, max_distance]) | Edit-distance typo-tolerant matching |
phrase_match | phrase_match(text, phrase [, slop]) | Ordered proximity phrase matching with optional word slop |
partial_match / partial_score | partial_match(text, query) | Exact/stem, edge-prefix, substring infix, and */? wildcard matching |
synonym_match | synonym_match(text, query, rules) | Query expansion from a => b, c synonym rule strings |
contains_token | contains_token(text, token) | Case-insensitive alphanumeric token check |
highlight | highlight(text, query [, open, close]) | Wrap exact/stem matches in <em>...</em> or custom tags |
highlight_natural / snippet_natural | highlight_natural(text, query [, open, close]) / snippet_natural(text, query, chars) | Highlight/excerpt for natural, fuzzy, prefix & phrase hits |
highlight_partial / snippet_partial | highlight_partial(text, query [, open, close]) / snippet_partial(text, query, chars) | Highlight/excerpt for stem, prefix, substring & wildcard hits |
snippet | snippet(text, query, chars) | Contextual window around first match truncated to chars |
rrf | rrf(rank1, rank2 [, k=60]) | Reciprocal Rank Fusion over two candidate rank lists |
hybrid_score | hybrid_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):
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:
search "serializable snapshot"
in (kb_articles, runbooks)
boost (title: 2.5, body: 1.0)
min_match 1
take 10
skip 0Autocomplete Suggestions (suggest / /v1/suggest)#
Power low-latency prefix search boxes over full-text indexes (supports wildcard collection patterns such as docs*):
suggest "serial" in (kb_articles, docs*) take 8Via HTTP:
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
}'Distributed & Cross-Cluster Search#
In clustered deployments, /v1/search supports fan-out scatter/gather scoring across shards and remote Cross-Cluster Search (CCS) links:
{
"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.