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



##########
File path: 
oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/query/ElasticRequestHandler.java
##########
@@ -787,7 +787,21 @@ 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);
+            Boolean allowLeadingWildcard = false;
+            for (PropertyDefinition pd : pr.indexingRule.getProperties()) {
+                if (pd.name.equals(fieldName)) {
+                    allowLeadingWildcard = pd.allowLeadingWildcard;
+                }
+            }
+            // 
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
+            // Setting this to true can have performance impact, hence it's 
false by default in oak implementation for elastic,
+            // However clients can set it to true from property definition 
based on case by case usage.
+            if (allowLeadingWildcard) {
+                return 
queryStringQuery(text).field(fieldName).defaultOperator(Operator.AND);
+            } else {
+                return 
simpleQueryStringQuery(text).analyzeWildcard(true).field(fieldName).defaultOperator(Operator.AND);
+            }

Review comment:
       @fabriziofortino  - yes, usage for this is not documented on lucene and 
I suppose it was found out by SITES team while working on 
https://jira.corp.adobe.com/browse/SITES-2564.
   
   I added this check for specific properties/fields because elastic docs 
mention that this can have significant performance impact, so I didn't want to 
give an option to enable this at index level.
   
   >Does it mean that for full-text queries (eg: contains(. ,"*foo*") this 
would never work?
   atm, yes..we can change this behaviour, but I am not sure if we should. (I 
have not tested what the corresponding behaviour in lucene), but imo, we should 
restrict this to per field basis. wdyt ? 




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