barrel_ngram_query (barrel_ngram v0.7.1)

View Source

Substring query path: fan across segments, then the confirm pass.

Candidates are gathered from every live segment (gram intersection, or the whole segment for a sub-trigram literal) plus the shard's unfrozen buffer, then de-duplicated by id. Every candidate is confirmed by fetching the current document and running the real substring match on its corpus text, so trigram false positives, stale entries left by an update, and deleted documents (fetched as not_found) are all dropped. Trigram presence is necessary, never sufficient.

The query runs in the calling process against its own immutable read handles, never inside the shard loop.

Summary

Functions

Regex search: turn the regex into a mandatory-trigram query, intersect it over the index (only when the selector indexes every gram), then confirm each candidate with the real regex engine.

Substring search for Literal in Corpus. Fans across the corpus's shards and merges. Each document lives in exactly one shard, so the union needs no cross-shard dedup.

Types

hit/0

-type hit() :: #{id := binary(), spans := [{non_neg_integer(), non_neg_integer()}]}.

Functions

regex_search(Corpus, Regex, Opts)

-spec regex_search(term(), binary(), map()) -> {ok, [hit()]} | {error, term()}.

Regex search: turn the regex into a mandatory-trigram query, intersect it over the index (only when the selector indexes every gram), then confirm each candidate with the real regex engine.

search(Corpus, Literal, Opts)

-spec search(term(), binary(), map()) -> {ok, [hit()]} | {error, term()}.

Substring search for Literal in Corpus. Fans across the corpus's shards and merges. Each document lives in exactly one shard, so the union needs no cross-shard dedup.