Use DFA for better performance

Signed-off-by: hr567 <hr567@linux.alibaba.com>
This commit is contained in:
hr567 2024-03-08 16:36:41 +08:00
parent 4e1206a1bb
commit 4d8990d37f
No known key found for this signature in database

View File

@ -10,7 +10,7 @@ use std::sync::{
};
use std::time::Duration;
use aho_corasick::AhoCorasick;
use aho_corasick::{AhoCorasick, AhoCorasickKind, MatchKind};
use clap::Parser;
use dashmap::DashMap;
use indicatif::{ProgressBar, ProgressState, ProgressStyle};
@ -47,7 +47,14 @@ static KEYWORDS: &[&str] = &[
"物联网",
"机器学习",
];
static ANALYZER: Lazy<AhoCorasick> = Lazy::new(|| AhoCorasick::new(KEYWORDS.iter()).unwrap());
static ANALYZER: Lazy<AhoCorasick> = Lazy::new(|| {
AhoCorasick::builder()
.kind(Some(AhoCorasickKind::DFA))
.match_kind(MatchKind::Standard)
.prefilter(true)
.build(KEYWORDS.iter())
.unwrap()
});
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]