pub struct SearchIndex { /* private fields */ }Expand description
In-memory inverted index mapping tokens to weighted (node_id, weight) pairs.
Built from a KnowledgeGraph via SearchIndex::build. Each node contributes
tokens from its label, id, and source_file, each with a different base
weight plus a degree-based boost.
Implementations§
Source§impl SearchIndex
impl SearchIndex
Sourcepub fn build(graph: &KnowledgeGraph) -> Self
pub fn build(graph: &KnowledgeGraph) -> Self
Build the inverted index from a knowledge graph.
Token weights:
- Label token:
2.0 + ln_1p(degree) * 0.1 - Id token:
1.0 + ln_1p(degree) * 0.1 - Source file token:
0.5 + ln_1p(degree) * 0.1
Note: the same token from multiple fields (label + id) stacks additively, rewarding nodes whose token appears in multiple fields.
Sourcepub fn search(&self, terms: &[String]) -> Vec<(f64, String)>
pub fn search(&self, terms: &[String]) -> Vec<(f64, String)>
Search for nodes matching any of the given terms.
Each term is tokenized and matched against the index using exact and prefix matching. Scores are aggregated per node. Results are returned sorted by descending score.
Prefix matches receive half the weight of an exact match.
Auto Trait Implementations§
impl Freeze for SearchIndex
impl RefUnwindSafe for SearchIndex
impl Send for SearchIndex
impl Sync for SearchIndex
impl Unpin for SearchIndex
impl UnsafeUnpin for SearchIndex
impl UnwindSafe for SearchIndex
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more