Skip to content

feat: add precise content preview with offset support#343

Merged
deepin-bot[bot] merged 2 commits into
linuxdeepin:masterfrom
Johnson-zs:master
Jul 10, 2026
Merged

feat: add precise content preview with offset support#343
deepin-bot[bot] merged 2 commits into
linuxdeepin:masterfrom
Johnson-zs:master

Conversation

@Johnson-zs

Copy link
Copy Markdown
Contributor
  1. Implement PreviewOptions and PreviewResult classes for precise
    content extraction
  2. Add fetchPreview API to ContentRetriever for offset-based content
    reading
  3. Create previewSnippet utility function in ContentHighlighter
  4. Update CLI client to support offset and precise preview commands
  5. Add comprehensive unit tests for all new functionality
  6. Implement private classes with value semantics using
    QSharedDataPointer

This feature enables applications to:

  • Read content from specific offsets without keyword searching
  • Search content starting from an offset position
  • Get exact content snippets without formatting or simplification
  • See keyword match positions in the source text

Log: Added precise content preview with offset parameter support

Influence:

  1. Test fetchPreview with various offset values (valid and invalid)
  2. Verify keyword searching starting from different offsets
  3. Test edge cases (empty content, negative offsets, offsets beyond
    content length)
  4. Verify output formatting and keyword position reporting
  5. Test concurrent access to the preview functionality
  6. Check CLI interface with new offset parameter

feat: 添加带偏移量的精确内容预览功能

  1. 实现 PreviewOptions 和 PreviewResult 类用于精确内容提取
  2. 在 ContentRetriever 中添加 fetchPreview API 用于基于偏移量的内容读取
  3. 在 ContentHighlighter 中创建 previewSnippet 工具函数
  4. 更新命令行客户端以支持偏移量和精确预览命令
  5. 添加全面的单元测试覆盖新功能
  6. 使用 QSharedDataPointer 实现具有值语义的私有类

该功能使应用程序能够:

  • 从特定偏移量读取内容而无需关键字搜索
  • 从偏移位置开始搜索内容
  • 获取精确内容片段而无需格式化或简化
  • 查看关键字在源文本中的匹配位置

Log: 新增带偏移量参数的内容精确预览功能

Influence:

  1. 测试不同偏移量下的 fetchPreview 功能(有效和无效值)
  2. 验证从不同偏移位置开始的关键字搜索
  3. 测试边界情况(空内容、负偏移量、超出内容长度的偏移量)
  4. 验证输出格式和关键字位置报告
  5. 测试预览功能的并发访问
  6. 检查包含新偏移量参数的命令行接口

1. Implement PreviewOptions and PreviewResult classes for precise
content extraction
2. Add fetchPreview API to ContentRetriever for offset-based content
reading
3. Create previewSnippet utility function in ContentHighlighter
4. Update CLI client to support offset and precise preview commands
5. Add comprehensive unit tests for all new functionality
6. Implement private classes with value semantics using
QSharedDataPointer

This feature enables applications to:
- Read content from specific offsets without keyword searching
- Search content starting from an offset position
- Get exact content snippets without formatting or simplification
- See keyword match positions in the source text

Log: Added precise content preview with offset parameter support

Influence:
1. Test fetchPreview with various offset values (valid and invalid)
2. Verify keyword searching starting from different offsets
3. Test edge cases (empty content, negative offsets, offsets beyond
content length)
4. Verify output formatting and keyword position reporting
5. Test concurrent access to the preview functionality
6. Check CLI interface with new offset parameter

feat: 添加带偏移量的精确内容预览功能

1. 实现 PreviewOptions 和 PreviewResult 类用于精确内容提取
2. 在 ContentRetriever 中添加 fetchPreview API 用于基于偏移量的内容读取
3. 在 ContentHighlighter 中创建 previewSnippet 工具函数
4. 更新命令行客户端以支持偏移量和精确预览命令
5. 添加全面的单元测试覆盖新功能
6. 使用 QSharedDataPointer 实现具有值语义的私有类

该功能使应用程序能够:
- 从特定偏移量读取内容而无需关键字搜索
- 从偏移位置开始搜索内容
- 获取精确内容片段而无需格式化或简化
- 查看关键字在源文本中的匹配位置

Log: 新增带偏移量参数的内容精确预览功能

Influence:
1. 测试不同偏移量下的 fetchPreview 功能(有效和无效值)
2. 验证从不同偏移位置开始的关键字搜索
3. 测试边界情况(空内容、负偏移量、超出内容长度的偏移量)
4. 验证输出格式和关键字位置报告
5. 测试预览功能的并发访问
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

1. Added comprehensive documentation for dfm-searcher command line tool
2. Covers all major features including filename search, content search,
OCR search, semantic search and preview functionality
3. Includes detailed examples for all command options and use cases
4. Provides JSON output structure documentation
5. Contains troubleshooting FAQ section

This documentation serves as a complete reference guide for users and
developers working with dfm-searcher tool. It explains both basic and
advanced usage patterns with clear examples. The document is organized
into three main parts covering search functionality, preview operations,
and reference sections.

Log: Added official documentation for dfm-searcher command line tool

Influence:
1. Verify all example commands work as described
2. Test documentation coverage against actual tool functionality
3. Check formatting and accuracy of JSON output examples
4. Validate troubleshooting advice against real issues

docs: 添加dfm-searcher使用指南文档

1. 添加了dfm-searcher命令行工具的完整文档
2. 涵盖包括文件名搜索、内容搜索、OCR搜索、语义搜索和预览功能等主要特性
3. 提供所有命令选项和使用场景的详细示例
4. 包含JSON输出结构文档
5. 提供故障排除FAQ部分

本文档作为dfm-searcher工具用户和开发者的完整参考指南。通过清晰示例解释基
础和高级使用模式。文档分为三大部分,涵盖搜索功能、预览操作和参考章节。

Log: 新增dfm-searcher命令行工具的官方文档

Influence:
1. 验证所有示例命令是否按描述工作
2. 测试文档覆盖范围与工具实际功能的匹配度
3. 检查JSON输出示例的格式和准确性
4. 验证故障排除建议是否解决实际问题
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:100分

■ 【总体评价】

代码实现了dfm-searcher的preview预览功能,采用Pimpl模式保证ABI稳定性,测试覆盖完善,无安全漏洞
核心逻辑正确,异常处理完善,文档详尽,代码质量优秀,无需扣分

■ 【详细分析】

  • 1.语法逻辑(完全正确)✓

previewSnippet函数(contenthighlighter.cpp)正确处理了空内容、负偏移、零长度等边界条件,无关键词时使用content.mid(offset, maxLength)截取,有关键词时使用indexOf从offset搜索后截取,逻辑清晰
fetchPreview函数(contentretriever.cpp)正确路由Semantic类型,使用QMutexLocker保护索引访问,try-catch捕获LuceneException和std::exception,异常处理完善
CLI层(main.cpp)正确组装PreviewOptions并输出JSON/文本结果,路径解析兼容Qt 5.15前后版本
测试用例(tst_content_retriever.cpp)覆盖了无关键词、有关键词、关键词未找到、offset越界等场景,边界覆盖完整
潜在问题:无
建议:无

  • 2.代码质量(优秀)✓

采用Pimpl模式(PreviewOptionsPrivate、PreviewResultPrivate)保证ABI稳定性,支持隐式共享(QSharedDataPointer)
Doxygen注释完善,包括参数说明、返回值说明、行为描述
命名规范统一,offset/maxLength/keywordOffset语义清晰
新增922行用户文档(dfm-searcher-guide.md),覆盖所有功能场景,包含示例、选项速查表、FAQ
潜在问题:无
建议:无

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

previewSnippet使用QString::mid和indexOf,时间复杂度O(n),无冗余拷贝
fetchPreview使用CachedIndexContext缓存索引上下文,避免重复打开索引
互斥锁粒度适当,仅保护索引访问阶段
潜在问题:无
建议:无

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

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
代码未引入任何安全漏洞,路径输入经过isEmpty检查,CLI选项解析使用QCommandLineParser框架,Lucene索引查询通过API接口调用,无注入风险

  • 建议:无

■ 【改进建议代码示例】

// 代码质量优秀,无需修复,以下为可选的增强建议:
// 在previewSnippet中可增加对offset超过content.length()的显式处理,虽然QString::mid会安全返回空字符串,但显式检查可提升可读性

QString previewSnippet(const QString &content, int offset, int maxLength,
                       const QString &keyword, int *keywordOffset)
{
    if (keywordOffset) {
        *keywordOffset = -1;
    }

    if (content.isEmpty() || maxLength <= 0 || offset < 0 || offset >= content.length()) {
        return {};
    }

    if (keyword.isEmpty()) {
        return content.mid(offset, maxLength);
    }

    int pos = content.indexOf(keyword, offset, Qt::CaseInsensitive);
    if (pos == -1) {
        return {};
    }

    if (keywordOffset) {
        *keywordOffset = pos;
    }

    return content.mid(pos, maxLength);
}

@Johnson-zs

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Jul 10, 2026

Copy link
Copy Markdown

This pr force merged! (status: blocked)

@deepin-bot
deepin-bot Bot merged commit 0412139 into linuxdeepin:master Jul 10, 2026
21 of 23 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