Author: chetanm Date: Mon Oct 16 10:23:19 2017 New Revision: 1812276 URL: http://svn.apache.org/viewvc?rev=1812276&view=rev Log: OAK-6831 - Nodetype index support in Lucene Index
Ensure that if jcr:primaryType is indexed then jcr:mixins is also indexed This is required to ensure consistency when multiple index rules for different types are defined 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=1812276&r1=1812275&r2=1812276&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 Mon Oct 16 10:23:19 2017 @@ -1213,9 +1213,26 @@ public final class IndexDefinition imple } } } + ensureNodeTypeIndexingIsConsistent(propDefns, syncProps); return ImmutableMap.copyOf(propDefns); } + /** + * If jcr:primaryType is indexed but jcr:mixinTypes is not indexed + * then ensure that jcr:mixinTypes is also indexed + */ + private void ensureNodeTypeIndexingIsConsistent(Map<String, PropertyDefinition> propDefns, + List<PropertyDefinition> syncProps) { + PropertyDefinition pd_pr = propDefns.get(JcrConstants.JCR_PRIMARYTYPE.toLowerCase(Locale.ENGLISH)); + PropertyDefinition pd_mixin = propDefns.get(JcrConstants.JCR_MIXINTYPES.toLowerCase(Locale.ENGLISH)); + + if (pd_pr != null && pd_pr.propertyIndex && pd_mixin == null) { + pd_mixin = createNodeTypeDefinition(this, JcrConstants.JCR_MIXINTYPES, pd_pr.sync); + syncProps.add(pd_mixin); + propDefns.put(JcrConstants.JCR_MIXINTYPES.toLowerCase(Locale.ENGLISH), pd_mixin); + } + } + private boolean hasAnyFullTextEnabledProperty() { for (PropertyDefinition pd : propConfigs.values()){ if (pd.fulltextEnabled()){ 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=1812276&r1=1812275&r2=1812276&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 Mon Oct 16 10:23:19 2017 @@ -1136,6 +1136,30 @@ public class IndexDefinitionTest { assertNull(getRule(defn, "oak:TestSuperType")); } + @Test + public void mixinAndPrimaryType() throws Exception{ + TestUtil.registerNodeType(builder, testNodeTypeDefn); + root = builder.getNodeState(); + + + IndexDefinitionBuilder defnb = new IndexDefinitionBuilder(); + defnb.indexRule("oak:TestMixA").property(JcrConstants.JCR_PRIMARYTYPE).propertyIndex(); + defnb.indexRule("oak:TestSuperType").property(JcrConstants.JCR_PRIMARYTYPE).propertyIndex().sync(); + + IndexDefinition defn = IndexDefinition.newBuilder(root, defnb.build(), "/foo").build(); + + IndexingRule a = getRule(defn, "oak:TestMixA"); + assertNotNull(a.getConfig(JcrConstants.JCR_PRIMARYTYPE)); + assertNotNull(a.getConfig(JcrConstants.JCR_MIXINTYPES)); + assertFalse(a.getConfig(JcrConstants.JCR_MIXINTYPES).sync); + + IndexingRule b = getRule(defn, "oak:TestSuperType"); + assertNotNull(b.getConfig(JcrConstants.JCR_PRIMARYTYPE)); + assertNotNull(b.getConfig(JcrConstants.JCR_MIXINTYPES)); + assertTrue(b.getConfig(JcrConstants.JCR_PRIMARYTYPE).sync); + assertTrue(b.getConfig(JcrConstants.JCR_MIXINTYPES).sync); + } + //TODO indexesAllNodesOfMatchingType - with nullCheckEnabled private static IndexingRule getRule(IndexDefinition defn, String typeName){