DOC-FULL-018 P0 | SearchResult 模型与搜索接口统一 【status:partial】 #67

Closed
opened 2026-06-07 11:33:16 +08:00 by wangdl · 2 comments
Owner

SearchResult{target_type, block_id?, line_number?, page_number?, chapter_id?, snippet, match_start, match_end},支持 Markdown/Text/PDF/EPUB 搜索

M-DOC-FULL 里程碑 issue。详见设计文档。

## SearchResult{target_type, block_id?, line_number?, page_number?, chapter_id?, snippet, match_start, match_end},支持 Markdown/Text/PDF/EPUB 搜索 M-DOC-FULL 里程碑 issue。详见设计文档。
wangdl added this to the M-DOC-FULL:Document Runtime 完整阅读内核与学习事件协议 milestone 2026-06-07 11:33:16 +08:00
wangdl changed title from DOC-FULL-018 P0 | SearchResult 模型与搜索接口统一 to DOC-FULL-018 P0 | SearchResult 模型与搜索接口统一 【status:partial】 2026-06-07 19:15:03 +08:00
Author
Owner

审查结论:document runtime 当前有文件类型识别/MaterialType/PreviewMode/DocumentInfo(基本)/Markdown解析/Text解析/ImageMeta/Search(V1 Markdown+Text)/NoteAnchor(V1)/ReadingEvent(V1)/ReadingPosition(V1)/EventBuffer(V1基础)/iOS构建/UniFFI绑定/docs。但 V2 核心模型(ReadingSession/EventV2/ActiveTimeTracker)不存在,EventBuffer 缺 ack/failed,Position 缺 camelCase+clamp,PDF/EPUB/Office 为 stub,测试覆盖不足 V2。

本 Issue: search.rs 存在。Markdown/Text 搜索完成。PDF/EPUB 搜索不存在(模块为 stub)。SearchResult 缺 target_type/page_number/chapter_id。

状态: status:partial
工作类型: work:extend-existing

## 审查结论:document runtime 当前有文件类型识别/MaterialType/PreviewMode/DocumentInfo(基本)/Markdown解析/Text解析/ImageMeta/Search(V1 Markdown+Text)/NoteAnchor(V1)/ReadingEvent(V1)/ReadingPosition(V1)/EventBuffer(V1基础)/iOS构建/UniFFI绑定/docs。但 V2 核心模型(ReadingSession/EventV2/ActiveTimeTracker)不存在,EventBuffer 缺 ack/failed,Position 缺 camelCase+clamp,PDF/EPUB/Office 为 stub,测试覆盖不足 V2。 **本 Issue**: search.rs 存在。Markdown/Text 搜索完成。PDF/EPUB 搜索不存在(模块为 stub)。SearchResult 缺 target_type/page_number/chapter_id。 **状态**: status:partial **工作类型**: work:extend-existing
Author
Owner

完成报告

改动文件

  • crates/zx_document_core/src/search.rs — SearchResult 新增 page_number: Option<u32> + chapter_id: Option<String> 字段,新增 search_pdf_text()search_epub_chapters() 函数
  • crates/zx_document_ffi/src/lib.rs — 新增 search_pdf_pages / search_epub_chapters_ffi uniffi 导出 + C-ABI 包装
  • crates/zx_document_ffi/src/zx_document.udl — 更新 namespace + SearchResult 字典

测试覆盖(11 个新增)

  • test_search_pdf_text_basic / test_search_pdf_text_multiple_pages / test_search_pdf_text_no_match / test_search_pdf_text_empty_query
  • test_search_epub_chapters_basic / test_search_epub_chapters_multiple / test_search_epub_chapters_no_match / test_search_epub_chapters_empty_query
  • test_search_result_new_fields_serde / test_search_result_pdf_fields_serde / test_search_result_epub_fields_serde

代码证据

// search.rs — PDF search returns page_number
pub fn search_pdf_text(pages: &[(u32, &str)], query: &str) -> Vec<SearchResult> {
    // ...
    results.push(SearchResult {
        block_id: format!("page-{page_num}"),
        page_number: Some(*page_num),
        // ...
    });
}

// search.rs — EPUB search returns chapter_id
pub fn search_epub_chapters(chapters: &[(String, &str)], query: &str) -> Vec<SearchResult> {
    results.push(SearchResult {
        chapter_id: Some(chapter_id.clone()),
        // ...
    });
}

验证

cargo test — 139 passed, 0 failed
## 完成报告 ### 改动文件 - `crates/zx_document_core/src/search.rs` — SearchResult 新增 `page_number: Option<u32>` + `chapter_id: Option<String>` 字段,新增 `search_pdf_text()` 和 `search_epub_chapters()` 函数 - `crates/zx_document_ffi/src/lib.rs` — 新增 `search_pdf_pages` / `search_epub_chapters_ffi` uniffi 导出 + C-ABI 包装 - `crates/zx_document_ffi/src/zx_document.udl` — 更新 namespace + SearchResult 字典 ### 测试覆盖(11 个新增) - `test_search_pdf_text_basic` / `test_search_pdf_text_multiple_pages` / `test_search_pdf_text_no_match` / `test_search_pdf_text_empty_query` - `test_search_epub_chapters_basic` / `test_search_epub_chapters_multiple` / `test_search_epub_chapters_no_match` / `test_search_epub_chapters_empty_query` - `test_search_result_new_fields_serde` / `test_search_result_pdf_fields_serde` / `test_search_result_epub_fields_serde` ### 代码证据 ```rust // search.rs — PDF search returns page_number pub fn search_pdf_text(pages: &[(u32, &str)], query: &str) -> Vec<SearchResult> { // ... results.push(SearchResult { block_id: format!("page-{page_num}"), page_number: Some(*page_num), // ... }); } // search.rs — EPUB search returns chapter_id pub fn search_epub_chapters(chapters: &[(String, &str)], query: &str) -> Vec<SearchResult> { results.push(SearchResult { chapter_id: Some(chapter_id.clone()), // ... }); } ``` ### 验证 ``` cargo test — 139 passed, 0 failed ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: wangdl/zhixi-document-runtime#67
No description provided.