Return case-preserving email when suggesting reviewers

While Ie82c014e0 introduced case-insensitive by email search for
reviewers, it also introduced a bug by returning the lower-cased email
to the client. In case when an email for an account contained upper-case
letter(s), this account couldn't be added as a reviewer by selecting it
from the suggested list of accounts because its email (as received from
the suggest reviewers REST call) was lowercased and Gerrit couldn't find
such an account when adding the reviewer.

The Ie82c014e0 already stored both original and lowercased email fields
in the index, it just did it in a wrong order. Lucene's
Document.get(fieldName) returns the first value of the field when there
are multiple values.  To fix the issue swap to order of the lower-cased
and original-case values for the EMAIL field in the index.

Change-Id: I4d9025810252641028288d961a1f9e62dd7b8e3e
This commit is contained in:
Saša Živkov
2016-01-18 15:43:17 +01:00
committed by Saša Živkov
parent 7c6ff45137
commit 970f1c9374
2 changed files with 6 additions and 2 deletions

View File

@@ -62,7 +62,7 @@ public class SuggestReviewersIT extends AbstractDaemonTest {
"users1");
user2 = accounts.create("user2", "user2@example.com", "First2 Last2",
"users2");
user3 = accounts.create("user3", "user3@example.com", "First3 Last3",
user3 = accounts.create("user3", "USER3@example.com", "First3 Last3",
"users1", "users2");
}
@@ -207,6 +207,10 @@ public class SuggestReviewersIT extends AbstractDaemonTest {
reviewers = suggestReviewers(changeId, "user1 example", 2);
assertThat(reviewers).hasSize(1);
reviewers = suggestReviewers(changeId, "user3@example.com", 2);
assertThat(reviewers).hasSize(1);
assertThat(reviewers.get(0).account.email).isEqualTo("USER3@example.com");
}
@Test

View File

@@ -172,9 +172,9 @@ public class ReviewerSuggestionCache {
doc.add(new TextField(NAME, a.getFullName(), Store.YES));
}
if (a.getPreferredEmail() != null) {
doc.add(new TextField(EMAIL, a.getPreferredEmail(), Store.YES));
doc.add(new StringField(EMAIL, a.getPreferredEmail().toLowerCase(),
Store.YES));
doc.add(new TextField(EMAIL, a.getPreferredEmail(), Store.YES));
}
AccountExternalIdAccess extIdAccess = db.get().accountExternalIds();
String username = AccountState.getUserName(