jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexparvule...@apache.org
Subject svn commit: r1393400 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak: plugins/lucene/LuceneIndex.java query/ast/ComparisonImpl.java query/index/FilterImpl.java spi/query/Filter.java
Date Wed, 03 Oct 2012 10:48:15 GMT
Author: alexparvulescu
Date: Wed Oct  3 10:48:15 2012
New Revision: 1393400

URL: http://svn.apache.org/viewvc?rev=1393400&view=rev
Log:
OAK-347 QueryEngine 'like' interpretation error

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndex.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/ComparisonImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/FilterImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/Filter.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndex.java?rev=1393400&r1=1393399&r2=1393400&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndex.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndex.java
Wed Oct  3 10:48:15 2012
@@ -20,6 +20,7 @@ import static org.apache.jackrabbit.oak.
 import static org.apache.jackrabbit.oak.plugins.lucene.FieldNames.PATH;
 import static org.apache.jackrabbit.oak.plugins.lucene.FieldNames.PATH_SELECTOR;
 import static org.apache.jackrabbit.oak.plugins.lucene.TermFactory.newPathTerm;
+import static org.apache.jackrabbit.oak.query.Query.JCR_PATH;
 
 import java.io.IOException;
 import java.util.ArrayList;
@@ -55,12 +56,14 @@ import org.apache.lucene.index.Term;
 import org.apache.lucene.search.BooleanClause.Occur;
 import org.apache.lucene.search.BooleanQuery;
 import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.MatchAllDocsQuery;
 import org.apache.lucene.search.PrefixQuery;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.ScoreDoc;
 import org.apache.lucene.search.TermQuery;
 import org.apache.lucene.search.TermRangeQuery;
 import org.apache.lucene.search.TopDocs;
+import org.apache.lucene.search.WildcardQuery;
 import org.apache.lucene.store.Directory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -162,6 +165,9 @@ public class LuceneIndex implements Quer
         String path = filter.getPath();
         switch (filter.getPathRestriction()) {
         case ALL_CHILDREN:
+            if ("/".equals(path)) {
+                break;
+            }
             if (!path.endsWith("/")) {
                 path += "/";
             }
@@ -190,6 +196,7 @@ public class LuceneIndex implements Quer
             String name = pr.propertyName;
             String first = null;
             String last = null;
+            boolean isLike = pr.isLike;
 
             if (pr.first != null) {
                 first = pr.first.getString();
@@ -198,29 +205,52 @@ public class LuceneIndex implements Quer
                 last = pr.last.getString();
             }
 
+            if (isLike) {
+                if (first.contains("%")) {
+                    first = first.replace("%", "*");
+                }
+                if (first.endsWith("*")) {
+                    if (JCR_PATH.equals(name)) {
+                        qs.add(new PrefixQuery(newPathTerm(first)));
+                    } else {
+                        qs.add(new PrefixQuery(new Term(name, first)));
+                    }
+                } else {
+                    if (JCR_PATH.equals(name)) {
+                        qs.add(new WildcardQuery(newPathTerm(first)));
+                    } else {
+                        qs.add(new WildcardQuery(new Term(name, first)));
+                    }
+                }
+                continue;
+            }
+
             if (first != null && first.equals(last) && pr.firstIncluding
                     && pr.lastIncluding) {
-                if (org.apache.jackrabbit.oak.query.Query.JCR_PATH.equals(name)) {
+                if (JCR_PATH.equals(name)) {
                     qs.add(new TermQuery(newPathTerm(first)));
                 } else {
                     qs.add(new TermQuery(new Term(name, first)));
                 }
-
-            } else {
-                qs.add(TermRangeQuery.newStringRange(name, first, last,
-                        pr.firstIncluding, pr.lastIncluding));
+                continue;
             }
+
+            qs.add(TermRangeQuery.newStringRange(name, first, last,
+                    pr.firstIncluding, pr.lastIncluding));
+
         }
 
-        if (qs.size() > 1) {
-            BooleanQuery bq = new BooleanQuery();
-            for (Query q : qs) {
-                bq.add(q, Occur.MUST);
-            }
-            return bq;
-        } else {
+        if (qs.size() == 0) {
+            return new MatchAllDocsQuery();
+        }
+        if (qs.size() == 1) {
             return qs.get(0);
         }
+        BooleanQuery bq = new BooleanQuery();
+        for (Query q : qs) {
+            bq.add(q, Occur.MUST);
+        }
+        return bq;
     }
 
     private static void addNodeTypeConstraints(

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/ComparisonImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/ComparisonImpl.java?rev=1393400&r1=1393399&r2=1393400&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/ComparisonImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/ComparisonImpl.java
Wed Oct  3 10:48:15 2012
@@ -19,7 +19,6 @@
 package org.apache.jackrabbit.oak.query.ast;
 
 import org.apache.jackrabbit.oak.api.CoreValue;
-import org.apache.jackrabbit.oak.api.CoreValueFactory;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.query.Query;
 import org.apache.jackrabbit.oak.query.index.FilterImpl;
@@ -128,26 +127,28 @@ public class ComparisonImpl extends Cons
     public void restrict(FilterImpl f) {
         CoreValue v = operand2.currentValue();
         if (v != null) {
-            if (operator == Operator.LIKE) {
-                String pattern;
-                pattern = v.getString();
-                LikePattern p = new LikePattern(pattern);
-                String lowerBound = p.getLowerBound();
-                String upperBound = p.getUpperBound();
-                if (lowerBound == null && upperBound == null) {
-                    // ignore
-                } else if (operand1.supportsRangeConditions()) {
-                    CoreValueFactory vf = query.getValueFactory();
-                    if (lowerBound != null) {
-                        operand1.restrict(f, Operator.GREATER_OR_EQUAL, vf.createValue(lowerBound));
-                    }
-                    if (upperBound != null) {
-                        operand1.restrict(f, Operator.LESS_OR_EQUAL, vf.createValue(upperBound));
-                    }
-                }
-            } else {
-                operand1.restrict(f, operator, v);
-            }
+            operand1.restrict(f, operator, v);
+            // TODO OAK-347
+//            if (operator == Operator.LIKE) {
+//                String pattern;
+//                pattern = v.getString();
+//                LikePattern p = new LikePattern(pattern);
+//                String lowerBound = p.getLowerBound();
+//                String upperBound = p.getUpperBound();
+//                if (lowerBound == null && upperBound == null) {
+//                    // ignore
+//                } else if (operand1.supportsRangeConditions()) {
+//                    CoreValueFactory vf = query.getValueFactory();
+//                    if (lowerBound != null) {
+//                        operand1.restrict(f, Operator.GREATER_OR_EQUAL, vf.createValue(lowerBound));
+//                    }
+//                    if (upperBound != null) {
+//                        operand1.restrict(f, Operator.LESS_OR_EQUAL, vf.createValue(upperBound));
+//                    }
+//                }
+//            } else {
+//                operand1.restrict(f, operator, v);
+//            }
         }
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/FilterImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/FilterImpl.java?rev=1393400&r1=1393399&r2=1393400&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/FilterImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/FilterImpl.java
Wed Oct  3 10:48:15 2012
@@ -219,7 +219,10 @@ public class FilterImpl implements Filte
             x.lastIncluding = x.last == oldLast ? x.lastIncluding : true;
             break;
         case LIKE:
-            throw new IllegalArgumentException("LIKE is not supported");
+            // LIKE is handled in the fulltext index
+            x.isLike = true;
+            x.first = value;
+            break;
         }
         if (x.first != null && x.last != null) {
             if (x.first.compareTo(x.last) > 0) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/Filter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/Filter.java?rev=1393400&r1=1393399&r2=1393400&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/Filter.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/Filter.java
Wed Oct  3 10:48:15 2012
@@ -97,6 +97,12 @@ public interface Filter {
         public boolean lastIncluding;
 
         /**
+         * Whether this is a like constraint. in this case only the 'first'
+         * value should be taken into consideration
+         */
+        public boolean isLike;
+
+        /**
          * The property type, if restricted.
          * If not restricted, this field is set to PropertyType.UNDEFINED.
          */



Mime
View raw message