barrel_ngram_query (barrel_ngram v0.9.0)

View Source

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

A literal's candidates come from three lanes per shard, verified independently and merged: dense (phase-1 intersection, full re-scan confirm), positional (phase-2 distance-checked candidates, windowed confirm via source when configured else folded into dense's fetch-and-rescan), and buffer (the shard's unfrozen buffer, never phase-2 indexed, always full-content confirm). A key with a dense-sourced candidacy is dropped from the positional lane -- dense's re-scan already covers it.

A key present in the buffer snapshot (live or tombstoned) is authoritative over any segment occurrence of the same key, dropped from both segment lanes before verification.

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, then confirm each candidate with the real regex engine. An eligible AND-chain pattern (see barrel_ngram_planner:regex_plan/2) also gets windowed verification via source when configured.

Substring search for Literal in Corpus. Fans across the corpus's shards and merges (no cross-shard dedup needed -- each document lives in exactly one shard).

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, then confirm each candidate with the real regex engine. An eligible AND-chain pattern (see barrel_ngram_planner:regex_plan/2) also gets windowed verification via source when configured.

Opts may carry case_sensitive => false (default true); a pattern with its own leading (?i) is caseless regardless of Opts. Either way, case-insensitive regex search never narrows or windows -- see barrel_ngram_planner's moduledoc.

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 (no cross-shard dedup needed -- each document lives in exactly one shard).

Opts may carry case_sensitive => false (default true); see barrel_ngram_planner's moduledoc for what that changes.