Skip to content

Commit d7e5566

Browse files
committed
fix: optimize search for pure numbers
If we have numbers entered in the search field, it makes no sense to use the jaro winkler distance, as most numbers contain some of the entered ones in some order. Do a perfect match here, and be more relaxed when the input starts with 0/+.
1 parent 3107665 commit d7e5566

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

src/contacts/Contact.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,15 @@ qreal Contact::matchesSearch(const QString &searchString) const
166166
{
167167
qreal maxDist = 0;
168168

169+
// Phone number
170+
if ((searchString.startsWith("+") && searchString.length() > 4) || (!searchString.startsWith("+") && searchString.length() > 2)) {
171+
for (const auto &phoneNumber : std::as_const(m_phoneNumbers)) {
172+
if (phoneNumber.number.contains(searchString)) {
173+
return 1.0;
174+
}
175+
}
176+
}
177+
169178
// Full name
170179
const auto fullName = m_splittedName.join(' ');
171180
if (searchString.compare(fullName, Qt::CaseSensitivity::CaseInsensitive) == 0) {
@@ -199,15 +208,6 @@ qreal Contact::matchesSearch(const QString &searchString) const
199208
}
200209
}
201210

202-
// Phone number
203-
for (const auto &phoneNumber : std::as_const(m_phoneNumbers)) {
204-
const qreal dist = FuzzyCompare::jaroWinklerDistance(phoneNumber.number, searchString);
205-
maxDist = std::max(dist, maxDist);
206-
if (maxDist == 1.0) {
207-
return maxDist;
208-
}
209-
}
210-
211211
return maxDist;
212212
}
213213

0 commit comments

Comments
 (0)