推进 OCR UI 与 provider 删除验收

This commit is contained in:
lix-2026
2026-06-01 10:07:42 +08:00
parent 488f9a0937
commit 1481de2018
13 changed files with 548 additions and 55 deletions
@@ -185,6 +185,18 @@ pub(crate) fn refresh_local_search_index_for_path(
index
.resources
.retain(|resource| resource.path != relative_path);
if local_ocr::is_local_ocr_sidecar_relative_path(&relative_path) {
index.built_at = now_ms();
write_local_search_index(root_path, &index)?;
return Ok(json!({
"version": index.version,
"rootUri": index.root_uri,
"workspaceId": index.workspace_id,
"builtAt": index.built_at,
"documentCount": index.documents.len(),
"resourceCount": index.resources.len()
}));
}
let absolute_path = root_path.join(&relative_path);
if absolute_path.exists() && absolute_path.is_file() && is_markdown_path(&absolute_path) {
index
@@ -1168,6 +1180,11 @@ mod tests {
"---\nmnote_ocr_version: 1\nprovider: mock\nmodel_version: vlm\nowner_document: ../Page.md\nsource_path: ./Page.assets/photo.png\nsource_root_relative_path: docs/Page.assets/photo.png\nsource_size: 3\nsource_mtime_ms: 1\nstatus: done\ncreated_at: 1\nupdated_at: 1\n---\n\nOCR-only-token 识别正文\n",
)
.expect("ocr markdown");
fs::write(
root.join("docs").join("Page.ocr").join("photo.png-704905.ocr.md"),
"---\nmnote_ocr_version: 1\nprovider: mock\nmodel_version: vlm\nowner_document: ../Page.md\nsource_path: ./Page.assets/photo.png\nsource_root_relative_path: docs/Page.assets/photo.png\nsource_size: 3\nsource_mtime_ms: 2\nstatus: done\ncreated_at: 2\nupdated_at: 2\n---\n\nOCR-hash-token 识别正文\n",
)
.expect("hashed ocr markdown");
fs::create_dir_all(root.join(".mnote")).expect("mnote dir");
fs::write(
root.join(".mnote").join("ocr-index.json"),
@@ -1208,6 +1225,22 @@ mod tests {
)
.expect("without ocr");
assert_eq!(without_ocr["results"].as_array().map(Vec::len), Some(0));
let without_hashed_ocr = query_local_search_index(
&root,
&root_uri,
workspace_id,
"OCR-hash-token",
None,
10,
false,
false,
false,
)
.expect("without hashed ocr");
assert_eq!(
without_hashed_ocr["results"].as_array().map(Vec::len),
Some(0)
);
let with_ocr = query_local_search_index(
&root,
@@ -1245,6 +1278,24 @@ mod tests {
.documents
.iter()
.any(|document| document.path == "docs/Page.ocr/photo.png.ocr.md"));
assert!(!index
.documents
.iter()
.any(|document| document.path == "docs/Page.ocr/photo.png-704905.ocr.md"));
refresh_local_search_index_for_path(
&root,
&root_uri,
workspace_id,
"docs/Page.ocr/photo.png-704905.ocr.md",
)
.expect("refresh hashed ocr sidecar");
let refreshed_index = read_local_search_index(&root)
.expect("read refreshed search index")
.expect("refreshed search index");
assert!(!refreshed_index
.documents
.iter()
.any(|document| document.path == "docs/Page.ocr/photo.png-704905.ocr.md"));
let _ = fs::remove_dir_all(&root);
}