Skip to content
This repository has been archived by the owner on Sep 4, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
[libcontacts] Find merge candidates with short form names
Also exclude contacts with the wrong gender, if the gender of the match
is known.
  • Loading branch information
matthewvogt committed Sep 24, 2013
1 parent 498b61f commit 47d5b56
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/seasidecache.cpp
Expand Up @@ -1087,8 +1087,8 @@ static QContactFilter filterForMergeCandidates(const QContact &contact)
QContactFilter rv;

QContactName name(contact.detail<QContactName>());
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
Expand Down Expand Up @@ -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<QContactName>(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
Expand Down Expand Up @@ -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<QContactGender>());
if (gender.gender() != QContactGender::GenderUnspecified) {
QContactDetailFilter matchFilter;
setDetailType<QContactGender>(matchFilter, QContactGender::FieldGender);
matchFilter.setValue(gender.gender());

QContactDetailFilter unknownFilter;
setDetailType<QContactGender>(unknownFilter, QContactGender::FieldGender);
unknownFilter.setValue(QContactGender::GenderUnspecified);

rv = rv & (matchFilter | unknownFilter);
}

// Only return aggregate contact IDs
return rv & aggregateFilter();
}
Expand Down

0 comments on commit 47d5b56

Please sign in to comment.