From 21c98b9f04586064671ac39cd28113b914983b9e Mon Sep 17 00:00:00 2001 From: Roland Pallai Date: Fri, 2 Feb 2018 16:29:34 +0100 Subject: [PATCH] =?utf8?q?Akonadi=20abook:=20do=20not=20filter=20out=20ema?= =?utf8?q?il=20addresses=20with=20odd=20=E2=80=98logic=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit There is an odd logic that "tries to sort out irrelevant email addresses" such way that filters out non-matching email addresses if the search condition matched on one or more. The goal is to make search by email address more comfortable. But this behaviour quietly and unfairly prefers matching by email address over contact name as Erik Quaeghebeur pointed out on Trojitá mailing list: "For example, one contact of mine has 4 addresses. The search result is effectively unique after entering the first four characters of their first name. However, because this first name only appears in one address, only that address is returned. I need to type the full first name and a space to override the logic and trigger true search-by-contact-name." So this patch introduces a fairer logic which puts the matching email addresses first and then the rest - without filtering. Change-Id: I16b8f74a672c9864d9da994ac90d7bf9738f6001 --- .../AkonadiAddressbook/AkonadiAddressbookCompletionJob.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Plugins/AkonadiAddressbook/AkonadiAddressbookCompletionJob.cpp b/src/Plugins/AkonadiAddressbook/AkonadiAddressbookCompletionJob.cpp index 6f98c5a4..6c6765f2 100644 --- a/src/Plugins/AkonadiAddressbook/AkonadiAddressbookCompletionJob.cpp +++ b/src/Plugins/AkonadiAddressbook/AkonadiAddressbookCompletionJob.cpp @@ -67,12 +67,11 @@ void AkonadiAddressbookCompletionJob::searchResult(KJob *job) for (int i = 0; i < contacts.size() && (m_max == -1 || list.size() < m_max); ++i) { KContacts::Addressee contact = contacts[i]; - // Trying to sort out irrelevant email addresses. Although this is not perfect. - QStringList emails = contact.emails().filter(m_input, Qt::CaseInsensitive); - if (emails.size() == 0) - emails = contact.emails(); + // put the matching ones first and then the rest + QStringList emails1 = contact.emails().filter(m_input, Qt::CaseInsensitive); + QStringList emails2 = contact.emails().toSet().subtract(emails1.toSet()).toList(); - Q_FOREACH(const QString &email, emails) { + Q_FOREACH(const QString &email, emails1 + emails2) { if (!m_ignores.contains(email)) { list << NameEmail(contact.realName(), email); if (m_max != -1 && list.size() >= m_max) -- 2.11.4.GIT