This commit is contained in:
lychang
2026-07-20 01:36:31 +08:00
parent 5b803cc178
commit 8d2f3361f8

View File

@@ -285,17 +285,23 @@ pub async fn phase_clean_persons(db: &Database) -> (DirtySet, usize) {
/// 这样可以防止停用词(如 "photo"、"model" 等通用词)被错误识别为人物。 /// 这样可以防止停用词(如 "photo"、"model" 等通用词)被错误识别为人物。
pub async fn phase_clean_stop_word_persons(db: &Database) -> (DirtySet, usize) { pub async fn phase_clean_stop_word_persons(db: &Database) -> (DirtySet, usize) {
let persons = db.get_all_persons_with_counts().await; let persons = db.get_all_persons_with_counts().await;
let dict = tag_dict::get_tag_dict();
// 预先复制停用词集合到本地 HashSet,避免持 RwLockReadGuard 穿越 await
let stop_words: HashSet<String> = {
let dict = tag_dict::get_tag_dict();
dict.get_stop_words().clone()
};
let mut dirty = DirtySet::new(); let mut dirty = DirtySet::new();
let mut deleted = 0usize; let mut deleted = 0usize;
for (pid, name, _albums, _images) in &persons { for (pid, name, _albums, _images) in &persons {
// 检查人名本身是否在停用词中 // 检查人名本身是否在停用词中
let in_stop_words = dict.is_stop_word(name) let in_stop_words = stop_words.contains(name)
|| dict.is_stop_word(&name.to_lowercase()); || stop_words.contains(&name.to_lowercase());
// 检查中文核心是否在停用词中(例如 "杨晨晨" 不在,但 "photo" 可能在) // 检查中文核心是否在停用词中
let cn_in_stop_words = title_parser::extract_cn(name) let cn_in_stop_words = title_parser::extract_cn(name)
.map(|cn| dict.is_stop_word(&cn)) .map(|cn| stop_words.contains(&cn))
.unwrap_or(false); .unwrap_or(false);
if in_stop_words || cn_in_stop_words { if in_stop_words || cn_in_stop_words {