Skip to content

fix(search): return plain verbose snippets for text search#355

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

fix(search): return plain verbose snippets for text search#355
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
Johnson-zs:master

Conversation

@Johnson-zs

Copy link
Copy Markdown
Contributor

Use plain snippets for content and OCR verbose output.

为内容和 OCR 的详细输出使用纯文本片段。

Log: 修复详细搜索结果片段输出
Influence: content/ocr 的 -v 输出改为纯文本,并新增 snippetOffset。

Use plain snippets for content and OCR verbose output.

为内容和 OCR 的详细输出使用纯文本片段。

Log: 修复详细搜索结果片段输出
Influence: content/ocr 的 -v 输出改为纯文本,并新增 snippetOffset。

@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分

■ 【总体评价】

代码实现了纯文本摘要提取功能,解决了CLI输出中包含HTML标签的问题,逻辑清晰且安全。
逻辑正确但因存在重复代码扣5分。

■ 【详细分析】

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

代码新增了 PlainSnippetResult 结构体和 plainSnippet 函数,在 contenthighlighter.cpp 中实现了基于最早关键字匹配的纯文本截取逻辑,边界条件处理得当。在 indexedstrategy.cpp 中正确设置了自定义属性,并在输出模块中优先读取该属性。
潜在问题:无
建议:无

  • 2.代码质量(一般)✕

代码命名规范,注释完整,但在 json_output.cpptext_output.cpp 中存在完全相同的辅助函数 plainContentMatchsnippetOffset,违反了 DRY 原则。
潜在问题:重复代码导致后续维护成本增加,若逻辑变更需同步修改多处。
建议:将这两个辅助函数提取到公共工具类或头文件中,供两个输出模块共享。

  • 3.代码性能(良好)✓

plainSnippet 函数中的 findEarliestKeywordMatch 遍历关键字并调用 indexOf,复杂度在可接受范围内。输出模块中回退使用的正则表达式声明为 static const,避免了重复编译开销。
潜在问题:无
建议:无

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

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
代码主要进行字符串处理和属性读写,正则表达式用于清理已知的高亮标签,不存在注入或越权风险。

  • 建议:无

■ 【改进建议代码示例】

// 建议将 json_output.cpp 和 text_output.cpp 中重复的代码提取到公共头文件中
// 例如:src/dfm-search/dfm-search-client/output/output_utils.h

#pragma once

#include <dfm-search/searchresult.h>
#include <QRegularExpression>
#include <QString>

namespace dfmsearch {

inline QString plainContentMatch(const SearchResult &result)
{
    if (result.hasCustomAttribute("plainContentMatch")) {
        return result.customAttribute("plainContentMatch").toString();
    }

    QString content = result.customAttribute("highlightedContent").toString();
    static const QRegularExpression kHtmlTagPattern(QStringLiteral("<[^>]+>"));
    return content.remove(kHtmlTagPattern);
}

inline int snippetOffset(const SearchResult &result)
{
    return result.hasCustomAttribute("snippetOffset")
            ? result.customAttribute("snippetOffset").toInt()
            : -1;
}

} // namespace dfmsearch

// 然后在 json_output.cpp 和 text_output.cpp 中包含该头文件并移除重复定义

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