james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [2/8] james-project git commit: JAMES-2044 Introduce sentDate search API
Date Fri, 02 Jun 2017 12:02:17 GMT
JAMES-2044 Introduce sentDate search API


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

Branch: refs/heads/master
Commit: c24100fc6c868c750e9e0648b28e00902bd4749e
Parents: bea5ac1
Author: Antoine Duprat <aduprat@linagora.com>
Authored: Fri Jun 2 10:54:36 2017 +0200
Committer: Antoine Duprat <aduprat@linagora.com>
Committed: Fri Jun 2 11:01:13 2017 +0200

----------------------------------------------------------------------
 .../apache/james/mailbox/model/SearchQuery.java | 50 ++++++++++++++++++++
 .../elasticsearch/query/CriterionConverter.java |  3 ++
 .../search/LuceneMessageSearchIndexTest.java    | 15 ++++++
 .../search/SimpleMessageSearchIndexTest.java    | 15 ++++++
 .../search/AbstractMessageSearchIndexTest.java  | 30 ++++++++++++
 5 files changed, 113 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/c24100fc/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java
index 2006502..deb3535 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java
@@ -329,6 +329,56 @@ public class SearchQuery implements Serializable {
     }
 
     /**
+     * Creates a filter matching messages with sent date after the given
+     * date.
+     * 
+     * @param date
+     *            given date
+     * @param res
+     *            the date resolution, either {@link DateResolution#Year},
+     *            {@link DateResolution#Month}, {@link DateResolution#Day},
+     *            {@link DateResolution#Hour}, {@link DateResolution#Minute} or
+     *            {@link DateResolution#Second}
+     * @return <code>Criterion</code>, not null
+     */
+    public static Criterion sentDateAfter(Date date, DateResolution res) {
+        return new SentDateCriterion(new DateOperator(DateComparator.AFTER, date, res));
+    }
+
+    /**
+     * Creates a filter matching messages with sent date on the given date.
+     * 
+     * @param date
+     *            given date
+     * @param res
+     *            the date resolution, either {@link DateResolution#Year},
+     *            {@link DateResolution#Month}, {@link DateResolution#Day},
+     *            {@link DateResolution#Hour}, {@link DateResolution#Minute} or
+     *            {@link DateResolution#Second}
+     * @return <code>Criterion</code>, not null
+     */
+    public static Criterion sentDateOn(Date date, DateResolution res) {
+        return new SentDateCriterion(new DateOperator(DateComparator.ON, date, res));
+    }
+
+    /**
+     * Creates a filter matching messages with sent date before the given
+     * date.
+     * 
+     * @param date
+     *            given date
+     * @param res
+     *            the date resolution, either {@link DateResolution#Year},
+     *            {@link DateResolution#Month}, {@link DateResolution#Day},
+     *            {@link DateResolution#Hour}, {@link DateResolution#Minute} or
+     *            {@link DateResolution#Second}
+     * @return <code>Criterion</code>, not null
+     */
+    public static Criterion sentDateBefore(Date date, DateResolution res) {
+        return new SentDateCriterion(new DateOperator(DateComparator.BEFORE, date, res));
+    }
+
+    /**
      * Creates a filter matching messages with the date of the given header
      * after the given date. If the header's value is not a date then it will
      * not be included.

http://git-wip-us.apache.org/repos/asf/james-project/blob/c24100fc/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/CriterionConverter.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/CriterionConverter.java
b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/CriterionConverter.java
index 9e06c87..600c335 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/CriterionConverter.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/CriterionConverter.java
@@ -80,6 +80,9 @@ public class CriterionConverter {
         registerCriterionConverter(SearchQuery.InternalDateCriterion.class,
             criterion -> dateRangeFilter(JsonMessageConstants.DATE, criterion.getOperator()));
 
+        registerCriterionConverter(SearchQuery.SentDateCriterion.class,
+            criterion -> dateRangeFilter(JsonMessageConstants.SENT_DATE, criterion.getOperator()));
+
         registerCriterionConverter(SearchQuery.AttachmentCriterion.class, this::convertAttachmentCriterion);
     }
     

http://git-wip-us.apache.org/repos/asf/james-project/blob/c24100fc/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndexTest.java
----------------------------------------------------------------------
diff --git a/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndexTest.java
b/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndexTest.java
index 541d1d1..8e05fca 100644
--- a/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndexTest.java
+++ b/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndexTest.java
@@ -149,4 +149,19 @@ public class LuceneMessageSearchIndexTest extends AbstractMessageSearchIndexTest
     @Override
     public void multimailboxSearchShouldReturnUidOfMessageMarkedAsSeenInAllMailboxes() throws
MailboxException {
     }
+
+    @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/c24100fc/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 c4403a4..7b0ba58 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
@@ -250,4 +250,19 @@ public class SimpleMessageSearchIndexTest extends AbstractMessageSearchIndexTest
     @Override
     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/c24100fc/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/AbstractMessageSearchIndexTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/AbstractMessageSearchIndexTest.java
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/AbstractMessageSearchIndexTest.java
index 48b2708..85b0026 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/AbstractMessageSearchIndexTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/AbstractMessageSearchIndexTest.java
@@ -623,6 +623,36 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
+    public void sentDateAfterShouldReturnMessagesAfterAGivenDate() throws Exception {
+        SearchQuery searchQuery = new SearchQuery();
+        // Date : 2015/06/04 11:00:00.000 ( Paris time zone )
+        searchQuery.andCriteria(SearchQuery.sentDateAfter(new Date(1433408400000L), SearchQuery.DateResolution.Second));
+        searchQuery.setSorts(Lists.newArrayList(new SearchQuery.Sort(SearchQuery.Sort.SortClause.Arrival,
true)));
+        assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
+            .containsOnly(m3.getUid(), m2.getUid());
+    }
+
+    @Test
+    public void sentDateBeforeShouldReturnMessagesBeforeAGivenDate() throws Exception {
+        SearchQuery searchQuery = new SearchQuery();
+        // Date : 2015/06/01 00:00:00.000 ( Paris time zone )
+        searchQuery.andCriteria(SearchQuery.sentDateBefore(new Date(1433109600000L), SearchQuery.DateResolution.Day));
+        searchQuery.setSorts(Lists.newArrayList(new SearchQuery.Sort(SearchQuery.Sort.SortClause.Arrival,
true)));
+        assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
+            .containsOnly(m5.getUid());
+    }
+
+    @Test
+    public void sentDateOnShouldReturnMessagesOfTheGivenDate() throws Exception {
+        SearchQuery searchQuery = new SearchQuery();
+        // Date : 2015/06/02 08:00:00.000 ( Paris time zone )
+        searchQuery.andCriteria(SearchQuery.sentDateOn(new Date(1433224800000L), SearchQuery.DateResolution.Day));
+        searchQuery.setSorts(Lists.newArrayList(new SearchQuery.Sort(SearchQuery.Sort.SortClause.Arrival,
true)));
+        assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
+            .containsOnly(m4.getUid(), m9.getUid());
+    }
+
+    @Test
     public void modSeqEqualsShouldReturnUidsOfMessageHavingAGivenModSeq() throws Exception
{
         SearchQuery searchQuery = new SearchQuery();
         searchQuery.andCriteria(SearchQuery.modSeqEquals(2L));


---------------------------------------------------------------------
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