feat: Add fuzzy search support for applications#538
Conversation
Reviewer's Guide by SourceryThis pull request introduces fuzzy search functionality for applications. It implements a fuzzy matching algorithm based on the longest common subsequence and uses a threshold to determine the minimum match score required for a successful match. The changes were made in Sequence diagram for fuzzy search in SearchFilterProxyModelsequenceDiagram
participant User
participant SearchFilterProxyModel
participant AppsModel
User->>SearchFilterProxyModel: Types search query
activate SearchFilterProxyModel
SearchFilterProxyModel->>SearchFilterProxyModel: filterAcceptsRow(sourceRow, sourceParent)
activate SearchFilterProxyModel
SearchFilterProxyModel->>AppsModel: displayName = data(Qt::DisplayRole)
activate AppsModel
AppsModel-->>SearchFilterProxyModel: Return displayName
deactivate AppsModel
SearchFilterProxyModel->>AppsModel: name = data(AppsModel::NameRole)
activate AppsModel
AppsModel-->>SearchFilterProxyModel: Return name
deactivate AppsModel
SearchFilterProxyModel->>AppsModel: transliterated = data(AppsModel::AllTransliteratedRole)
activate AppsModel
AppsModel-->>SearchFilterProxyModel: Return transliterated
deactivate AppsModel
SearchFilterProxyModel->>SearchFilterProxyModel: fuzzyMatch(displayName, pattern)
activate SearchFilterProxyModel
SearchFilterProxyModel-->>SearchFilterProxyModel: Return matchResult
deactivate SearchFilterProxyModel
SearchFilterProxyModel->>SearchFilterProxyModel: fuzzyMatch(name, pattern)
activate SearchFilterProxyModel
SearchFilterProxyModel-->>SearchFilterProxyModel: Return matchResult
deactivate SearchFilterProxyModel
SearchFilterProxyModel->>SearchFilterProxyModel: fuzzyMatch(transliterated, pattern)
activate SearchFilterProxyModel
SearchFilterProxyModel-->>SearchFilterProxyModel: Return matchResult
deactivate SearchFilterProxyModel
SearchFilterProxyModel-->>User: Return whether row is accepted
deactivate SearchFilterProxyModel
deactivate SearchFilterProxyModel
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey @wjyrich - I've reviewed your changes - here's some feedback:
Overall Comments:
- Consider extracting the fuzzyMatch lambda to a named method for better readability.
- The fuzzy threshold should be configurable.
Here's what I looked at during the review
- 🟡 General issues: 2 issues found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟡 Complexity: 1 issue found
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| } | ||
| } | ||
|
|
||
| float matchScore = static_cast<float>(dp[textLen][patternLen]) / patternLen; |
There was a problem hiding this comment.
issue (bug_risk): Division by zero risk when the search pattern is empty.
If searchPattern.pattern() yields an empty string, patternLen equals 0 and dividing by it will cause a runtime error. Consider adding a check to handle cases where the pattern is empty before performing the division.
| QString pattern = searchPattern.pattern().toLower().remove(" "); | ||
|
|
||
| // 模糊匹配函数 | ||
| auto fuzzyMatch = [this](const QString & modelData, const QString & pattern) -> bool { |
There was a problem hiding this comment.
suggestion: Consider extracting the fuzzyMatch logic for clarity or reuse.
The inline lambda is defined within filterAcceptsRow and recreated on every call. While this may be acceptable if the data is small, extracting it to a dedicated member function could improve readability and maintainability if similar fuzzy matching is required elsewhere or if the logic evolves further.
add fuzzy search. PMS-BUG-288459
deepin pr auto review关键摘要:
是否建议立即修改: |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: BLumia, wjyrich The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
add fuzzy search.
PMS-BUG-288459
Summary by Sourcery
Implement fuzzy search functionality for application filtering, improving search flexibility and matching accuracy
New Features:
Enhancements: