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
impl InMemoryIndex
Sourcepub fn with_position_encoding(encoding: PositionEncoding) -> Self
pub fn with_position_encoding(encoding: PositionEncoding) -> Self
Create an index that returns match spans in the given encoding.
Sourcepub fn with_dictionary_config(dictionary: DictionaryConfig) -> Self
pub fn with_dictionary_config(dictionary: DictionaryConfig) -> Self
Create an index that uses a custom dictionary for tokenization.
Sourcepub fn set_position_encoding(&mut self, encoding: PositionEncoding)
pub fn set_position_encoding(&mut self, encoding: PositionEncoding)
Set the encoding (bytes or UTF-16) used when returning match spans.
Sourcepub fn set_dictionary_config(&mut self, dictionary: Option<DictionaryConfig>)
pub fn set_dictionary_config(&mut self, dictionary: Option<DictionaryConfig>)
Swap in or remove a dictionary config for future tokenization.
Sourcepub fn add_doc(
&mut self,
index_name: &str,
doc_id: &str,
text: &str,
index: bool,
)
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).
Sourcepub fn remove_doc(&mut self, index_name: &str, doc_id: &str)
pub fn remove_doc(&mut self, index_name: &str, doc_id: &str)
Remove a document and its postings from an index.
Sourcepub fn get_doc(&self, index_name: &str, doc_id: &str) -> Option<String>
pub fn get_doc(&self, index_name: &str, doc_id: &str) -> Option<String>
Fetch raw document content by id, if present.
Sourcepub fn take_dirty_and_deleted(
&mut self,
) -> (Vec<(String, String, String, i64)>, HashMap<String, HashSet<String>>)
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.
Sourcepub fn has_unpersisted_changes(&self, index_name: Option<&str>) -> bool
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.
Sourcepub fn persist_if_dirty<E>(
&mut self,
index_name: &str,
persist: impl FnMut(SnapshotData) -> Result<(), E>,
) -> Result<bool, E>
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.
Sourcepub fn get_matches(
&self,
index_name: &str,
doc_id: &str,
query: &str,
) -> Vec<(u32, u32)>
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.
Sourcepub fn get_matches_for_terms(
&self,
index_name: &str,
doc_id: &str,
terms: &[String],
) -> Vec<(u32, u32)>
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.
Sourcepub fn get_matches_for_matched_terms(
&self,
index_name: &str,
doc_id: &str,
terms: &[MatchedTerm],
) -> Vec<(u32, u32)>
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).
Sourcepub fn load_snapshot(&mut self, index_name: &str, snapshot: SnapshotData)
pub fn load_snapshot(&mut self, index_name: &str, snapshot: SnapshotData)
Load a snapshot into an index, expecting all auxiliary structures to be present.
Sourcepub fn get_snapshot_data(&self, index_name: &str) -> Option<SnapshotData>
pub fn get_snapshot_data(&self, index_name: &str) -> Option<SnapshotData>
Get a serializable snapshot of the given index, including postings.
Source§impl InMemoryIndex
impl InMemoryIndex
Sourcepub fn search(&self, index_name: &str, query: &str) -> Vec<(String, f64)>
pub fn search(&self, index_name: &str, query: &str) -> Vec<(String, f64)>
Execute an auto-mode search and return doc ids with scores.
Sourcepub fn search_hits(&self, index_name: &str, query: &str) -> Vec<SearchHit>
pub fn search_hits(&self, index_name: &str, query: &str) -> Vec<SearchHit>
Execute an auto-mode search and return full hits including matched terms.
Sourcepub fn search_with_mode(
&self,
index_name: &str,
query: &str,
mode: SearchMode,
) -> Vec<(String, f64)>
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.
Sourcepub fn search_with_mode_hits(
&self,
index_name: &str,
query: &str,
mode: SearchMode,
) -> Vec<SearchHit>
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.