Skip to content

fix: filter excluded paths in recent search strategy - #368

Merged
deepin-bot[bot] merged 1 commit into
masterfrom
agent/bugfix/a8ac6989
Jul 24, 2026
Merged

fix: filter excluded paths in recent search strategy#368
deepin-bot[bot] merged 1 commit into
masterfrom
agent/bugfix/a8ac6989

Conversation

@Johnson-zs

@Johnson-zs Johnson-zs commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

根因分析

全局搜索将某目录加入黑名单后,使用智能语义搜索输入"今天打开过文件"仍能搜出黑名单目录下的文件。本 PR 修复 util-dfm(dfm-search 库)侧的缺陷。

dfm-search 的其它子引擎(FileName/Content/OCR)都尊重 searchExcludedPaths(),唯独 RecentSearchStrategy 全文无该引用、search() 只做 keyword/extension/time 过滤。而"今天打开过文件"经 action_rules.json 命中 action_recentrecentOnly=true → 独占走 Recent 子引擎,黑名单目录下的最近使用文件不会被过滤。

关键证据:recentsearchstrategy.cpp 全文无 searchExcludedPaths 引用;对比 realtimestrategy.cpp:81 / indexedstrategy.cpp:728 均消费 excluded paths。

修复方案

RecentSearchStrategy 新增 filterByExcludedPaths 方法,按 m_options.searchExcludedPaths() 过滤黑名单目录下的最近使用项。采用路径边界匹配excludedPathexcludedPath + "/"),并经 QDir::cleanPath 标准化,避免 /home/uos/Downloads 误匹配 /home/uos/Downloads_backup。在 search() 过滤管道中尽早调用(Step 2,keyword 过滤之前)。补充 4 个单元测试:

  • search_excludedPathsFilter_removesBlacklistedItems:黑名单目录下文件被过滤
  • search_excludedPathsFilter_emptyKeepsAllItems:空黑名单保留全部
  • search_excludedPathsCombinedWithKeyword_appliesBoth:黑名单+关键词组合过滤
  • search_excludedPathsFilter_respectsPathBoundary:路径边界匹配,_backup/_archive 不被误过滤

注:本 bug 需与 dde-grand-search 侧修复(语义 worker 调用 setSearchExcludedPaths)同时合入,两层缺一不可。

改动安全评估

低风险。新增 1 个 private 过滤方法 + 在 search() 中调用,不改变任何公开 API 签名;路径边界匹配采用 Qt 标准 QDir::cleanPath + startsWith(excludedPath + '/') 惯用法。单元测试沿用现有 stub-ext + TestableRecentStrategy 测试范式。

关联 PMS:https://pms.uniontech.com/bug-view-371177.html

@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

@Johnson-zs
Johnson-zs force-pushed the agent/bugfix/a8ac6989 branch from 68ab056 to 131e85c Compare July 24, 2026 03:32
1. 为 RecentSearchStrategy 新增 filterByExcludedPaths,按 searchExcludedPaths 过滤黑名单目录下的最近使用文件,与其它子引擎的排除语义对齐;
2. 采用路径边界匹配(excludedPath 或 excludedPath + "/")并经 QDir::cleanPath 标准化,避免 /home/uos/Downloads 误匹配 /home/uos/Downloads_backup;
3. 在 search() 过滤管道中尽早调用黑名单路径过滤;
4. 补充单元测试覆盖黑名单过滤、空黑名单、路径边界匹配及与关键词组合过滤的场景;

=====================================

1. added filterByExcludedPaths to RecentSearchStrategy to filter recently-used files under blacklisted directories via searchExcludedPaths, aligning with the exclusion semantics of other sub-engines;
2. used path-boundary matching (excludedPath or excludedPath + "/") with QDir::cleanPath normalization to avoid /home/uos/Downloads matching /home/uos/Downloads_backup;
3. invoked the excluded-paths filter early in the search() pipeline;
4. added unit tests covering blacklist filtering, empty blacklist, path-boundary matching, and combined keyword plus blacklist filtering;

Log: 修复语义搜索走 Recent 子引擎时未过滤黑名单路径,导致黑名单目录下最近使用文件仍被搜出的问题

Bug: https://pms.uniontech.com/bug-view-371177.html
@Johnson-zs
Johnson-zs force-pushed the agent/bugfix/a8ac6989 branch from 131e85c to 977c883 Compare July 24, 2026 04:08
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:100分

■ 【总体评价】

代码实现了最近使用项的黑名单路径过滤功能,逻辑严谨且测试覆盖全面
路径边界匹配处理正确,无任何安全漏洞,代码质量优秀

■ 【详细分析】

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

在 recentsearchstrategy.cpp 的 filterByExcludedPaths 函数中,通过 QDir::cleanPath 标准化路径,并使用 item.path == excludedPath || item.path.startsWith(excludedPath + QLatin1Char('/')) 进行匹配,正确实现了路径边界过滤,避免了前缀相同但非子目录的误匹配。在 search 函数中,将黑名单过滤置于关键词过滤之前,逻辑顺序合理。
潜在问题:无
建议:无

  • 2.代码质量优秀✓

代码结构清晰,函数职责单一。注释详尽,说明了路径边界匹配的原理和目的。测试用例覆盖了正常过滤、空黑名单、结合关键词以及路径边界匹配等多种场景,测试数据设计合理。
潜在问题:无
建议:无

  • 3.代码性能良好✓

在遍历 items 时使用了 std::as_const 避免不必要的 Qt 隐式共享深拷贝。黑名单过滤前置,有效减少了后续关键词、扩展名和时间范围过滤的数据量。excludedPaths 在函数开始时获取并清理一次,避免了在循环内重复处理。
潜在问题:无
建议:无

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

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
本次修改未引入任何安全漏洞,路径处理使用了安全的 Qt API,不存在路径遍历或注入风险。

  • 建议:无

■ 【改进建议代码示例】

// 代码逻辑已非常完善,无需修改,保持原样即可。

@Johnson-zs

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Jul 24, 2026

Copy link
Copy Markdown

This pr force merged! (status: blocked)

@deepin-bot
deepin-bot Bot merged commit eddf802 into master Jul 24, 2026
31 of 32 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