james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject svn commit: r1688136 - in /james/mailbox/trunk/elasticsearch/src: main/java/org/apache/james/mailbox/elasticsearch/query/CriterionConverter.java test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
Date Mon, 29 Jun 2015 08:37:39 GMT
Author: btellier
Date: Mon Jun 29 08:37:39 2015
New Revision: 1688136

URL: http://svn.apache.org/r1688136
Log:
MAILBOX-234 ElasticSearch project creation - patch contributed by Antoine Duprat

Modified:
    james/mailbox/trunk/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/CriterionConverter.java
    james/mailbox/trunk/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java

Modified: james/mailbox/trunk/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/CriterionConverter.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/CriterionConverter.java?rev=1688136&r1=1688135&r2=1688136&view=diff
==============================================================================
--- james/mailbox/trunk/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/CriterionConverter.java
(original)
+++ james/mailbox/trunk/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/CriterionConverter.java
Mon Jun 29 08:37:39 2015
@@ -60,17 +60,13 @@ public class CriterionConverter {
         registerCriterionConverter(SearchQuery.ConjunctionCriterion.class, this::convertConjunction);
         registerCriterionConverter(SearchQuery.InternalDateCriterion.class, this::convertInternalDate);
         registerCriterionConverter(SearchQuery.HeaderCriterion.class, this::convertHeader);
+        registerCriterionConverter(SearchQuery.TextCriterion.class, this::convertTextCriterion);
         
         registerCriterionConverter(
             SearchQuery.AllCriterion.class, 
             criterion -> FilteredQueryRepresentation.fromQuery(matchAllQuery()));
         
         registerCriterionConverter(
-            SearchQuery.TextCriterion.class,
-            criterion -> FilteredQueryRepresentation.fromQuery(
-                    matchQuery(JsonMessageConstants.TEXT_BODY, criterion.getOperator().getValue())));
-        
-        registerCriterionConverter(
             SearchQuery.ModSeqCriterion.class,
             criterion -> createNumericFilter(JsonMessageConstants.MODSEQ, criterion.getOperator()));
         
@@ -121,6 +117,22 @@ public class CriterionConverter {
         return criterionConverterMap.get(criterion.getClass()).apply(criterion);
     }
 
+
+    private FilteredQueryRepresentation convertTextCriterion(SearchQuery.TextCriterion textCriterion)
{
+        switch (textCriterion.getType()) {
+        case BODY:
+            return FilteredQueryRepresentation.fromQuery(
+                matchQuery(JsonMessageConstants.TEXT_BODY, textCriterion.getOperator().getValue()));
+        case FULL:
+            return FilteredQueryRepresentation.fromQuery(
+                boolQuery()
+                    .should(matchQuery(JsonMessageConstants.TEXT_BODY, textCriterion.getOperator().getValue()))
+                    .should(matchQuery(JsonMessageConstants.ATTACHMENTS + "." + JsonMessageConstants.Attachment.TEXT_CONTENT,
+                        textCriterion.getOperator().getValue())));
+        }
+        throw new RuntimeException("Unknown SCOPE for text criterion");
+    }
+
     private FilteredQueryRepresentation convertInternalDate(SearchQuery.InternalDateCriterion
dateCriterion) {
         SearchQuery.DateOperator dateOperator = dateCriterion.getOperator();
         return dateRangeFilter(JsonMessageConstants.DATE, dateOperator);

Modified: james/mailbox/trunk/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java?rev=1688136&r1=1688135&r2=1688136&view=diff
==============================================================================
--- james/mailbox/trunk/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
(original)
+++ james/mailbox/trunk/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
Mon Jun 29 08:37:39 2015
@@ -512,4 +512,12 @@ public class ElasticSearchIntegrationTes
             .containsOnly(4L, 9L);
     }
 
+    @Test
+    public void mailsContainsShouldIncludeMailHavingAttachmentsMatchingTheRequest() throws
Exception {
+        SearchQuery searchQuery = new SearchQuery();
+        searchQuery.andCriteria(SearchQuery.mailContains("root mailing list"));
+        assertThat(elasticSearchListeningMessageSearchIndex.search(session, mailbox, searchQuery))
+            .containsOnly(1L, 6L);
+    }
+
 }



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