From polars sources, I found that
fn build_ac(patterns: &StringChunked, ascii_case_insensitive: bool) -> PolarsResult<AhoCorasick> {
AhoCorasickBuilder::new()
.ascii_case_insensitive(ascii_case_insensitive)
.build(patterns.downcast_iter().flatten().flatten())
.map_err(|e| polars_err!(ComputeError: "could not build aho corasick automaton {}", e))
}
I think they use the default MatchKind::Standard, and this configuration does not fit my case.
My case
let patterns = &["abcd", "abc", "ab"];
let haystack = "asd abcd asd abc asd";
let ac = AhoCorasick::builder()
.ascii_case_insensitive(true)
.match_kind(MatchKind::Standard)
.build(patterns)
.unwrap();
let result = ac.replace_all(&haystack, &["1", "2", "3"]);
println!("{}", result)
Result of MatchKind::Standard asd 3cd asd 3c asd
, and I want the to be asd 1 asd 2 asd
. I need MatchKind::LeftmostFirst or MatchKind::LeftmostLongest for my case. How can I select MatchKind in the replace_many function instead of writing another function and using the map function?