InMemoryIndex

Struct InMemoryIndex 

Source
pub struct InMemoryIndex {
    pub versions: HashMap<String, u32>,
    pub docs: HashMap<String, HashMap<String, DocData>>,
    pub domains: HashMap<String, HashMap<TermDomain, DomainIndex>>,
    pub total_lens: HashMap<String, i64>,
    pub domain_total_lens: HashMap<String, DomainLengths>,
    pub dirty: HashMap<String, HashSet<String>>,
    pub deleted: HashMap<String, HashSet<String>>,
    pub position_encoding: PositionEncoding,
    pub dictionary: Option<DictionaryConfig>,
}
Expand description

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

Fields§

§versions: HashMap<String, u32>§docs: HashMap<String, HashMap<String, DocData>>§domains: HashMap<String, HashMap<TermDomain, DomainIndex>>§total_lens: HashMap<String, i64>§domain_total_lens: HashMap<String, DomainLengths>§dirty: HashMap<String, HashSet<String>>§deleted: HashMap<String, HashSet<String>>§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 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, rebuilding missing auxiliary structures if needed.

Source

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

Get a serializable snapshot of the given index, including aux dictionaries/ngrams.

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.

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.