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


##########
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;
+        }
+    }

Review Comment:
   Oops. I originally copied it from findConjugatedUidCriterion, but then 
envolved it from abbreviated to complete traversal and forgot to adapt it 
accordingly. Nice catch!



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