Skip to content

feat: Add fuzzy search support for applications#538

Merged
BLumia merged 1 commit into
linuxdeepin:masterfrom
wjyrich:fix-bug-288459
May 6, 2025
Merged

feat: Add fuzzy search support for applications#538
BLumia merged 1 commit into
linuxdeepin:masterfrom
wjyrich:fix-bug-288459

Conversation

@wjyrich
Copy link
Copy Markdown
Contributor

@wjyrich wjyrich commented Apr 18, 2025

add fuzzy search.

PMS-BUG-288459

Summary by Sourcery

Implement fuzzy search functionality for application filtering, improving search flexibility and matching accuracy

New Features:

  • Add advanced fuzzy matching algorithm to search through application names, display names, and transliterated names

Enhancements:

  • Improve search matching by introducing a dynamic scoring mechanism that allows partial and flexible text matching
  • Implement a configurable fuzzy matching threshold to control search sensitivity

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Apr 18, 2025

Reviewer's Guide by Sourcery

This 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 src/models/searchfilterproxymodel.cpp and src/models/searchfilterproxymodel.h.

Sequence diagram for fuzzy search in SearchFilterProxyModel

sequenceDiagram
    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
Loading

File-Level Changes

Change Details Files
Implemented fuzzy search functionality to enhance application search capabilities.
  • Added a fuzzyMatch function to perform fuzzy matching between the model data and the search pattern.
  • The fuzzyMatch function calculates a match score based on the longest common subsequence between the processed text and the pattern.
  • A m_fuzzyThreshold variable was added to control the minimum match score required for a successful fuzzy match.
  • The filterAcceptsRow function now uses the fuzzyMatch function to determine if a row should be accepted based on the display name, name, and transliterated values.
  • The search pattern is preprocessed by converting it to lowercase and removing spaces.
src/models/searchfilterproxymodel.cpp
src/models/searchfilterproxymodel.h

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/models/searchfilterproxymodel.cpp Outdated
}
}

float matchScore = static_cast<float>(dp[textLen][patternLen]) / patternLen;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/models/searchfilterproxymodel.cpp Outdated
QString pattern = searchPattern.pattern().toLower().remove(" ");

// 模糊匹配函数
auto fuzzyMatch = [this](const QString & modelData, const QString & pattern) -> bool {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/models/searchfilterproxymodel.cpp
Comment thread src/models/searchfilterproxymodel.cpp Outdated
Comment thread src/models/searchfilterproxymodel.cpp Outdated
Comment thread src/models/searchfilterproxymodel.cpp
add fuzzy search.

PMS-BUG-288459
@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

关键摘要:

  • fuzzyMatch 函数中使用了动态规划算法来计算模糊匹配的得分,这是一个合理的做法,但需要确保算法的正确性和效率。
  • fuzzyMatch 函数中的 m_fuzzyThreshold 应该在类的构造函数中进行初始化,而不是在头文件中直接赋值。
  • filterAcceptsRow 函数中移除了对 jianpin 的检查,如果这是有意为之,需要确认这一改动是否符合预期。
  • fuzzyMatch 函数的命名不够直观,建议使用更具描述性的名称,如 calculateFuzzyMatchScore

是否建议立即修改:

@deepin-ci-robot
Copy link
Copy Markdown

[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.

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

@BLumia BLumia merged commit 0e9e9fd into linuxdeepin:master May 6, 2025
2 of 3 checks passed
@wjyrich wjyrich deleted the fix-bug-288459 branch June 6, 2025 00:36
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.

3 participants