Get assignee from ChangeIndex

Change-Id: Ib36dedb430900590cbdc8f444903ebfbd6b7437c
This commit is contained in:
Sven Selberg
2016-09-20 14:37:43 +02:00
parent c2d215858b
commit 72f61c4936
6 changed files with 35 additions and 12 deletions

View File

@@ -24,6 +24,7 @@ import static com.google.gerrit.server.index.change.ChangeField.PROJECT;
import static com.google.gerrit.server.index.change.ChangeIndexRewriter.CLOSED_STATUSES;
import static com.google.gerrit.server.index.change.ChangeIndexRewriter.OPEN_STATUSES;
import com.google.common.base.Optional;
import com.google.common.base.Throwables;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.FluentIterable;
@@ -118,6 +119,7 @@ public class LuceneChangeIndex implements ChangeIndex {
private static final String ADDED_FIELD = ChangeField.ADDED.getName();
private static final String APPROVAL_FIELD = ChangeField.APPROVAL.getName();
private static final String ASSIGNEE_FIELD = ChangeField.ASSIGNEE.getName();
private static final String CHANGE_FIELD = ChangeField.CHANGE.getName();
private static final String DELETED_FIELD = ChangeField.DELETED.getName();
private static final String MERGEABLE_FIELD = ChangeField.MERGEABLE.getName();
@@ -477,6 +479,9 @@ public class LuceneChangeIndex implements ChangeIndex {
if (fields.contains(REVIEWEDBY_FIELD)) {
decodeReviewedBy(doc, cd);
}
if(fields.contains(ASSIGNEE_FIELD)) {
decodeAssignee(doc, cd);
}
if (fields.contains(HASHTAG_FIELD)) {
decodeHashtags(doc, cd);
}
@@ -551,6 +556,18 @@ public class LuceneChangeIndex implements ChangeIndex {
}
}
private void decodeAssignee(Multimap<String, IndexableField> doc, ChangeData cd) {
IndexableField af = Iterables.getFirst(doc.get(ASSIGNEE_FIELD), null);
Account.Id assignee = null;
if (af != null) {
int id = af.numericValue().intValue();
if (id > 0) {
assignee = new Account.Id(id);
}
}
cd.setAssignee(Optional.fromNullable(assignee));
}
private void decodeHashtags(Multimap<String, IndexableField> doc, ChangeData cd) {
Collection<IndexableField> hashtag = doc.get(HASHTAG_FIELD);
Set<String> hashtags = Sets.newHashSetWithExpectedSize(hashtag.size());