Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add contains automaton #172

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

hengfeiyang
Copy link

@hengfeiyang hengfeiyang commented Aug 14, 2024

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(())
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant