@@ -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-
4421bool 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}
0 commit comments