Skip to main content

TermIndex

Struct TermIndex 

Source
pub struct TermIndex { /* private fields */ }
Expand description

An inverted index mapping tokenized terms to posting lists (sorted node ID arrays).

Implementations§

Source§

impl TermIndex

Source

pub fn new() -> Self

Create an empty term index.

Source

pub fn build(graph: &MemoryGraph, tokenizer: &Tokenizer) -> Self

Build the index from all node contents in the graph.

Source

pub fn get(&self, term: &str) -> &[(u64, u32)]

Look up a term. Returns (node_id, term_frequency) pairs.

Source

pub fn doc_frequency(&self, term: &str) -> usize

Number of nodes containing a term (document frequency).

Source

pub fn doc_count(&self) -> u64

Total number of indexed documents.

Source

pub fn avg_doc_length(&self) -> f32

Average document length.

Source

pub fn term_count(&self) -> usize

Number of unique terms.

Source

pub fn add_node(&mut self, event: &CognitiveEvent)

Add a single node to the index incrementally.

Source

pub fn remove_node(&mut self, id: u64)

Remove a node from the index.

Source

pub fn clear(&mut self)

Clear the index.

Source

pub fn rebuild(&mut self, graph: &MemoryGraph)

Rebuild the index from a graph.

Source

pub fn to_bytes(&self) -> Vec<u8>

Serialize the term index to bytes for file writing.

Source

pub fn from_bytes(data: &[u8]) -> Option<Self>

Deserialize a term index from bytes.

Trait Implementations§

Source§

impl Default for TermIndex

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.