fabriziofortino commented on a change in pull request #424:
URL: https://github.com/apache/jackrabbit-oak/pull/424#discussion_r772649309



##########
File path: 
oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/query/ElasticRequestHandler.java
##########
@@ -787,7 +787,28 @@ private static QueryBuilder fullTextQuery(String text, 
String fieldName, PlanRes
             // and could contain other parts like renditions, node name, etc
             return multiMatchQuery.field(fieldName);
         } else {
-            return 
simpleQueryStringQuery(text).field(fieldName).defaultOperator(Operator.AND);
+            // 
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html
+            // simpleQueryStringQuery does not support leading wildcards 
whereas it's supported by default in queryStringQuery
+            // Not using queryStringQuery by default , since some functional 
cases break.
+            // simpleQueryStringQuery is less Strict, for instance searches 
for terms starting with / work, whereas
+            // with queryStringQuery, they throw an Exception (which 
ultimately results in an empty result set in oak),
+            // so using simpleQueryStringQuery by default would break certain 
functional cases.
+            // So only support this in case any term in the text String 
actually starts with *
+            // For example *hello or Hello *world
+            String[] textTerms = text.split(" ");
+            boolean allowLeadingWildCard = false;
+            for(String textTerm : textTerms) {
+                if (textTerm.startsWith("*")) {
+                    allowLeadingWildCard = true;
+                    break;
+                }
+            }

Review comment:
       
   You could use streams to be more concise:
   ```suggestion
               boolean allowLeadingWildCard = Arrays.stream(text.split(" "))
                       .anyMatch(textTerm -> textTerm.startsWith("*"));
   ```




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


Reply via email to