iword-rs 0.1.11

High-speed keyword search — Rust implementation of iWord
Documentation
use iword::{Dictionary, Mode};

fn main() {
    let dict = Dictionary::builder()
        .add("spam", 2)
        .add("adult_word", 1)
        .add("apple", 9)
        .add("free", 2)
        .build();

    println!("seek(spam)    = {:?}", dict.seek("spam"));
    println!("seek(apple)   = {:?}", dict.seek("apple"));
    println!("seek(notfound)= {:?}", dict.seek("notfound"));

    let text = "get free prize and apple today";
    let matches = dict.scan(text, Mode::HTML | Mode::FORBID);
    println!("\nscan({text:?}):");
    for m in &matches {
        println!("  pos={} len={} key={} word={:?}", m.position, m.length, m.key, m.extract(text));
    }

    let clean = dict.filter("buy spam now", Mode::HTML | Mode::FORBID);
    println!("\nfilter(\"buy spam now\") = {clean:?}");
}