Skip to content

Commit

Permalink
JAMES-1894 ElasticSearch should index MessageId
Browse files Browse the repository at this point in the history
  • Loading branch information
chibenwa committed Jan 9, 2017
1 parent c679556 commit 7a893c4
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 22 deletions.
Expand Up @@ -70,7 +70,11 @@ private static XContentBuilder getMappingContent() {

.startObject(ElasticSearchIndexer.MESSAGE_TYPE)
.startObject(PROPERTIES)
.startObject(JsonMessageConstants.ID)
.startObject(JsonMessageConstants.MESSAGE_ID)
.field(TYPE, STRING)
.field(INDEX, NOT_ANALYZED)
.endObject()
.startObject(JsonMessageConstants.UID)
.field(TYPE, LONG)
.endObject()
.startObject(JsonMessageConstants.MODSEQ)
Expand Down
Expand Up @@ -33,6 +33,7 @@
import org.apache.james.mailbox.elasticsearch.IndexAttachments;
import org.apache.james.mailbox.elasticsearch.query.DateResolutionFormater;
import org.apache.james.mailbox.extractor.TextExtractor;
import org.apache.james.mailbox.model.MessageId;
import org.apache.james.mailbox.store.mail.model.MailboxMessage;
import org.apache.james.mailbox.store.mail.model.Property;
import org.apache.james.mime4j.MimeException;
Expand Down Expand Up @@ -89,7 +90,8 @@ private void copyHeaderFields(HeaderCollection headerCollection, ZonedDateTime i
}

private void copyMessageFields(MailboxMessage message, ZoneId zoneId) {
this.id = message.getUid();
this.messageId = message.getMessageId();
this.uid = message.getUid();
this.mailboxId = message.getMailboxId().serialize();
this.modSeq = message.getModSeq();
this.size = message.getFullContentOctets();
Expand Down Expand Up @@ -127,7 +129,8 @@ private void generateText() {
.collect(Collectors.joining(" "));
}

private MessageUid id;
private MessageId messageId;
private MessageUid uid;
private String mailboxId;
private List<String> users;
private long modSeq;
Expand Down Expand Up @@ -156,9 +159,14 @@ private void generateText() {
private Optional<String> bodyHtml;
private String text;

@JsonProperty(JsonMessageConstants.ID)
public Long getId() {
return id.asLong();
@JsonProperty(JsonMessageConstants.MESSAGE_ID)
public String getId() {
return messageId.serialize();
}

@JsonProperty(JsonMessageConstants.UID)
public Long getUid() {
return uid.asLong();
}

@JsonProperty(JsonMessageConstants.MAILBOX_ID)
Expand Down
Expand Up @@ -24,7 +24,8 @@ public interface JsonMessageConstants {
/*
Properties defined by JMAP
*/
String ID = "id";
String MESSAGE_ID = "messageId";
String UID = "uid";
String MAILBOX_ID = "mailboxId";
String USERS = "users";
String IS_UNREAD = "isUnread";
Expand Down
Expand Up @@ -229,7 +229,7 @@ private BoolQueryBuilder convertUid(SearchQuery.UidCriterion uidCriterion) {
}

private QueryBuilder uidRangeFilter(SearchQuery.UidRange numericRange) {
return rangeQuery(JsonMessageConstants.ID)
return rangeQuery(JsonMessageConstants.UID)
.lte(numericRange.getHighValue().asLong())
.gte(numericRange.getLowValue().asLong());
}
Expand Down
Expand Up @@ -57,15 +57,15 @@ private static FieldSortBuilder getSortClause(SearchQuery.Sort.SortClause clause
case SentDate :
return SortBuilders.fieldSort(JsonMessageConstants.SENT_DATE);
case Uid :
return SortBuilders.fieldSort(JsonMessageConstants.ID);
return SortBuilders.fieldSort(JsonMessageConstants.UID);
case DisplayFrom:
return SortBuilders.fieldSort(JsonMessageConstants.FROM + PATH_SEPARATOR + JsonMessageConstants.EMailer.NAME + PATH_SEPARATOR + NodeMappingFactory.RAW)
.setNestedPath(JsonMessageConstants.FROM);
case DisplayTo:
return SortBuilders.fieldSort(JsonMessageConstants.TO + PATH_SEPARATOR + JsonMessageConstants.EMailer.NAME + PATH_SEPARATOR + NodeMappingFactory.RAW)
.setNestedPath(JsonMessageConstants.TO);
case Id:
return SortBuilders.fieldSort(JsonMessageConstants.ID);
return SortBuilders.fieldSort(JsonMessageConstants.MESSAGE_ID);
default:
throw new RuntimeException("Sort is not implemented");
}
Expand Down
Expand Up @@ -85,7 +85,7 @@ private SearchRequestBuilder getSearchRequestBuilder(Client client, List<User> u
client.prepareSearch(ElasticSearchIndexer.MAILBOX_INDEX)
.setTypes(ElasticSearchIndexer.MESSAGE_TYPE)
.setScroll(TIMEOUT)
.addFields(JsonMessageConstants.ID, JsonMessageConstants.MAILBOX_ID)
.addFields(JsonMessageConstants.UID, JsonMessageConstants.MAILBOX_ID, JsonMessageConstants.MESSAGE_ID)
.setQuery(queryConverter.from(users, query))
.setSize(size),
(searchBuilder, sort) -> searchBuilder.addSort(SortConverter.convertSort(sort)),
Expand All @@ -101,7 +101,7 @@ private Stream<Pair<MailboxId, MessageUid>> transformResponseToUidStream(SearchR

private Optional<Pair<MailboxId, MessageUid>> extractContentFromHit(SearchHit hit) {
SearchHitField mailboxId = hit.field(JsonMessageConstants.MAILBOX_ID);
SearchHitField uid = hit.field(JsonMessageConstants.ID);
SearchHitField uid = hit.field(JsonMessageConstants.UID);
if (mailboxId != null && uid != null) {
Number uidAsNumber = uid.getValue();
return Optional.of(Pair.of(mailboxIdFactory.fromString(mailboxId.getValue()), MessageUid.of(uidAsNumber.longValue())));
Expand Down
Expand Up @@ -35,13 +35,13 @@
import org.apache.commons.io.IOUtils;
import org.apache.james.mailbox.FlagsBuilder;
import org.apache.james.mailbox.MailboxSession.User;
import org.apache.james.mailbox.elasticsearch.IndexAttachments;
import org.apache.james.mailbox.MessageUid;
import org.apache.james.mailbox.elasticsearch.IndexAttachments;
import org.apache.james.mailbox.mock.MockMailboxSession;
import org.apache.james.mailbox.model.MessageId;
import org.apache.james.mailbox.model.TestId;
import org.apache.james.mailbox.model.TestMessageId;
import org.apache.james.mailbox.store.extractor.DefaultTextExtractor;
import org.apache.james.mailbox.store.mail.model.DefaultMessageId;
import org.apache.james.mailbox.store.mail.model.MailboxMessage;
import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
import org.apache.james.mailbox.store.mail.model.impl.SimpleMailboxMessage;
Expand All @@ -58,7 +58,7 @@ public class MailboxMessageToElasticSearchJsonTest {
public static final int SIZE = 25;
public static final int BODY_START_OCTET = 100;
public static final TestId MAILBOX_ID = TestId.of(18L);
public static final MessageId MESSAGE_ID = new DefaultMessageId();
public static final MessageId MESSAGE_ID = TestMessageId.of(184L);
public static final long MOD_SEQ = 42L;
public static final MessageUid UID = MessageUid.of(25);
public static final Charset CHARSET = Charsets.UTF_8;
Expand Down
3 changes: 2 additions & 1 deletion mailbox/store/src/test/resources/eml/htmlMail.json
@@ -1,5 +1,6 @@
{
"id":25,
"id":"184",
"uid":25,
"mailboxId":"18",
"modSeq":42,
"size":25,
Expand Down
3 changes: 2 additions & 1 deletion mailbox/store/src/test/resources/eml/mail.json
@@ -1,5 +1,6 @@
{
"id": 25,
"id":"184",
"uid":25,
"mailboxId": "18",
"modSeq": 42,
"size": 25,
Expand Down
3 changes: 2 additions & 1 deletion mailbox/store/src/test/resources/eml/nonTextual.json
@@ -1,5 +1,6 @@
{
"id": 25,
"id":"184",
"uid":25,
"mailboxId":"18",
"modSeq":42,
"size":25,
Expand Down
3 changes: 2 additions & 1 deletion mailbox/store/src/test/resources/eml/pgpSignedMail.json
@@ -1,5 +1,6 @@
{
"id": 25,
"id":"184",
"uid":25,
"mailboxId": "18",
"modSeq": 42,
"size": 25,
Expand Down
3 changes: 2 additions & 1 deletion mailbox/store/src/test/resources/eml/recursiveMail.json
@@ -1,5 +1,6 @@
{
"id": 25,
"id":"184",
"uid":25,
"mailboxId": "18",
"modSeq": 42,
"size": 25,
Expand Down
@@ -1,5 +1,6 @@
{
"id": 25,
"id":"184",
"uid":25,
"mailboxId": "18",
"modSeq": 42,
"size": 25,
Expand Down
3 changes: 2 additions & 1 deletion mailbox/store/src/test/resources/eml/spamMail.json
@@ -1,5 +1,6 @@
{
"id": 25,
"id":"184",
"uid":25,
"mailboxId": "18",
"modSeq": 42,
"size": 25,
Expand Down

0 comments on commit 7a893c4

Please sign in to comment.