Chapter 8 Text Fuzzy Query

fst provides a fast implementation of ordered sets and maps using finite state machines. It levages memory maps to make range queries, regular expression queries and Levenshtein distance queries very fast.

extern crate fst;
pub use fst::{IntoStreamer, Streamer, Levenshtein, Set};
pub use rustr::rptr::*;


// #[rustr_export]
pub fn new_chunck(x:Vec<String>)-> RResult<RPtr<Set>>{
    
    Ok(RPtr::new(
        Box::new(
            rtry!(Set::from_iter(&x))
            )))
}
// #[rustr_export]
pub fn search_chunck(x : RPtr<Set> ,y:String , distance: u32)-> RResult<Vec<String>>{
    let mut obj = x;
    let lev = rtry!(Levenshtein::new(&y, distance));
    
    let mut stream = {
        rtry!(obj.get())
        .search(lev).into_stream()
        } ;
    
    Ok(rtry!(stream.into_strs()))
    
}
rust(code = '
extern crate fst;
pub use fst::{IntoStreamer, Streamer, Levenshtein, Set};
pub use rustr::rptr::*;


// #[rustr_export]
pub fn new_chunck(x:Vec<String>)-> RResult<RPtr<Set>>{
    
    Ok(RPtr::new(
        Box::new(
            rtry!(Set::from_iter(&x))
            )))
}
// #[rustr_export]
pub fn search_chunck(x : RPtr<Set> ,y:String , distance: u32)-> RResult<Vec<String>>{
    let mut obj = x;
    let lev = rtry!(Levenshtein::new(&y, distance));
    
    let mut stream = {
        rtry!(obj.get())
        .search(lev).into_stream()
        } ;
    
    Ok(rtry!(stream.into_strs()))
    
}
',depend = '
[dependencies]
rustr = "*"
fst = "*"
')
#> updating cached Cargo.toml.

chunck = new_chunck(c("fa", "fo", "fob", "focus", "foo", "food", "foul"))

search_chunck(chunck, "abc", 1)
#> Error in eval(expr, envir, enclos): NotCompatible: expecting a integer

search_chunck(chunck, "abc", 1L)
#> character(0)

search_chunck(chunck, "f", 1L)
#> [1] "fa" "fo"

search_chunck(chunck, "fo", 1L)
#> [1] "fa"  "fo"  "fob" "foo"