Skip to main content

InMemoryIndex

Struct InMemoryIndex 

Source
pub struct InMemoryIndex {
    pub indexes: HashMap<String, IndexState>,
    pub position_encoding: PositionEncoding,
    pub dictionary: Option<DictionaryConfig>,
}
Expand description

In-memory inverted index supporting exact, pinyin, and fuzzy search over documents.

Fields§

§indexes: HashMap<String, IndexState>§position_encoding: PositionEncoding§dictionary: Option<DictionaryConfig>

Implementations§

Source§

impl InMemoryIndex

Source

pub fn with_position_encoding(encoding: PositionEncoding) -> Self

Create an index that returns match spans in the given encoding.

Source

pub fn with_dictionary_config(dictionary: DictionaryConfig) -> Self

Create an index that uses a custom dictionary for tokenization.

Source

pub fn set_position_encoding(&mut self, encoding: PositionEncoding)

Set the encoding (bytes or UTF-16) used when returning match spans.

Source

pub fn set_dictionary_config(&mut self, dictionary: Option<DictionaryConfig>)

Swap in or remove a dictionary config for future tokenization.

Source

pub fn add_doc( &mut self, index_name: &str, doc_id: &str, text: &str, index: bool, )

Add or replace a document in an index. Set index to false to stage content without tokenization (doc will exist but not be searchable).

Source

pub fn remove_doc(&mut self, index_name: &str, doc_id: &str)

Remove a document and its postings from an index.

Source

pub fn get_doc(&self, index_name: &str, doc_id: &str) -> Option<String>

Fetch raw document content by id, if present.

Source

pub fn take_dirty_and_deleted( &mut self, ) -> (Vec<(String, String, String, i64)>, HashMap<String, HashSet<String>>)

Return and clear the sets of dirty and deleted docs for persistence.

Source

pub fn has_unpersisted_changes(&self, index_name: Option<&str>) -> bool

Returns true if the index has new changes awaiting persistence. Pass Some(name) to check a specific index or None to check all.

Source

pub fn persist_if_dirty<E>( &mut self, index_name: &str, persist: impl FnMut(SnapshotData) -> Result<(), E>, ) -> Result<bool, E>

Persist the given index only if there are pending changes.

Returns Ok(true) if persistence was attempted (and succeeded), Ok(false) if skipped. The index is marked clean only after the provided callback returns Ok.

Source

pub fn get_matches( &self, index_name: &str, doc_id: &str, query: &str, ) -> Vec<(u32, u32)>

Get byte/UTF-16 spans for a query’s terms within a document by re-tokenizing the query.

Source

pub fn get_matches_for_terms( &self, index_name: &str, doc_id: &str, terms: &[String], ) -> Vec<(u32, u32)>

Get spans for specific terms within a document.

Source

pub fn get_matches_for_matched_terms( &self, index_name: &str, doc_id: &str, terms: &[MatchedTerm], ) -> Vec<(u32, u32)>

Get spans for previously returned matched terms (e.g., from search_hits).

Source

pub fn load_snapshot(&mut self, index_name: &str, snapshot: SnapshotData)

Load a snapshot into an index, expecting all auxiliary structures to be present.

Source

pub fn get_snapshot_data(&self, index_name: &str) -> Option<SnapshotData>

Get a serializable snapshot of the given index, including postings.

Source§

impl InMemoryIndex

Source

pub fn search(&self, index_name: &str, query: &str) -> Vec<(String, f64)>

Execute an auto-mode search and return doc ids with scores.

Source

pub fn search_hits(&self, index_name: &str, query: &str) -> Vec<SearchHit>

Execute an auto-mode search and return full hits including matched terms.

Source

pub fn search_with_mode( &self, index_name: &str, query: &str, mode: SearchMode, ) -> Vec<(String, f64)>

Execute a search in the specified mode and return doc ids with scores.

Source

pub fn search_with_mode_hits( &self, index_name: &str, query: &str, mode: SearchMode, ) -> Vec<SearchHit>

Execute a search in the specified mode and return full hits including matched terms.

Source§

impl InMemoryIndex

Trait Implementations§

Source§

impl Debug for InMemoryIndex

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for InMemoryIndex

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.