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 ch...@apache.org on 2014/12/14 08:15:01 UTC

svn commit: r1645424 - in /jackrabbit/oak/trunk/oak-lucene/src: main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinition.java test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinitionTest.java

Author: chetanm
Date: Sun Dec 14 07:15:01 2014
New Revision: 1645424

URL: http://svn.apache.org/r1645424
Log:
OAK-2351 - Property name regex should only be applied on property name

Handle relative property in NamePattern

Modified:
    jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinition.java
    jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinitionTest.java

Modified: jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinition.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinition.java?rev=1645424&r1=1645423&r2=1645424&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinition.java (original)
+++ jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinition.java Sun Dec 14 07:15:01 2014
@@ -66,6 +66,7 @@ import static com.google.common.collect.
 import static com.google.common.collect.Sets.newHashSet;
 import static org.apache.jackrabbit.JcrConstants.NT_BASE;
 import static org.apache.jackrabbit.oak.api.Type.NAMES;
+import static org.apache.jackrabbit.oak.commons.PathUtils.getParentPath;
 import static org.apache.jackrabbit.oak.commons.PathUtils.isAbsolute;
 import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.DECLARING_NODE_TYPES;
 import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.ENTRY_COUNT_PROPERTY_NAME;
@@ -721,6 +722,7 @@ class IndexDefinition implements Aggrega
      * A property name pattern.
      */
     private static final class NamePattern {
+        private final String parentPath;
         /**
          * The pattern to match.
          */
@@ -740,7 +742,16 @@ class IndexDefinition implements Aggrega
         private NamePattern(String pattern,
                             PropertyDefinition config){
 
-            this.pattern = Pattern.compile(pattern);
+            //Special handling for all props regex as its already being used
+            //and use of '/' in regex would confuse the parent path calculation
+            //logic
+            if (LuceneIndexConstants.REGEX_ALL_PROPS.equals(pattern)){
+                this.parentPath = "";
+                this.pattern = Pattern.compile(pattern);
+            } else {
+                this.parentPath = getParentPath(pattern);
+                this.pattern = Pattern.compile(PathUtils.getName(pattern));
+            }
             this.config = config;
         }
 
@@ -750,7 +761,12 @@ class IndexDefinition implements Aggrega
          *         pattern; <code>false</code> otherwise.
          */
         boolean matches(String propertyPath) {
-            return pattern.matcher(propertyPath).matches();
+            String parentPath = getParentPath(propertyPath);
+            String propertyName = PathUtils.getName(propertyPath);
+            if (!this.parentPath.equals(parentPath)) {
+                return false;
+            }
+            return pattern.matcher(propertyName).matches();
         }
 
         PropertyDefinition getConfig() {

Modified: jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinitionTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinitionTest.java?rev=1645424&r1=1645423&r2=1645424&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinitionTest.java (original)
+++ jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinitionTest.java Sun Dec 14 07:15:01 2014
@@ -263,6 +263,32 @@ public class IndexDefinitionTest {
     }
 
     @Test
+    public void indexRuleWithPropertyRegEx2() throws Exception{
+        NodeBuilder rules = builder.child(INDEX_RULES);
+        rules.child("nt:folder");
+        child(rules, "nt:folder/properties/prop1")
+                .setProperty(LuceneIndexConstants.PROP_NAME, ".*")
+                .setProperty(LuceneIndexConstants.PROP_IS_REGEX, true);
+        child(rules, "nt:folder/properties/prop2")
+                .setProperty(LuceneIndexConstants.PROP_NAME, "metadata/.*")
+                .setProperty(LuceneIndexConstants.PROP_IS_REGEX, true)
+                .setProperty(LuceneIndexConstants.FIELD_BOOST, 4.0);
+
+
+        IndexDefinition defn = new IndexDefinition(root, builder.getNodeState());
+
+        IndexingRule rule1 = defn.getApplicableIndexingRule(newTree(newNode("nt:folder")));
+        assertNotNull(rule1);
+
+        assertTrue(rule1.isIndexed("prop1"));
+        assertTrue(rule1.isIndexed("prop2"));
+        assertFalse(rule1.isIndexed("jcr:content/prop1"));
+
+        assertTrue(rule1.isIndexed("metadata/foo"));
+        assertFalse(rule1.isIndexed("metadata/foo/bar"));
+    }
+
+    @Test
     public void indexRuleWithPropertyOrdering() throws Exception{
         NodeBuilder rules = builder.child(INDEX_RULES);
         rules.child("nt:folder");