You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by th...@apache.org on 2014/11/05 16:09:39 UTC

svn commit: r1636891 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/query/ast/ main/java/org/apache/jackrabbit/oak/query/index/ main/java/org/apache/jackrabbit/oak/query/xpath/ main/java/org/apache/jackrabbit/oak/spi/query...

Author: thomasm
Date: Wed Nov  5 15:09:39 2014
New Revision: 1636891

URL: http://svn.apache.org/r1636891
Log:
OAK-2249 Query with mixed full-text, "and", "or" conditions fails

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/FullTextSearchImpl.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/query/xpath/Statement.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/Cursors.java
    jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/xpath.txt

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/FullTextSearchImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/FullTextSearchImpl.java?rev=1636891&r1=1636890&r2=1636891&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/FullTextSearchImpl.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/FullTextSearchImpl.java Wed Nov  5 15:09:39 2014
@@ -48,7 +48,7 @@ public class FullTextSearchImpl extends 
      * instead, as in the spec, using double quotes.
      */
     public static final boolean JACKRABBIT_2_SINGLE_QUOTED_PHRASE = true;
-    
+
     private final String selectorName;
     private final String relativePath;
     private final String propertyName;
@@ -251,8 +251,12 @@ public class FullTextSearchImpl extends 
     public void restrict(FilterImpl f) {
         if (propertyName != null) {
             if (f.getSelector().equals(selector)) {
-                String pn = normalizePropertyName(propertyName);
-                f.restrictProperty(pn, Operator.NOT_EQUAL, null);
+                String p = propertyName;
+                if (relativePath != null) {
+                    p = PathUtils.concat(p, relativePath);
+                }                
+                p = normalizePropertyName(p);
+                f.restrictProperty(p, Operator.NOT_EQUAL, null);
             }
         }
         f.restrictFulltextCondition(fullTextSearchExpression.currentValue().getValue(Type.STRING));

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=1636891&r1=1636890&r2=1636891&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 Nov  5 15:09:39 2014
@@ -401,7 +401,7 @@ public class FilterImpl implements Filte
             buff.append("query=").append(queryStatement);
         }
         if (fullTextConstraint != null) {
-            buff.append("fullText=").append(fullTextConstraint);
+            buff.append(" fullText=").append(fullTextConstraint);
         }
         buff.append(", path=").append(getPathPlan());
         if (!propertyRestrictions.isEmpty()) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/xpath/Statement.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/xpath/Statement.java?rev=1636891&r1=1636890&r2=1636891&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/xpath/Statement.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/xpath/Statement.java Wed Nov  5 15:09:39 2014
@@ -83,9 +83,7 @@ public class Statement {
     }
     
     private static void addToUnionList(Expression condition,  ArrayList<Expression> unionList) {
-        if (condition.containsFullTextCondition()) {
-            // do not use union
-        } else if (condition instanceof OrCondition) {
+        if (condition instanceof OrCondition) {
             OrCondition or = (OrCondition) condition;
             // conditions of type                
             // @x = 1 or @y = 2

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/Cursors.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/Cursors.java?rev=1636891&r1=1636890&r2=1636891&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/Cursors.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/Cursors.java Wed Nov  5 15:09:39 2014
@@ -439,7 +439,12 @@ public class Cursors {
         ConcatCursor(List<Cursor> cursors, QueryEngineSettings settings) {
             this.cursors = cursors;
             this.settings = settings;
-            this.currentCursor = cursors.remove(0);
+            if (cursors.size() == 0) {
+                init = true;
+                closed = true;
+            } else {
+                this.currentCursor = cursors.remove(0);
+            }
         }
 
         @Override

Modified: jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/xpath.txt
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/xpath.txt?rev=1636891&r1=1636890&r2=1636891&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/xpath.txt (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/xpath.txt Wed Nov  5 15:09:39 2014
@@ -237,8 +237,11 @@ xpath2sql //*[((@jcr:primaryType = 'nt:u
 select [jcr:path], [jcr:score], *
   from [nt:base] as a
   where [jcr:primaryType] = 'nt:unstructured'
-  and (contains(*, 'hello')
-  or contains(*, 'world'))
+  and contains(*, 'hello')
+  union select [jcr:path], [jcr:score], *
+  from [nt:base] as a
+  where [jcr:primaryType] = 'nt:unstructured'
+  and contains(*, 'world')
   /* xpath ... */
 
 xpath2sql //*[(((@jcr:primaryType = 'nt:unstructured')
@@ -249,9 +252,14 @@ xpath2sql //*[(((@jcr:primaryType = 'nt:
 select [jcr:path], [jcr:score], *
   from [nt:base] as a
   where [jcr:primaryType] = 'nt:unstructured'
-  and (contains(*, 'hello')
-  or contains(*, 'world'))
-  or [content] = '/data'
+  and contains(*, 'hello')
+  union select [jcr:path], [jcr:score], *
+  from [nt:base] as a
+  where [jcr:primaryType] = 'nt:unstructured'
+  and contains(*, 'world')
+  union select [jcr:path], [jcr:score], *
+  from [nt:base] as a
+  where [content] = '/data'
   and [jcr:primaryType] = 'nt:folder'
   /* xpath ... */
 
@@ -590,10 +598,18 @@ xpath2sql //element(*,rep:Authorizable)
 select [jcr:path], [jcr:score], *
   from [rep:Authorizable] as a
   where contains([profile/givenName/*], '**')
-  or contains([profile/familyName/*], '**')
-  or contains([profile/email/*], '**')
-  or [rep:principalName] like '%%'
-  or name(a) like '%%'
+  union select [jcr:path], [jcr:score], *
+  from [rep:Authorizable] as a
+  where contains([profile/familyName/*], '**')
+  union select [jcr:path], [jcr:score], *
+  from [rep:Authorizable] as a
+  where contains([profile/email/*], '**')
+  union select [jcr:path], [jcr:score], *
+  from [rep:Authorizable] as a
+  where [rep:principalName] like '%%'
+  union select [jcr:path], [jcr:score], *
+  from [rep:Authorizable] as a
+  where name(a) like '%%'
   order by [rep:principalName]
   /* xpath ... */
 
@@ -607,10 +623,18 @@ xpath2sql //element(*,rep:Authorizable)
 select [jcr:path], [jcr:score], *
   from [rep:Authorizable] as a
   where contains([profile/givenName/*], '**')
-  or contains([profile/familyName/*], '**')
-  or contains([profile/email/*], '**')
-  or [rep:principalName] like '%%'
-  or name(a) like '%%'
+  union select [jcr:path], [jcr:score], *
+  from [rep:Authorizable] as a
+  where contains([profile/familyName/*], '**')
+  union select [jcr:path], [jcr:score], *
+  from [rep:Authorizable] as a
+  where contains([profile/email/*], '**')
+  union select [jcr:path], [jcr:score], *
+  from [rep:Authorizable] as a
+  where [rep:principalName] like '%%'
+  union select [jcr:path], [jcr:score], *
+  from [rep:Authorizable] as a
+  where name(a) like '%%'
   order by [rep:principalName]
   /* xpath ... */
 
@@ -672,10 +696,18 @@ xpath2sql //element(*,rep:Authorizable)
 select [jcr:path], [jcr:score], *
   from [rep:Authorizable] as a
   where contains([profile/givenName], '**')
-  or contains([profile/familyName], '**')
-  or contains([profile/email], '**')
-  or [rep:principalName] like '%%'
-  or name(a) like '%%'
+  union select [jcr:path], [jcr:score], *
+  from [rep:Authorizable] as a
+  where contains([profile/familyName], '**')
+  union select [jcr:path], [jcr:score], *
+  from [rep:Authorizable] as a
+  where contains([profile/email], '**')
+  union select [jcr:path], [jcr:score], *
+  from [rep:Authorizable] as a
+  where [rep:principalName] like '%%'
+  union select [jcr:path], [jcr:score], *
+  from [rep:Authorizable] as a
+  where name(a) like '%%'
   order by [rep:principalName]
   /* xpath ... */