Expand description
Unicode-aware Aho–Corasick automaton with fuzzy matching: substitutions, insertions, deletions, and transpositions, over grapheme clusters, with optional case-insensitive folding.
Build an immutable engine with FuzzyAhoCorasickBuilder, then query it. Similarity for a
candidate match against a length-N pattern is (N - penalties) / N * weight, and a match is
kept when it meets the caller’s threshold. Edit limits can be set globally on the builder or
per Pattern, and edit costs are tuned via FuzzyPenalties.
§Example
use fuzzy_aho_corasick::{FuzzyAhoCorasickBuilder, FuzzyLimits, SearchOptions};
let engine = FuzzyAhoCorasickBuilder::new()
.fuzzy(FuzzyLimits::new().edits(1))
.case_insensitive(true)
.build(["hello", "world"]);
// Two typos: an extra 'l' (insertion) and swapped 'lr' (transposition).
let matches = engine.search("helllo wolrd", &SearchOptions::new().threshold(0.8).sorted().non_overlapping()).unwrap();
let found: Vec<&str> = matches.iter().map(|m| m.pattern.as_str()).collect();
assert!(found.contains(&"hello") && found.contains(&"world"));§Bounding worst-case work
The search is exact by default. When a high edit budget is combined with a low threshold the
state space can explode; FuzzyAhoCorasickBuilder::beam_width caps the active frontier, and
FuzzyAhoCorasickBuilder::auto_beam stays exact until a state budget is exceeded and only
then engages a beam — leaving ordinary searches unaffected.
§Bit-parallel pre-filter
For large, mostly-non-matching inputs, FuzzyAhoCorasick::with_prefilter returns a
Prefiltered wrapper that runs a bit-parallel approximate scan to locate candidate regions and
only re-searches those with the full engine. Results are identical to FuzzyAhoCorasick::search;
it falls back to a plain full search when the configuration can’t be reduced to the bit model.
See the README for a full guide.
Re-exports§
pub use structs::*;
Modules§
- structs
- The crate’s public data types (patterns, limits, penalties, matches, segments, …). Everything
here is also re-exported at the crate root, so
use fuzzy_aho_corasick::Patternanduse fuzzy_aho_corasick::structs::Patternare equivalent.
Structs§
- Fuzzy
AhoCorasick Builder - Builder for
FuzzyAhoCorasick. - Fuzzy
Replacer - A turnkey fuzzy find-and-replace built from
(pattern → replacement)pairs. - Prefiltered
- A
FuzzyAhoCorasickwrapped with an optional bit-parallel pre-filter. - Search
Options - Configuration for a search: the similarity
threshold, the rankingorder, and theoverlapresolution. Construct withSearchOptions::new(all defaults) and refine with the chainable setters; or build one literally. - Stream
Match - A match found by the streaming API, with absolute byte offsets into the whole stream.
- Stream
Matches - Iterator returned by
FuzzyAhoCorasick::stream_matches.
Enums§
- Order
- How the raw matches are ranked before they’re returned (and before overlap resolution).
- Overlap
- How overlapping matches are resolved after ranking.
- Search
Error - An error from a search call.
Constants§
- DEFAULT_
THRESHOLD - Default similarity threshold used when
SearchOptionsdoesn’t set one.0.0keeps every match the configured edit limits allow — the limits are the real quality gate, so an unset threshold adds no extra similarity filter. SetSearchOptions::thresholdto filter more aggressively.
Type Aliases§
- Pattern
Index - Index of a pattern within the automaton’s pattern list — the
pattern_indexon aFuzzyMatch, and the position of a pattern in the slice passed tobuild.