ottoka commented on code in PR #1111:
URL: https://github.com/apache/james-project/pull/1111#discussion_r941152239


##########
mailbox/store/src/main/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndex.java:
##########
@@ -113,6 +114,67 @@ private static UidCriterion 
findConjugatedUidCriterion(List<Criterion> crits) {
         return null;
     }
     
+    /**
+     * Walks down the query tree's conjunctions to find the highest necessary 
mail fetch type.
+     * @param crits - list of Criterion to search from
+     * @return required fetch type - metadata, headers, or full
+     */
+    private static FetchType getFetchTypeForCriteria(List<Criterion> crits) {
+        FetchType maximum = FetchType.METADATA;
+        for (Criterion crit : crits) {
+            if (crit instanceof ConjunctionCriterion) {
+                return getFetchTypeForCriteria(((ConjunctionCriterion) crit)
+                    .getCriteria());
+            } else {
+                maximum = maxFetchType(maximum, 
getFetchTypeForCriterion(crit));
+            }
+        }
+        return maximum;
+    }
+
+    private static FetchType getFetchTypeForCriterion(Criterion crit) {
+        if (crit instanceof SearchQuery.AllCriterion || crit instanceof 
SearchQuery.TextCriterion) {
+            return FetchType.FULL;
+        } else
+        if (crit instanceof SearchQuery.HeaderCriterion || crit instanceof 
SearchQuery.MimeMessageIDCriterion) {
+            return FetchType.HEADERS;
+        } else {
+            return FetchType.METADATA;
+        }
+    }
+
+    /**
+     * Searches a list of query sort options for the highest necessary mail 
fetch type.
+     * @param sorts - list of Sort to search
+     * @return required fetch type - metadata or headers
+     */
+    private static FetchType getFetchTypeForSorts(List<SearchQuery.Sort> 
sorts) {
+        return sorts.stream()
+            .map(SimpleMessageSearchIndex::getFetchTypeForSort)
+            .reduce(FetchType.METADATA, 
SimpleMessageSearchIndex::maxFetchType);
+    }
+
+    private static FetchType getFetchTypeForSort(SearchQuery.Sort sort) {
+        switch (sort.getSortClause()) {
+            case Arrival:
+            case Size:
+            case Uid:
+            case Id:
+                return FetchType.METADATA;
+            case MailboxCc:
+            case MailboxFrom:
+            case MailboxTo:
+            case BaseSubject:
+            case SentDate:
+            default:

Review Comment:
   Makes sense, I will change the default case to throw an 
IllegalArgumentException.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to