BurntSushi / fst

Represent large sets and maps compactly with finite state transducers.
The Unlicense
1.76k stars 123 forks source link

feat: add contains automaton #172

Open hengfeiyang opened 1 month ago

hengfeiyang commented 1 month ago

I added a contains automaton, then you can search keyword contains in some terms.

use fst::{automaton::Contains, IntoStreamer, Set};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let paths = vec!["a foo bar", "foo", "foo1", "foo12", "foo3", "foobar"];
    let set = Set::from_iter(paths)?;

    // Build our contains query.
    let prefix = Contains::new("foob");

    // Apply our query to the set we built.
    let stream = set.search(&prefix).into_stream();

    let matches = stream.into_strs()?;
    println!("{:?}", matches);
    // ["foobar"]
    Ok(())
}