Search and vectors · Engineering
BM25 full-text search in one process
How NonoDB’s text index ranks documents, what its tokenizer does, and where the built-in search stops.
Full-text search is often the first reason a project adds a second database. The application already stores the content; it just needs relevance ranking, phrase matching, and typo tolerance without syncing everything to a separate search service.
NonoDB includes a BM25 text index and a search operation in the same process. It is not Elasticsearch, but it covers a useful subset without another service.
Creating an index
A text index covers exactly one field:
{"op": "create_text_index", "coll": "articles", "field": "body"}The index is built synchronously. Writers are blocked while the backfill transaction runs, so create it before the collection becomes hot, or accept the pause.
The field can contain strings, booleans, and numeric scalars. Arrays, objects, dates, binary values, and ObjectIds are not indexed for text search.
Query semantics
{ "op": "search", "coll": "articles", "field": "body", "query": "rust async \"zero copy\"", "filter": {"published": true}, "skip": 0, "limit": 10}The current semantics are deliberately simple:
- all positive terms must match (AND);
- duplicate terms are removed;
- quoted phrases must occur as contiguous token sequences;
filteris a residual document filter applied before pagination;skipandlimitapply after filtering and phrase checks;limitdefaults to 10 and is capped at 1,000;_scoreis added to each result, higher is better.
This is not MongoDB’s OR-by-default behavior. If you need “match any of these words”, issue separate searches or use a different query shape.
Tokenization and ranking
Tokenization lowercases and folds diacritics. A query for zazolc matches zażółć. There is no stemming, no stop-word removal, and no language-specific analyzer. Ranking is BM25 over the indexed field.
That makes behavior predictable and language-agnostic, but it also means:
- “run” and “running” are different tokens;
- common words are not filtered out automatically;
- phrase matching is exact after normalization;
- relevance is not tuned per language.
For many product catalogs, support tools, and internal documents, this is enough. For natural-language search with synonyms and stemming, a dedicated search engine is still the better tool.
The index format
Text postings are not a giant LMDB B+ tree. They live in immutable segment files under search/, with manifests, deltas, tombstones, and exact statistics in LMDB metadata.
That design keeps the hot write path bounded: a new document updates the transactional metadata and a delta, while immutable segments are rebuilt or merged outside the request. The trade-off is that search has its own sidecar lifecycle. Backups need to copy the search/ directory, and NONODB_REBUILD_MISSING_SEARCH=1 can rebuild missing segment files at startup.
A reindex rebuilds the text definition and backfills the field. It is a heavy operation; schedule it outside peak traffic.
Filters and TTL
filter uses the normal document filter language and is applied to search results before skip and limit. It can narrow by tenant, status, or any other indexed field.
TTL is enforced before results are returned. Expired documents are filtered from lexical results, and the search path over-fetches when necessary so an expired hit does not consume the requested limit. Strict TTL reads are on by default.
What it does not do
The built-in search does not provide:
- custom analyzers, synonyms, or thesauri;
- stemming or stop words;
- faceting and rich aggregations;
- fuzzy matching inside the text query (use the fuzzy index);
- vector similarity (use a vector index);
- a distributed search cluster;
- Atlas Search/Lucene scoring parity.
There is a small Atlas compatibility subset for $search, $searchMeta, and $vectorSearch, but it is a migration bridge, not full Atlas Search.
When it is enough
Use the built-in text index when:
- the content is already in NonoDB;
- relevance can be BM25 over one field;
- the application needs filters and pagination more than language features;
- one more service is a real operational cost.
Use a dedicated engine when:
- search is the product and needs analyzers, synonyms, facets, and relevance tuning;
- the corpus is large enough that a separate search tier is justified;
- the team already operates Elasticsearch or OpenSearch.
The search guide covers search_all, the Atlas subset, limits, and validation scripts.