Expand description
Ngram-based indexing of strings into a binary file.
This library can be used to index lots of strings into a file (identified by a numeric ID), and then perform a fuzzy search over those strings.
Example:
// Build index
let mut builder = Ngrams::builder();
builder.add("spam", 0);
builder.add("ham", 1);
builder.add("mam", 2);
// Write it to a file
let mut file = BufWriter::new(File::create(path).unwrap());
builder.write(&mut file).unwrap();
// Search our index
let mut data = Ngrams::open(path).unwrap();
assert_eq!(
data.search("ham", 0.24).unwrap(),
vec![
(1, 1.0), // "ham" is an exact match
(2, 0.25), // "mam" is close
],
);
assert_eq!(
data.search("spa", 0.2).unwrap(),
vec![
(0, 0.22222222), // "spam" is close
],
);
Structsยง
- Ngrams
- Ngrams index of strings backed by a file.
- Ngrams
Builder - A builder object used to build the index file.