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
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 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, rebuilding missing auxiliary structures if needed.
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 aux dictionaries/ngrams.
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.