Use DFA for better performance
Signed-off-by: hr567 <hr567@linux.alibaba.com>
This commit is contained in:
parent
4e1206a1bb
commit
4d8990d37f
11
src/main.rs
11
src/main.rs
@ -10,7 +10,7 @@ use std::sync::{
|
|||||||
};
|
};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use aho_corasick::AhoCorasick;
|
use aho_corasick::{AhoCorasick, AhoCorasickKind, MatchKind};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use dashmap::DashMap;
|
use dashmap::DashMap;
|
||||||
use indicatif::{ProgressBar, ProgressState, ProgressStyle};
|
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)]
|
#[derive(Parser, Debug)]
|
||||||
#[command(version, about, long_about = None)]
|
#[command(version, about, long_about = None)]
|
||||||
|
Loading…
Reference in New Issue
Block a user