feat: 知识库文档列表标题增加「清空」按钮——一键清空全部文档(分块与检索索引级联删除),清空前弹窗警告确认
This commit is contained in:
@@ -250,6 +250,15 @@ pub fn delete_document(db: &Connection, id: &str) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// 清空某知识库的全部文档(分块随外键级联删除,FTS 索引由触发器同步)。
|
||||
pub fn delete_all_documents(db: &Connection, kb_id: &str) -> Result<i64> {
|
||||
let n = db.execute(
|
||||
"DELETE FROM kb_documents WHERE kb_id = ?1",
|
||||
params![kb_id],
|
||||
)?;
|
||||
Ok(n as i64)
|
||||
}
|
||||
|
||||
/// 同一知识库下是否已存在来自该文件路径的文档(目录导入去重)。
|
||||
pub fn document_exists(db: &Connection, kb_id: &str, file_path: &str) -> Result<bool> {
|
||||
if file_path.is_empty() {
|
||||
@@ -608,6 +617,32 @@ mod tests {
|
||||
assert!(hits.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn clear_all_documents_removes_everything() {
|
||||
let conn = test_conn();
|
||||
insert_knowledge_base(
|
||||
&conn,
|
||||
&KnowledgeBase {
|
||||
id: "kb1".to_string(),
|
||||
name: "测试库".to_string(),
|
||||
description: String::new(),
|
||||
chunk_size: 200,
|
||||
chunk_overlap: 20,
|
||||
doc_count: 0,
|
||||
chunk_count: 0,
|
||||
created_at: String::new(),
|
||||
updated_at: String::new(),
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
insert_doc(&conn, "d1", "第一份文档内容,用于清空测试。");
|
||||
insert_doc(&conn, "d2", "第二份文档内容,同样会被清空。");
|
||||
let n = delete_all_documents(&conn, "kb1").unwrap();
|
||||
assert_eq!(n, 2);
|
||||
assert!(list_documents(&conn, "kb1").unwrap().is_empty());
|
||||
assert!(search(&conn, Some("kb1"), "清空", 10, 0).unwrap().is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rechunk_changes_chunk_count() {
|
||||
let conn = test_conn();
|
||||
|
||||
Reference in New Issue
Block a user