This commit is contained in:
lychang
2026-07-19 18:57:30 +08:00
parent 879598585b
commit 34fdb18919
11 changed files with 2267 additions and 1531 deletions

View File

@@ -269,6 +269,45 @@ pub async fn analyze_groups(db: &Database) -> HashMap<String, Vec<(i64, String,
groups
}
/// 合并结果统计
#[derive(Debug, Clone, Default)]
pub struct MergeResult {
pub groups_analyzed: usize,
pub persons_merged: usize,
pub aliases_moved: usize,
}
/// 执行合并:扫描所有可合并的人物组,合并到相册数最多的那个
/// 返回合并统计
pub async fn execute_merge(db: &Database) -> MergeResult {
let groups = analyze_groups(db).await;
let mut result = MergeResult::default();
result.groups_analyzed = groups.len();
for (_core, items) in &groups {
if items.len() < 2 {
continue;
}
// 第一个(相册数最多)作为目标
let dst_id = items[0].0;
let dst_name = &items[0].1;
// 其余的合并到目标
for (src_id, src_name, _, _) in &items[1..] {
println!("[合并] {} (id={}) → {} (id={})", src_name, src_id, dst_name, dst_id);
db.merge_person_into(*src_id, dst_id).await;
result.persons_merged += 1;
}
}
if result.persons_merged > 0 {
println!("[合并] 完成:分析 {} 组,合并 {} 个人物", result.groups_analyzed, result.persons_merged);
}
result
}
/// 统计匹配分析
#[derive(Debug, Clone)]
pub struct MatchStats {