Author: amitj
Date: Thu Oct  9 06:58:45 2014
New Revision: 1630299

URL: http://svn.apache.org/r1630299
Log:
OAK-2146: empty resultset for PropertyIndex and multi-value properties with 
mixed OR+AND
Changed to union from intersection.

Added:
    
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/SinglePropertyIndexQueryTests.java
   (with props)
Modified:
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/FilterImpl.java

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=1630299&r1=1630298&r2=1630299&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
 Thu Oct  9 06:58:45 2014
@@ -287,7 +287,12 @@ public class FilterImpl implements Filte
         if (x.list == null) {
             x.list = list;
         } else {
-            x.list.retainAll(list);
+            // this is required for multi-valued properties:
+            // for example, if a multi-value property p contains {1, 2},
+            // and we search using "p in (1, 3) and p in (2, 4)", then
+            // this needs to match - so we search for "p in (1, 2, 3, 4)"
+            x.list.removeAll(list);
+            x.list.addAll(list);
         }
     }
 

Added: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/SinglePropertyIndexQueryTests.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/SinglePropertyIndexQueryTests.java?rev=1630299&view=auto
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/SinglePropertyIndexQueryTests.java
 (added)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/SinglePropertyIndexQueryTests.java
 Thu Oct  9 06:58:45 2014
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.plugins.index.property;
+
+import static com.google.common.collect.ImmutableList.of;
+import static com.google.common.collect.Lists.newArrayList;
+import static org.apache.jackrabbit.oak.api.Type.NAMES;
+import static org.apache.jackrabbit.oak.api.Type.STRINGS;
+import static 
org.apache.jackrabbit.oak.plugins.index.IndexConstants.PROPERTY_NAMES;
+import static 
org.apache.jackrabbit.oak.plugins.index.IndexConstants.REINDEX_PROPERTY_NAME;
+import static 
org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider.TYPE;
+
+import java.util.List;
+
+import org.apache.jackrabbit.oak.Oak;
+import org.apache.jackrabbit.oak.api.ContentRepository;
+import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.plugins.nodetype.write.InitialContent;
+import org.apache.jackrabbit.oak.query.AbstractQueryTest;
+import org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider;
+import org.junit.Test;
+
+public class SinglePropertyIndexQueryTests extends AbstractQueryTest {
+    private static final String INDEXED_PROPERTY = "indexedProperty";
+    
+    @Override
+    protected ContentRepository createRepository() {
+        return new Oak().with(new InitialContent())
+            .with(new OpenSecurityProvider())
+            .with(new PropertyIndexProvider())
+            .with(new PropertyIndexEditorProvider())
+            .createContentRepository();
+    }
+
+    @Override
+    protected void createTestIndexNode() throws Exception {
+        Tree index = super.createTestIndexNode(root.getTree("/"), TYPE);
+        index.setProperty(PROPERTY_NAMES, of(INDEXED_PROPERTY), NAMES);
+        index.setProperty(REINDEX_PROPERTY_NAME, true);
+        root.commit();
+    }
+
+    @Test
+    public void oak2146() throws Exception {
+        final String statement = "//*[ " +
+            "(@" + INDEXED_PROPERTY + " = 'a' or @" + INDEXED_PROPERTY + " = 
'c') " +
+            "and " +
+            "(@" + INDEXED_PROPERTY + " = 'b' or @" + INDEXED_PROPERTY + " = 
'd')]";
+        List<String> expected = newArrayList();
+        
+        Tree content = root.getTree("/").addChild("content");
+        
+        // adding /content/node1 { a, b } 
+        Tree node = content.addChild("node1");
+        node.setProperty(INDEXED_PROPERTY, of("a", "b"), STRINGS);
+        expected.add(node.getPath());
+        
+        // adding /content/node2 { c, d }
+        node = content.addChild("node2");
+        node.setProperty(INDEXED_PROPERTY, of("c", "d"), STRINGS);
+        expected.add(node.getPath());
+        
+        // adding nodes with {a, x} and {c, x} these should not be returned
+        node = content.addChild("node3");
+        node.setProperty(INDEXED_PROPERTY, of("a", "x"), STRINGS);
+        node = content.addChild("node4");
+        node.setProperty(INDEXED_PROPERTY, of("c", "x"), STRINGS);
+        
+        root.commit();
+        
+        assertQuery(statement, "xpath", expected);
+    }
+}

Propchange: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/SinglePropertyIndexQueryTests.java
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to