This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git


The following commit(s) were added to refs/heads/master by this push:
     new c03d2fe9d5 JAMES-4057 Use Query string only when control character are 
used (#2730)
c03d2fe9d5 is described below

commit c03d2fe9d5e3ebbd229299965d13a601831adf06
Author: Benoit TELLIER <[email protected]>
AuthorDate: Tue May 27 17:22:11 2025 +0200

    JAMES-4057 Use Query string only when control character are used (#2730)
---
 .../apache/james/mailbox/opensearch/query/CriterionConverter.java | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git 
a/mailbox/opensearch/src/main/java/org/apache/james/mailbox/opensearch/query/CriterionConverter.java
 
b/mailbox/opensearch/src/main/java/org/apache/james/mailbox/opensearch/query/CriterionConverter.java
index a85a1c050b..2c12932330 100644
--- 
a/mailbox/opensearch/src/main/java/org/apache/james/mailbox/opensearch/query/CriterionConverter.java
+++ 
b/mailbox/opensearch/src/main/java/org/apache/james/mailbox/opensearch/query/CriterionConverter.java
@@ -55,10 +55,12 @@ import 
org.opensearch.client.opensearch._types.query_dsl.SimpleQueryStringQuery;
 import org.opensearch.client.opensearch._types.query_dsl.TermQuery;
 
 import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.CharMatcher;
 import com.google.common.collect.ImmutableList;
 
 public class CriterionConverter {
 
+    public static final CharMatcher QUERY_STRING_CONTROL_CHAR = 
CharMatcher.anyOf("()\"~-|*");
     private final Map<Class<?>, Function<Criterion, Query>> 
criterionConverterMap;
     private final Map<Class<?>, BiFunction<String, HeaderOperator, Query>> 
headerOperatorConverterMap;
     private final String textFuzzinessSearchValue;
@@ -224,7 +226,7 @@ public class CriterionConverter {
     private Query convertTextCriterion(SearchQuery.TextCriterion 
textCriterion) {
         switch (textCriterion.getType()) {
         case BODY:
-            if (useQueryStringQuery) {
+            if (useQueryStringQuery && 
QUERY_STRING_CONTROL_CHAR.matchesAnyOf(textCriterion.getOperator().getValue())) 
{
                 return new SimpleQueryStringQuery.Builder()
                     .fields(ImmutableList.of(JsonMessageConstants.TEXT_BODY, 
JsonMessageConstants.HTML_BODY))
                     .query(textCriterion.getOperator().getValue())
@@ -249,7 +251,7 @@ public class CriterionConverter {
                     .toQuery();
             }
         case FULL:
-            if (useQueryStringQuery) {
+            if (useQueryStringQuery && 
QUERY_STRING_CONTROL_CHAR.matchesAnyOf(textCriterion.getOperator().getValue())) 
{
                 return new SimpleQueryStringQuery.Builder()
                     .fields(ImmutableList.of(JsonMessageConstants.TEXT_BODY, 
JsonMessageConstants.HTML_BODY, JsonMessageConstants.ATTACHMENTS + "." + 
JsonMessageConstants.Attachment.TEXT_CONTENT))
                     .query(textCriterion.getOperator().getValue())
@@ -493,7 +495,7 @@ public class CriterionConverter {
     }
 
     private Query convertSubject(SearchQuery.SubjectCriterion headerCriterion) 
{
-        if (useQueryStringQuery) {
+        if (useQueryStringQuery && 
QUERY_STRING_CONTROL_CHAR.matchesAnyOf(headerCriterion.getSubject())) {
             return new QueryStringQuery.Builder()
                 .fields(ImmutableList.of(JsonMessageConstants.SUBJECT))
                 .query(headerCriterion.getSubject())


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

Reply via email to