james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [10/21] james-project git commit: JAMES-2044 SimpleMessageSearchIndex should support searches on sent date
Date Wed, 07 Jun 2017 10:46:20 GMT
JAMES-2044 SimpleMessageSearchIndex should support searches on sent date


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/5aae15d8
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/5aae15d8
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/5aae15d8

Branch: refs/heads/master
Commit: 5aae15d8faef6a00af42adbebc2d0ae7f6500e54
Parents: d256b27
Author: benwa <btellier@linagora.com>
Authored: Mon Jun 5 11:30:45 2017 +0700
Committer: benwa <btellier@linagora.com>
Committed: Wed Jun 7 17:34:32 2017 +0700

----------------------------------------------------------------------
 .../search/SimpleMessageSearchIndexTest.java    | 14 ----
 .../mailbox/store/search/MessageSearches.java   | 69 +++++++++++++-------
 2 files changed, 47 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/5aae15d8/mailbox/scanning-search/src/test/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndexTest.java
----------------------------------------------------------------------
diff --git a/mailbox/scanning-search/src/test/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndexTest.java
b/mailbox/scanning-search/src/test/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndexTest.java
index 7b0ba58..533ac00 100644
--- a/mailbox/scanning-search/src/test/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndexTest.java
+++ b/mailbox/scanning-search/src/test/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndexTest.java
@@ -251,18 +251,4 @@ public class SimpleMessageSearchIndexTest extends AbstractMessageSearchIndexTest
     public void searchWithFullTextShouldReturnMailsWhenHtmlBodyMatchesWithStemming() throws
Exception {
     }
 
-    @Ignore
-    @Override
-    public void sentDateAfterShouldReturnMessagesAfterAGivenDate() throws Exception {
-    }
-
-    @Ignore
-    @Override
-    public void sentDateBeforeShouldReturnMessagesBeforeAGivenDate() throws Exception {
-    }
-
-    @Ignore
-    @Override
-    public void sentDateOnShouldReturnMessagesOfTheGivenDate() throws Exception {
-    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/5aae15d8/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
index 9516717..a58e925 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
@@ -201,6 +201,8 @@ public class MessageSearches implements Iterable<SimpleMessageSearchIndex.Search
             result = matches((SearchQuery.AttachmentCriterion) criterion, message);
         } else if (criterion instanceof SearchQuery.ModSeqCriterion) {
             result = matches((SearchQuery.ModSeqCriterion) criterion, message);
+        } else if (criterion instanceof SearchQuery.SentDateCriterion) {
+            result = matches((SearchQuery.SentDateCriterion) criterion, message);
         } else {
             throw new UnsupportedSearchException();
         }
@@ -586,16 +588,16 @@ public class MessageSearches implements Iterable<SimpleMessageSearchIndex.Search
     private boolean matchesInternalDate(SearchQuery.DateOperator operator, MailboxMessage
message)
             throws UnsupportedSearchException {
         Date date = operator.getDate();
-        DateResolution res = operator.getDateResultion();
+        DateResolution dateResultion = operator.getDateResultion();
         Date internalDate = message.getInternalDate();
         SearchQuery.DateComparator type = operator.getType();
         switch (type) {
         case ON:
-            return on(internalDate, date, res);
+            return on(internalDate, date, dateResultion);
         case BEFORE:
-            return before(internalDate, date, res);
+            return before(internalDate, date, dateResultion);
         case AFTER:
-            return after(internalDate, date, res);
+            return after(internalDate, date, dateResultion);
         default:
             throw new UnsupportedSearchException();
         }
@@ -622,37 +624,60 @@ public class MessageSearches implements Iterable<SimpleMessageSearchIndex.Search
     }
 
     private String createDateString(Date date, DateResolution res) {
-        SimpleDateFormat format;
+        SimpleDateFormat format = createFormat(res);
+        format.setCalendar(getGMT());
+        return format.format(date);
+    }
+
+    private SimpleDateFormat createFormat(DateResolution res) {
         switch (res) {
         case Year:
-            format = new SimpleDateFormat("yyyy");
-            break;
+            return new SimpleDateFormat("yyyy");
         case Month:
-            format = new SimpleDateFormat("yyyyMM");
-            break;
+            return new SimpleDateFormat("yyyyMM");
         case Day:
-            format = new SimpleDateFormat("yyyyMMdd");
-            break;
+            return new SimpleDateFormat("yyyyMMdd");
         case Hour:
-            format = new SimpleDateFormat("yyyyMMddhh");
-            break;
+            return new SimpleDateFormat("yyyyMMddhh");
         case Minute:
-            format = new SimpleDateFormat("yyyyMMddhhmm");
-            break;
+            return new SimpleDateFormat("yyyyMMddhhmm");
         case Second:
-            format = new SimpleDateFormat("yyyyMMddhhmmss");
-            break;
+            return new SimpleDateFormat("yyyyMMddhhmmss");
         default:
-            format = new SimpleDateFormat("yyyyMMddhhmmssSSS");
-
-            break;
+            return new SimpleDateFormat("yyyyMMddhhmmssSSS");
         }
-        format.setCalendar(getGMT());
-        return format.format(date);
     }
 
     private Calendar getGMT() {
         return Calendar.getInstance(TimeZone.getTimeZone("GMT"), Locale.ENGLISH);
     }
 
+    private boolean matches(SearchQuery.SentDateCriterion criterion, MailboxMessage message)
throws MailboxException {
+        SearchQuery.DateOperator operator = criterion.getOperator();
+        try {
+            return matchesSentDate(operator, message);
+        } catch (IOException e) {
+            throw new MailboxException("Can not read header Date", e);
+        } catch (ParseException e) {
+            throw new MailboxException("Can not parse header Date", e);
+        }
+    }
+
+    private boolean matchesSentDate(SearchQuery.DateOperator operator, MailboxMessage message)
throws MailboxException, IOException, ParseException {
+        Date date = operator.getDate();
+        DateResolution dateResolution = operator.getDateResultion();
+        Date sentDate = toISODate(headerValue("Date", message));
+        SearchQuery.DateComparator type = operator.getType();
+        switch (type) {
+            case ON:
+                return on(sentDate, date, dateResolution);
+            case BEFORE:
+                return before(sentDate, date, dateResolution);
+            case AFTER:
+                return after(sentDate, date, dateResolution);
+            default:
+                throw new UnsupportedSearchException();
+        }
+    }
+
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message