Suggest user accounts by also considering email aliases

Some users may have multiple email accounts, and people who know them
might remember one address more than another.  By offering completion
suggestions using all addresses stored for each account we can help
users to complete to the right identity.

Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
Shawn O. Pearce
2008-12-31 09:20:19 -08:00
parent 00d7a99e3e
commit c76e08c13e
2 changed files with 22 additions and 4 deletions

View File

@@ -33,4 +33,8 @@ public interface AccountExternalIdAccess extends
@Query("WHERE emailAddress = ?") @Query("WHERE emailAddress = ?")
ResultSet<AccountExternalId> byEmailAddress(String email) throws OrmException; ResultSet<AccountExternalId> byEmailAddress(String email) throws OrmException;
@Query("WHERE emailAddress >= ? AND emailAddress <= ? ORDER BY emailAddress LIMIT ?")
ResultSet<AccountExternalId> suggestByEmailAddress(String emailA,
String emailB, int limit) throws OrmException;
} }

View File

@@ -16,6 +16,7 @@ package com.google.gerrit.client.ui;
import com.google.gerrit.client.data.AccountInfo; import com.google.gerrit.client.data.AccountInfo;
import com.google.gerrit.client.reviewdb.Account; import com.google.gerrit.client.reviewdb.Account;
import com.google.gerrit.client.reviewdb.AccountExternalId;
import com.google.gerrit.client.reviewdb.AccountGroup; import com.google.gerrit.client.reviewdb.AccountGroup;
import com.google.gerrit.client.reviewdb.Project; import com.google.gerrit.client.reviewdb.Project;
import com.google.gerrit.client.reviewdb.ReviewDb; import com.google.gerrit.client.reviewdb.ReviewDb;
@@ -25,6 +26,7 @@ import com.google.gwtorm.client.OrmException;
import com.google.gwtorm.client.SchemaFactory; import com.google.gwtorm.client.SchemaFactory;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
public class SuggestServiceImpl extends BaseServiceImplementation implements public class SuggestServiceImpl extends BaseServiceImplementation implements
@@ -60,17 +62,29 @@ public class SuggestServiceImpl extends BaseServiceImplementation implements
final int max = 10; final int max = 10;
final int n = limit <= 0 ? max : Math.min(limit, max); final int n = limit <= 0 ? max : Math.min(limit, max);
final List<AccountInfo> r = new ArrayList<AccountInfo>(); final LinkedHashMap<Account.Id, AccountInfo> r =
new LinkedHashMap<Account.Id, AccountInfo>();
for (final Account p : db.accounts().suggestByFullName(a, b, n)) { for (final Account p : db.accounts().suggestByFullName(a, b, n)) {
r.add(new AccountInfo(p)); r.put(p.getId(), new AccountInfo(p));
} }
if (r.size() < n) { if (r.size() < n) {
for (final Account p : db.accounts().suggestByPreferredEmail(a, b, for (final Account p : db.accounts().suggestByPreferredEmail(a, b,
n - r.size())) { n - r.size())) {
r.add(new AccountInfo(p)); r.put(p.getId(), new AccountInfo(p));
} }
} }
return r; if (r.size() < n) {
for (final AccountExternalId e : db.accountExternalIds()
.suggestByEmailAddress(a, b, n - r.size())) {
if (!r.containsKey(e.getAccountId())) {
final Account p = db.accounts().get(e.getAccountId());
if (p != null) {
r.put(e.getAccountId(), new AccountInfo(p));
}
}
}
}
return new ArrayList<AccountInfo>(r.values());
} }
}); });
} }