Skip to content

feat: enhance preview command with indexed content validation#357

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
Johnson-zs:master
Jul 17, 2026
Merged

feat: enhance preview command with indexed content validation#357
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
Johnson-zs:master

Conversation

@Johnson-zs

Copy link
Copy Markdown
Contributor
  1. Added PreviewStatus enum to distinguish successful (0) and not-
    indexed (1) preview results
  2. Moved preview command logic to separate preview_command module
  3. Added thorough validation for indexed content paths
  4. Improved error reporting for non-indexed paths with detailed messages
  5. Added new test cases for not-indexed preview scenarios
  6. Extended ContentRetriever to return NotIndexed status for invalid
    paths/types

Log: Added validation and error handling for preview command when
accessing non-indexed content

Influence:

  1. Test preview command with paths to non-indexed content
  2. Verify error messages for non-indexed paths
  3. Check behavior with different search types (content/ocr/semantic)
  4. Test preview output formats (JSON/text) with invalid inputs
  5. Verify PreviewStatus values in API responses
  6. Test handling of semantic search routing failures

feat: 增强预览命令的索引内容验证功能

  1. 添加 PreviewStatus 枚举区分成功(0)和未索引(1)的预览结果
  2. 将预览命令逻辑移动到独立的 preview_command 模块
  3. 添加对索引内容路径的全面验证
  4. 为未索引路径改进错误报告,包含详细消息
  5. 新增未索引场景的测试用例
  6. 扩展 ContentRetriever 对无效路径/类型返回 NotIndexed 状态

Log: 新增预览命令访问非索引内容时的验证和错误处理

Influence:

  1. 测试预览命令在访问非索引内容时的行为
  2. 验证非索引路径的错误消息
  3. 检查不同搜索类型(content/ocr/semantic)的行为差异
  4. 测试无效输入时的输出格式(JSON/文本)
  5. 验证 API 响应中的 PreviewStatus 值
  6. 测试语义搜索路由失败时的处理情况

1. Added PreviewStatus enum to distinguish successful (0) and not-
indexed (1) preview results
2. Moved preview command logic to separate preview_command module
3. Added thorough validation for indexed content paths
4. Improved error reporting for non-indexed paths with detailed messages
5. Added new test cases for not-indexed preview scenarios
6. Extended ContentRetriever to return NotIndexed status for invalid
paths/types

Log: Added validation and error handling for preview command when
accessing non-indexed content

Influence:
1. Test preview command with paths to non-indexed content
2. Verify error messages for non-indexed paths
3. Check behavior with different search types (content/ocr/semantic)
4. Test preview output formats (JSON/text) with invalid inputs
5. Verify PreviewStatus values in API responses
6. Test handling of semantic search routing failures

feat: 增强预览命令的索引内容验证功能

1. 添加 PreviewStatus 枚举区分成功(0)和未索引(1)的预览结果
2. 将预览命令逻辑移动到独立的 preview_command 模块
3. 添加对索引内容路径的全面验证
4. 为未索引路径改进错误报告,包含详细消息
5. 新增未索引场景的测试用例
6. 扩展 ContentRetriever 对无效路径/类型返回 NotIndexed 状态

Log: 新增预览命令访问非索引内容时的验证和错误处理

Influence:
1. 测试预览命令在访问非索引内容时的行为
2. 验证非索引路径的错误消息
3. 检查不同搜索类型(content/ocr/semantic)的行为差异
4. 测试无效输入时的输出格式(JSON/文本)
5. 验证 API 响应中的 PreviewStatus 值
6. 测试语义搜索路由失败时的处理情况

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @Johnson-zs, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Johnson-zs

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:95分

■ 【总体评价】

代码重构了预览命令逻辑并修复了空指针解引用问题,增强了错误状态反馈机制
逻辑严谨且修复了潜在崩溃风险,代码结构清晰,因存在少量可优化空间扣5分

■ 【详细分析】

  • 1.语法逻辑(基本正确)✓

contentretriever.cppfetchPreview 函数中,新增了对 doc 空指针的检查(if (!doc)),修复了原代码中可能将空指针传给 storedContentFromDocument 导致的解引用崩溃。各错误分支正确设置了 PreviewStatus::NotIndexed 状态。
潜在问题:preview_command.cppbuildPreviewText 使用了 Qt::endl,但在某些较旧的 Qt 版本中可能不支持,不过代码已通过宏控制了其他部分的 Qt 版本兼容性,此处影响较小。
建议:统一 Qt 版本兼容性处理方式,或使用 "\n" 替代 Qt::endl 以确保跨版本兼容。

  • 2.代码质量(良好)✓

main.cpp 中的预览逻辑重构到 preview_command.cpp,职责分离清晰,符合单一职责原则。新增的 PreviewStatus 枚举和 PreviewCommandResult 结构体设计合理,测试用例覆盖全面。
潜在问题:preview_command.cpp 中的匿名命名空间内函数较多,虽然封装性好,但若未来需要复用这些辅助函数(如 buildPreviewJson),可能需要重新提取。
建议:保持当前结构即可,若后续有复用需求再提取到公共模块。

  • 3.代码性能(高效)✓

fetchPreviewEntries 中使用了 entries.reserve(paths.size()) 预分配内存,减少了动态扩容开销。错误路径收集使用引用指针传递,避免了不必要的拷贝。
潜在问题:无
建议:无需修改

  • 4.代码安全(存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
代码主要处理文件路径和索引检索,未涉及危险的系统调用或外部命令执行。错误信息通过标准错误流输出,未发现敏感信息泄露风险。修复了空指针解引用问题,提升了程序的稳定性。

  • 建议:继续保持当前的安全编码实践,对外部输入的路径进行规范化处理(虽然当前仅用于索引查找,但作为防御性编程的良好习惯)。

■ 【改进建议代码示例】

// src/dfm-search/dfm-search-client/preview_command.cpp
// 建议:使用 "\n" 替代 Qt::endl 以确保更好的跨版本兼容性
 QString buildPreviewText(const QList<PreviewEntry> &entries)
 {
     QString text;
     QTextStream out(&text);
     for (const PreviewEntry &entry : entries) {
         out << entry.path << "\n";
         if (!entry.content.isEmpty()) {
             out << "  " << entry.content << "\n";
         } else {
             out << "  (no content)\n";
         }
         out << "  Char count: " << entry.charCount << "\n";
-        out << Qt::endl;
+        out << "\n";
     }
     return text;
 }

@Johnson-zs

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Jul 17, 2026

Copy link
Copy Markdown

This pr force merged! (status: blocked)

@deepin-bot
deepin-bot Bot merged commit ec364b9 into linuxdeepin:master Jul 17, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants