Skip to content

feat: add character count support for search results#356

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

feat: add character count support for search results#356
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
Johnson-zs:master

Conversation

@Johnson-zs

Copy link
Copy Markdown
Contributor
  1. Added character count tracking for all search result types (Content/
    OCR/Semantic)
  2. Implemented PreviewResult::charCount() to expose the full content
    length
  3. Added TextSearchResultAPI::setCharCount() and charCount() methods
  4. Integrated character count into JSON and text output formats
  5. Added preview output utilities for consistent formatting
  6. Extended test coverage for character count functionality

Log: Added character count display for search preview results

Influence:

  1. Test search preview results with verbose output to verify character
    counts
  2. Check JSON output contains correct charCount fields
  3. Verify text output formatting for character count display
  4. Test boundary cases with empty content and various character sets
  5. Confirm character count matches actual content length in different
    search types

feat: 为搜索结果添加字符计数支持

  1. 为所有搜索结果类型(内容/OCR/语义)添加字符计数跟踪
  2. 实现PreviewResult::charCount()以暴露完整内容长度
  3. 新增TextSearchResultAPI::setCharCount()和charCount()方法
  4. 将字符计数集成到JSON和文本输出格式中
  5. 添加预览输出工具函数以确保格式一致性
  6. 扩展测试覆盖字符计数功能

Log: 为搜索结果预览添加字符计数显示功能

Influence:

  1. 使用详细输出测试搜索结果预览,验证字符计数
  2. 检查JSON输出是否包含正确的charCount字段
  3. 验证文本输出的字符计数显示格式
  4. 测试空内容和各种字符集的边界情况
  5. 确认不同搜索类型下字符计数与实际内容长度匹配

1. Added character count tracking for all search result types (Content/
OCR/Semantic)
2. Implemented PreviewResult::charCount() to expose the full content
length
3. Added TextSearchResultAPI::setCharCount() and charCount() methods
4. Integrated character count into JSON and text output formats
5. Added preview output utilities for consistent formatting
6. Extended test coverage for character count functionality

Log: Added character count display for search preview results

Influence:
1. Test search preview results with verbose output to verify character
counts
2. Check JSON output contains correct charCount fields
3. Verify text output formatting for character count display
4. Test boundary cases with empty content and various character sets
5. Confirm character count matches actual content length in different
search types

feat: 为搜索结果添加字符计数支持

1. 为所有搜索结果类型(内容/OCR/语义)添加字符计数跟踪
2. 实现PreviewResult::charCount()以暴露完整内容长度
3. 新增TextSearchResultAPI::setCharCount()和charCount()方法
4. 将字符计数集成到JSON和文本输出格式中
5. 添加预览输出工具函数以确保格式一致性
6. 扩展测试覆盖字符计数功能

Log: 为搜索结果预览添加字符计数显示功能

Influence:
1. 使用详细输出测试搜索结果预览,验证字符计数
2. 检查JSON输出是否包含正确的charCount字段
3. 验证文本输出的字符计数显示格式
4. 测试空内容和各种字符集的边界情况
5. 确认不同搜索类型下字符计数与实际内容长度匹配

@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.语法逻辑(完全正确)✓

新增的charCount属性在PreviewResultPrivate中初始化为0,在ContentRetriever::fetchPreview、ContentIndexedStrategy::processSearchResults和OcrTextIndexedStrategy::processSearchResults中均正确调用了content.size()进行赋值,存取逻辑一致。TextSearchResultAPI通过customAttribute存取charCount,类型转换正确。单元测试覆盖了各种场景,验证了逻辑的正确性。
潜在问题:无
建议:无

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

提取了preview_output_utils.cpp和preview_output_utils.h,将原本在main.cpp中重复的JSON和文本输出逻辑封装为previewResultToJson和writePreviewResultText,提高了代码复用性和可维护性。命名规范,注释清晰,如明确指出了字符单位与offset/keywordOffset保持一致。
潜在问题:preview_output_utils.cpp中的writePreviewResultText无论content是否为空都会输出Char count,而TextOutput::printSearchResult中使用了if (resultAPI.charCount() > 0)进行条件输出,输出格式在不同模块间存在细微不一致。
建议:统一charCount的输出条件,例如在preview_output_utils中也增加charCount大于0的判断,或者在所有地方都无条件输出以保持一致性。

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

content.size()在Qt中是O(1)时间复杂度的操作,不会对搜索性能产生负面影响。新增的属性存取操作均为简单的哈希表或成员变量访问,性能开销极小。
潜在问题:无
建议:无

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

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
本次变更为内部数据结构的属性新增与输出逻辑重构,不涉及外部输入的直接处理、网络通信或文件系统越权操作,不存在安全风险。

  • 建议:无

■ 【改进建议代码示例】

// src/dfm-search/dfm-search-client/preview_output_utils.cpp
void writePreviewResultText(QTextStream &out, const QString &path, const DFMSEARCH::PreviewResult &result)
{
    out << path << "\n";
    if (!result.content().isEmpty()) {
        out << "  " << result.content() << "\n";
    } else {
        out << "  (no content)\n";
    }
    // 统一输出条件,与 TextOutput::printSearchResult 保持一致
    if (result.charCount() > 0) {
        out << "  Char count: " << result.charCount() << "\n";
    }
    out << Qt::endl;
}

@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 e9c56a7 into linuxdeepin:master Jul 17, 2026
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