From 47d5b5627966b77f91edf91e8582c971fc4d3799 Mon Sep 17 00:00:00 2001 From: Matt Vogt Date: Tue, 24 Sep 2013 10:59:37 +1000 Subject: [PATCH] [libcontacts] Find merge candidates with short form names Also exclude contacts with the wrong gender, if the gender of the match is known. --- src/seasidecache.cpp | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/seasidecache.cpp b/src/seasidecache.cpp index a3f8b0a..24c5978 100644 --- a/src/seasidecache.cpp +++ b/src/seasidecache.cpp @@ -1087,8 +1087,8 @@ static QContactFilter filterForMergeCandidates(const QContact &contact) QContactFilter rv; QContactName name(contact.detail()); - QString firstName(name.firstName()); - QString lastName(name.lastName()); + const QString firstName(name.firstName()); + const QString lastName(name.lastName()); if (firstName.isEmpty() && lastName.isEmpty()) { // Use the displayLabel to match with @@ -1129,6 +1129,15 @@ static QContactFilter filterForMergeCandidates(const QContact &contact) nicknameFilter.setMatchFlags(QContactFilter::MatchContains | QContactFilter::MatchFixedString); nicknameFilter.setValue(firstName); rv = rv | nicknameFilter; + + if (firstName.length() > 3) { + // Also look for shortened forms of this name, such as 'Timothy' => 'Tim' + QContactDetailFilter shortFilter; + setDetailType(shortFilter, QContactName::FieldFirstName); + shortFilter.setMatchFlags(QContactFilter::MatchStartsWith | QContactFilter::MatchFixedString); + shortFilter.setValue(firstName.left(3)); + rv = rv | shortFilter; + } } if (!lastName.isEmpty()) { // Partial match to last name @@ -1184,6 +1193,20 @@ static QContactFilter filterForMergeCandidates(const QContact &contact) rv = rv | filter; } + // If we know the contact gender rule out mismatches + QContactGender gender(contact.detail()); + if (gender.gender() != QContactGender::GenderUnspecified) { + QContactDetailFilter matchFilter; + setDetailType(matchFilter, QContactGender::FieldGender); + matchFilter.setValue(gender.gender()); + + QContactDetailFilter unknownFilter; + setDetailType(unknownFilter, QContactGender::FieldGender); + unknownFilter.setValue(QContactGender::GenderUnspecified); + + rv = rv & (matchFilter | unknownFilter); + } + // Only return aggregate contact IDs return rv & aggregateFilter(); }