pub struct TrigramIndex { /* private fields */ }Expand description
The trigram inverted index: maps each trigram to the set of node indices that contain it.
Built once at GroundIndex::build time. Query-side: for each query term, extract its
trigrams, intersect posting lists → candidate set. The candidate set is a superset of
the actual matches (trigrams are necessary but not sufficient); the final contains()
check in the scoring loop filters false positives.
As of D0.6 the indexing side is dormant: GroundIndex::build no longer constructs one
(scoring.rs:48-50 commented out the call site — see Sprint D0.6). Default::default()
gives an empty index for callers that need one; build() is preserved for the D3
re-enable and unit tests that round-trip the original behavior. candidates() is
therefore safe to call only against a populated index; today the scoring loop in
ground_scoped (retrieval.rs:835-841) bypasses it and falls through to the full scan.
Implementations§
Source§impl TrigramIndex
impl TrigramIndex
Sourcepub fn candidates_for_term(&self, term: &str) -> Option<Vec<usize>>
pub fn candidates_for_term(&self, term: &str) -> Option<Vec<usize>>
Find candidate node indices for a query term.
Returns the set of nodes whose haystack CONTAINS all trigrams of term.
This is a superset of nodes whose haystack contains(term) — the scoring loop
does the final contains() check.
For terms shorter than 3 characters (no trigrams), returns None = “scan all” (the fallback — short terms are rare and cheap).
Sourcepub fn candidates(&self, terms: &[String]) -> Option<Vec<usize>>
pub fn candidates(&self, terms: &[String]) -> Option<Vec<usize>>
Find candidate node indices for ALL query terms: the UNION of per-term candidates.
A node is a candidate if ANY query term’s trigrams match (because the scoring loop checks each term independently — a node that matches one term gets a non-zero score).