Match¶
KeyviMatch represents a single lookup result from a dictionary.
use keyvi::dictionary::Dictionary;
let dict = Dictionary::new("data.kv").unwrap();
let m = dict.get("my_key");
if !m.is_empty() {
println!("key: {}", m.matched_string());
println!("value: {}", m.get_value_as_string());
println!("score: {}", m.get_score());
}
KeyviMatch¶
A single match result from a dictionary lookup.
Implements Into<(String, serde_json::Value)> and Into<(String, serde_json::Value, f64)>
for convenient destructuring.
- KeyviMatch::is_empty(&self) -> bool
Return whether this match is empty (key was not found).
- KeyviMatch::matched_string(&self) -> String
Return the matched key.
- KeyviMatch::get_value(&self) -> serde_json::Value
Return the value as a
serde_json::Value.
- KeyviMatch::get_value_as_string(&self) -> String
Return the value as a JSON string.
- KeyviMatch::get_score(&self) -> f64
Return the match score (e.g. edit distance for fuzzy matches, weight for completions).
- KeyviMatch::get_msgpacked_value(&self) -> Vec<u8>
Return the raw value as a MessagePack-encoded byte vector.
- KeyviMatch::get_msgpacked_value_compressed(&self, compression_algorithm: Compression) -> Vec<u8>
Return the raw value as a compressed MessagePack-encoded byte vector.
Available compression algorithms (from
keyvi::Compression):NO_COMPRESSIONZLIB_COMPRESSIONSNAPPY_COMPRESSIONZSTD_COMPRESSION
KeyviMatchIterator¶
An iterator over match results. Implements the standard Rust Iterator trait
with Item = KeyviMatch.
let dict = Dictionary::new("data.kv").unwrap();
for m in dict.get_prefix_completions("moz", 10) {
println!("{}: {}", m.matched_string(), m.get_value_as_string());
}