You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by GitBox <gi...@apache.org> on 2022/08/09 06:52:31 UTC

[GitHub] [jackrabbit-oak] nfsantos commented on a diff in pull request #657: OAK-9881 - Unreachable code in the logic that processes like constraints in Elastic

nfsantos commented on code in PR #657:
URL: https://github.com/apache/jackrabbit-oak/pull/657#discussion_r940963346


##########
oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/query/ElasticRequestHandler.java:
##########
@@ -746,15 +746,14 @@ private static Query nodeName(Filter.PropertyRestriction pr) {
         throw new IllegalStateException("For nodeName queries only EQUALS and LIKE are supported " + pr);
     }
 
-    private static Query like(String name, String first) {
-        first = first.replace('%', WildcardQuery.WILDCARD_STRING);
+    private static Query like(String name, String first) {first = first.replace('%', WildcardQuery.WILDCARD_STRING);
         first = first.replace('_', WildcardQuery.WILDCARD_CHAR);
 
-        int indexOfWS = first.indexOf(WildcardQuery.WILDCARD_STRING);
-        int indexOfWC = first.indexOf(WildcardQuery.WILDCARD_CHAR);
-        int len = first.length();
+        // If the query ends in a wildcard string (*) and has no other wildcard characters, use a prefix match query
+        boolean hasSingleWildcardStringAtEnd = first.indexOf(WildcardQuery.WILDCARD_STRING) == first.length() - 1;

Review Comment:
   I was planning of handling the escape characters issue separately from this PR, in this separate issue: https://issues.apache.org/jira/browse/OAK-9885 
   
   The Lucene logic that handles like queries with wildcards is here, in the class `LucenePropertyIndex`: 
   https://github.com/apache/jackrabbit-oak/blob/27a7a9ffa0e78e5b258626aef24066eb58efc559/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java#L1161-L1198
   I confirmed that this code is being used in a debugging session. 
   
   There is similar logic in `LuceneIndex` class, but I suspect it is unused, maybe leftovers from a refactoring. The logic in LuceneIndex does seem incomplete, it even has a TODO asking what to do about escaped characters.
   https://github.com/apache/jackrabbit-oak/blob/34edee29cf65e44f18cc0548d176ab005de6dea6/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndex.java#L755-L791
   
   Although it's not an ideal solution, we could just copy the correct code from Lucene to Elastic. Alternatively, we could refactor the wildcard handling logic to some common package where we can reuse it.
   



-- 
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: dev-unsubscribe@jackrabbit.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org