Skip to content

Commit 91647b5

Browse files
wjyrichBLumia
authored andcommitted
Revert "feat: Add fuzzy search support for applications"
This reverts commit 8e2bca7.
1 parent 370a535 commit 91647b5

2 files changed

Lines changed: 5 additions & 27 deletions

File tree

src/models/searchfilterproxymodel.cpp

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,6 @@ SearchFilterProxyModel::SearchFilterProxyModel(QObject *parent)
1818
sort(0, Qt::DescendingOrder);
1919
}
2020

21-
bool SearchFilterProxyModel::fuzzyMatch(const QString &modelData, const QString &pattern) const
22-
{
23-
if (modelData.contains(pattern, Qt::CaseInsensitive)) {
24-
return true;
25-
}
26-
QString processedText = modelData.toLower().simplified();
27-
int textLen = processedText.length();
28-
int patternLen = pattern.length();
29-
std::vector<std::vector<int>> dp(textLen + 1, std::vector<int>(patternLen + 1, 0));
30-
for (int i = 1; i <= textLen; i++) {
31-
for (int j = 1; j <= patternLen; j++) {
32-
if (processedText[i - 1] == pattern[j - 1]) {
33-
dp[i][j] = dp[i - 1][j - 1] + 1;
34-
} else {
35-
dp[i][j] = std::max(dp[i - 1][j], dp[i][j - 1]);
36-
}
37-
}
38-
}
39-
40-
float matchScore = static_cast<float>(dp[textLen][patternLen]) / patternLen;
41-
return matchScore >= m_fuzzyThreshold;
42-
}
43-
4421
bool SearchFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
4522
{
4623
QModelIndex modelIndex = this->sourceModel()->index(sourceRow, 0, sourceParent);
@@ -49,8 +26,11 @@ bool SearchFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &
4926
const QString & displayName = modelIndex.data(Qt::DisplayRole).toString();
5027
const QString & name = modelIndex.data(AppsModel::NameRole).toString();
5128
const QString & transliterated = modelIndex.data(AppsModel::AllTransliteratedRole).toString();
29+
const QString & jianpin = Dtk::Core::firstLetters(displayName).join(',');
5230

53-
QString pattern = searchPattern.pattern().toLower().remove(" ");
31+
auto nameCopy = name;
32+
nameCopy = nameCopy.toLower();
33+
nameCopy.replace(" ", "");
5434

55-
return fuzzyMatch(displayName, pattern) || fuzzyMatch(name, pattern) || fuzzyMatch(transliterated, pattern);
35+
return displayName.contains(searchPattern) || nameCopy.contains(searchPattern) || transliterated.contains(searchPattern) || jianpin.contains(searchPattern);
5636
}

src/models/searchfilterproxymodel.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,4 @@ class SearchFilterProxyModel : public QSortFilterProxyModel
3131
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
3232
private:
3333
explicit SearchFilterProxyModel(QObject *parent = nullptr);
34-
bool fuzzyMatch(const QString &modelData, const QString &pattern) const;
35-
float m_fuzzyThreshold = 0.8f;
3634
};

0 commit comments

Comments
 (0)