You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by re...@apache.org on 2018/06/20 09:02:34 UTC

svn commit: r1833896 - in /jackrabbit/branches/2.14: ./ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/ jackrabbit-core/src/test/resources/org/apache/jackrabb...

Author: reschke
Date: Wed Jun 20 09:02:34 2018
New Revision: 1833896

URL: http://svn.apache.org/viewvc?rev=1833896&view=rev
Log:
JCR-4093: IndexRule are meant to be applied based on both primaryType and minin type based inheritance. Currently it appears that only primaryType based inheritance is working (ported to 2.14)

Added:
    jackrabbit/branches/2.14/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/query/lucene/indexing_config5.xml
      - copied unchanged from r1780336, jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/query/lucene/indexing_config5.xml
Modified:
    jackrabbit/branches/2.14/   (props changed)
    jackrabbit/branches/2.14/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImpl.java
    jackrabbit/branches/2.14/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImplTest.java
    jackrabbit/branches/2.14/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/AbstractJCRTest.java

Propchange: jackrabbit/branches/2.14/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jun 20 09:02:34 2018
@@ -1,3 +1,3 @@
 /jackrabbit/branches/JCR-2272:1173165-1176545
 /jackrabbit/sandbox/JCR-2415-lucene-3.0:1060860-1064038
-/jackrabbit/trunk:1776907,1776911-1776912,1776914,1776918,1779166,1779460,1779614,1779632,1780208,1780220,1780406,1785225,1786325,1786330,1787043,1787381,1792100,1792105,1792113,1792193,1793315,1793323,1793327,1793332,1793339,1796980,1797209,1797917,1798586,1799429,1799538,1799549,1799575,1800359,1800378,1800752,1802925,1802977,1807234,1807244,1808752,1808754,1809149,1809329,1809624,1810108,1811667,1812543,1812634,1812994,1814831,1817094,1817097-1817098,1817100,1817113,1817201,1817213,1817373,1817377,1818586,1819269,1819271,1819839,1819849,1820119,1820133,1820294,1820573,1820675,1821247,1821475,1821597,1821705,1821880,1822643,1822863,1822947,1822950,1824756,1824763-1824764,1824771,1824876,1826230,1826647,1826940,1826964,1828213,1830107,1830201,1830540,1830753,1830878,1830951,1833374
+/jackrabbit/trunk:1776907,1776911-1776912,1776914,1776918,1779166,1779460,1779614,1779632,1780208,1780220,1780335-1780336,1780406,1785225,1786325,1786330,1787043,1787381,1792100,1792105,1792113,1792193,1793315,1793323,1793327,1793332,1793339,1796980,1797209,1797917,1798586,1799429,1799538,1799549,1799575,1800359,1800378,1800752,1802925,1802977,1807234,1807244,1808752,1808754,1809149,1809329,1809624,1810108,1811667,1812543,1812634,1812994,1814831,1817094,1817097-1817098,1817100,1817113,1817201,1817213,1817373,1817377,1818586,1819269,1819271,1819839,1819849,1820119,1820133,1820294,1820573,1820675,1821247,1821475,1821597,1821705,1821880,1822643,1822863,1822947,1822950,1824756,1824763-1824764,1824771,1824876,1826230,1826647,1826940,1826964,1828213,1830107,1830201,1830540,1830753,1830878,1830951,1833374

Modified: jackrabbit/branches/2.14/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.14/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImpl.java?rev=1833896&r1=1833895&r2=1833896&view=diff
==============================================================================
--- jackrabbit/branches/2.14/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImpl.java (original)
+++ jackrabbit/branches/2.14/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImpl.java Wed Jun 20 09:02:34 2018
@@ -28,6 +28,7 @@ import java.util.Properties;
 
 import javax.jcr.NamespaceException;
 import javax.jcr.RepositoryException;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
 
 import org.apache.commons.collections.iterators.AbstractIteratorDecorator;
 import org.apache.jackrabbit.core.HierarchyManager;
@@ -46,6 +47,8 @@ import org.apache.jackrabbit.core.value.
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.Path;
 import org.apache.jackrabbit.spi.PathFactory;
+import org.apache.jackrabbit.spi.QNodeTypeDefinition;
+import org.apache.jackrabbit.spi.QPropertyDefinition;
 import org.apache.jackrabbit.spi.commons.conversion.IllegalNameException;
 import org.apache.jackrabbit.spi.commons.conversion.MalformedPathException;
 import org.apache.jackrabbit.spi.commons.conversion.NameResolver;
@@ -212,7 +215,7 @@ public class IndexingConfigurationImpl
      *         <code>false</code> otherwise.
      */
     public boolean isIndexed(NodeState state, Name propertyName) {
-        IndexingRule rule = getApplicableIndexingRule(state);
+        IndexingRule rule = getApplicableIndexingRule(state, propertyName);
         if (rule != null) {
             return rule.isIndexed(propertyName);
         }
@@ -230,7 +233,7 @@ public class IndexingConfigurationImpl
      * @return the boost value for the property.
      */
     public float getPropertyBoost(NodeState state, Name propertyName) {
-        IndexingRule rule = getApplicableIndexingRule(state);
+        IndexingRule rule = getApplicableIndexingRule(state, propertyName);
         if (rule != null) {
             return rule.getBoost(propertyName);
         }
@@ -244,7 +247,7 @@ public class IndexingConfigurationImpl
      * @return the boost for the node scope fulltext index field.
      */
     public float getNodeBoost(NodeState state) {
-        IndexingRule rule = getApplicableIndexingRule(state);
+        IndexingRule rule = getApplicableIndexingRule(state, null);
         if (rule != null) {
             return rule.getNodeBoost();
         }
@@ -263,7 +266,7 @@ public class IndexingConfigurationImpl
      */
     public boolean isIncludedInNodeScopeIndex(NodeState state,
                                               Name propertyName) {
-        IndexingRule rule = getApplicableIndexingRule(state);
+        IndexingRule rule = getApplicableIndexingRule(state, propertyName);
         if (rule != null) {
             return rule.isIncludedInNodeScopeIndex(propertyName);
         }
@@ -282,7 +285,7 @@ public class IndexingConfigurationImpl
      *         included in an excerpt; <code>false</code> otherwise.
      */
     public boolean useInExcerpt(NodeState state, Name propertyName) {
-        IndexingRule rule = getApplicableIndexingRule(state);
+        IndexingRule rule = getApplicableIndexingRule(state, propertyName);
         if (rule != null) {
             return rule.useInExcerpt(propertyName);
         }
@@ -353,7 +356,7 @@ public class IndexingConfigurationImpl
                             nt2rules.put(ntName, perNtConfig);
                         }
                         log.debug("Registering it for name '{}'", ntName);
-                        perNtConfig.add(new IndexingRule(element, ntName));
+                        perNtConfig.add(new IndexingRule(element, ntReg.getNodeTypeDef(ntName)));
                     }
                 }
             }
@@ -367,9 +370,10 @@ public class IndexingConfigurationImpl
      * <code>state</code>.
      *
      * @param state a node state.
+     * @param propertyName the property name to check.
      * @return the indexing rule or <code>null</code> if none applies.
      */
-    private IndexingRule getApplicableIndexingRule(NodeState state) {
+    private IndexingRule getApplicableIndexingRule(NodeState state, Name propertyName) {
         List<IndexingRule> rules = null;
         List<IndexingRule> r = configElements.get(state.getNodeTypeName());
         if (r != null) {
@@ -389,7 +393,7 @@ public class IndexingConfigurationImpl
 
         if (rules != null) {
             for (IndexingRule rule : rules) {
-                if (rule.appliesTo(state)) {
+                if (rule.appliesTo(state, propertyName)) {
                     return rule;
                 }
             }
@@ -654,9 +658,9 @@ public class IndexingConfigurationImpl
     private class IndexingRule {
 
         /**
-         * The node type of this fulltext indexing rule.
+         * The NodeTypeDefinition of this fulltext indexing rule.
          */
-        private final Name nodeTypeName;
+        private final QNodeTypeDefinition nodeTypeDefinition;
 
         /**
          * Map of {@link PropertyConfig}. Key=Name of property.
@@ -683,10 +687,10 @@ public class IndexingConfigurationImpl
          * different node type name.
          *
          * @param original the existing rule.
-         * @param nodeTypeName the node type name for the rule.
+         * @param qNodeTypeDefinition the node type for the rule.
          */
-        IndexingRule(IndexingRule original, Name nodeTypeName) {
-            this.nodeTypeName = nodeTypeName;
+        IndexingRule(IndexingRule original, QNodeTypeDefinition qNodeTypeDefinition) {
+            this.nodeTypeDefinition = qNodeTypeDefinition;
             this.propConfigs = original.propConfigs;
             this.namePatterns = original.namePatterns;
             this.condition = original.condition;
@@ -699,10 +703,11 @@ public class IndexingConfigurationImpl
          * @throws MalformedPathException if the condition expression is malformed.
          * @throws IllegalNameException   if a name contains illegal characters.
          * @throws NamespaceException if a name contains an unknown prefix.
+         * @throws NoSuchNodeTypeException if the nodeType could not be evaluated
          */
         IndexingRule(Node config)
-                throws MalformedPathException, IllegalNameException, NamespaceException {
-            this.nodeTypeName = getNodeTypeName(config);
+                throws MalformedPathException, IllegalNameException, NamespaceException, NoSuchNodeTypeException {
+            this.nodeTypeDefinition = getNodeTypeDefinition(config);
             this.condition = getCondition(config);
             this.boost = getNodeBoost(config);
             this.propConfigs = new HashMap<Name, PropertyConfig>();
@@ -716,7 +721,7 @@ public class IndexingConfigurationImpl
          * @return name of the node type.
          */
         public Name getNodeTypeName() {
-            return nodeTypeName;
+            return nodeTypeDefinition.getName();
         }
 
         /**
@@ -788,10 +793,19 @@ public class IndexingConfigurationImpl
          * <code>state</code>.
          *
          * @param state the state to check.
+         * @param propertyName the property name to check.
          * @return <code>true</code> the rule applies to the given node;
          *         <code>false</code> otherwise.
          */
-        public boolean appliesTo(NodeState state) {
+        public boolean appliesTo(NodeState state, Name propertyName) {
+        	Name nodeTypeName = getNodeTypeName();
+        	if (propertyName != null) {
+	        	for (QPropertyDefinition propertyDefinition : nodeTypeDefinition.getPropertyDefs()) {
+	        		if (propertyDefinition.getName().equals(propertyName)) {
+	        			return true;
+	        		}
+	        	}
+        	}
             if (!nodeTypeName.equals(state.getNodeTypeName())) {
                 return false;
             }
@@ -831,11 +845,12 @@ public class IndexingConfigurationImpl
          *                                characters.
          * @throws NamespaceException if the node type contains an unknown
          *                                prefix.
+         * @throws NoSuchNodeTypeException if the node type could not be evaluated
          */
-        private Name getNodeTypeName(Node config)
-                throws IllegalNameException, NamespaceException {
+        private QNodeTypeDefinition getNodeTypeDefinition(Node config)
+                throws IllegalNameException, NamespaceException, NoSuchNodeTypeException {
             String ntString = config.getAttributes().getNamedItem("nodeType").getNodeValue();
-            return resolver.getQName(ntString);
+            return ntReg.getNodeTypeDef(resolver.getQName(ntString));
         }
 
         /**

Modified: jackrabbit/branches/2.14/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.14/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImplTest.java?rev=1833896&r1=1833895&r2=1833896&view=diff
==============================================================================
--- jackrabbit/branches/2.14/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImplTest.java (original)
+++ jackrabbit/branches/2.14/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImplTest.java Wed Jun 20 09:02:34 2018
@@ -43,12 +43,14 @@ public class IndexingConfigurationImplTe
     private static final Name FOO = NameFactoryImpl.getInstance().create("", "foo");
 
     private NodeState nState;
+    private Node n;
 
     @Override
     protected void setUp() throws Exception {
         super.setUp();
-        Node n = testRootNode.addNode(nodeName1, ntUnstructured);
+        n = testRootNode.addNode(nodeName1, ntUnstructured);
         n.addMixin(mixReferenceable);
+        n.addMixin(mixTitle);
         session.save();
         nState = (NodeState) getSearchIndex().getContext().getItemStateManager().getItemState(
                 new NodeId(n.getIdentifier()));
@@ -97,6 +99,13 @@ public class IndexingConfigurationImplTe
         assertFalse(config.isIncludedInNodeScopeIndex(state, FOO));
     }
 
+    public void testIndexRuleMixin() throws Exception{
+        IndexingConfiguration config = createConfig("config5");
+        assertTrue(config.isIndexed(nState, NameConstants.JCR_TITLE));
+        assertFalse(config.isIndexed(nState, NameConstants.JCR_DESCRIPTION));
+        assertTrue(config.isIndexed(nState, NameConstants.JCR_UUID)); // from mixReferenceable ... should be indexed
+    }
+
     //----------------------------< internal >----------------------------------
     protected IndexingConfiguration createConfig(String name) throws Exception {
         IndexingConfiguration config = new IndexingConfigurationImpl();

Modified: jackrabbit/branches/2.14/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/AbstractJCRTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.14/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/AbstractJCRTest.java?rev=1833896&r1=1833895&r2=1833896&view=diff
==============================================================================
--- jackrabbit/branches/2.14/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/AbstractJCRTest.java (original)
+++ jackrabbit/branches/2.14/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/AbstractJCRTest.java Wed Jun 20 09:02:34 2018
@@ -213,6 +213,11 @@ public abstract class AbstractJCRTest ex
     protected String mixLockable;
 
     /**
+     * JCR Name mix:title using the namespace resolver of the current session.
+     */
+    protected String mixTitle;
+
+    /**
      * JCR Name mix:shareable using the namespace resolver of the current session.
      */
     protected String mixShareable;
@@ -379,6 +384,7 @@ public abstract class AbstractJCRTest ex
         mixSimpleVersionable = superuser.getNamespacePrefix(NS_MIX_URI) + ":simpleVersionable";
         mixLockable = superuser.getNamespacePrefix(NS_MIX_URI) + ":lockable";
         mixShareable = superuser.getNamespacePrefix(NS_MIX_URI) + ":shareable";
+        mixTitle = superuser.getNamespacePrefix(NS_MIX_URI) + ":title";
         ntQuery = superuser.getNamespacePrefix(NS_NT_URI) + ":query";
 
         // setup custom namespaces