diff --git a/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/IndexDefinitionBuilderTest.java b/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/IndexDefinitionBuilderTest.java index de0dcfc..b3a474e 100644 --- a/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/IndexDefinitionBuilderTest.java +++ b/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/IndexDefinitionBuilderTest.java @@ -43,6 +43,7 @@ import static org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConsta import static org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConstants.FIELD_BOOST; import static org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConstants.PROP_FACETS; import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE; +import static org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConstants.PROP_REFRESH_DEFN; import static org.junit.Assert.*; public class IndexDefinitionBuilderTest { @@ -253,6 +254,227 @@ public class IndexDefinitionBuilderTest { assertTrue(builder.build().getBoolean(REINDEX_PROPERTY_NAME)); } + // This property is used in cost estimation - no reindexing required + // on property change + @Test + public void noReindexIfWeightPropertyAddedOrChanged() throws Exception { + + builder.indexRule("nt:base").property("fooProp"); + + NodeState currentNodeState = builder.build(); + nodeBuilder = currentNodeState.builder(); + + //Unset the reindex flag first because first build would have set it . + nodeBuilder.setProperty(REINDEX_PROPERTY_NAME, false); + builder = new IndexDefinitionBuilder(nodeBuilder); + + // Add the property weight to fooProp - this shouldn't cause reindex flag to set + builder.indexRule("nt:base").property("fooProp").weight(10); + + currentNodeState = builder.build(); + + assertFalse(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME)); + assertTrue(currentNodeState.getBoolean(PROP_REFRESH_DEFN)); + + nodeBuilder = currentNodeState.builder(); + nodeBuilder.setProperty(PROP_REFRESH_DEFN, false); + + // Now change the value for weight on fooProp - this also shouldn't lead to setting of reindex flag + builder = new IndexDefinitionBuilder(nodeBuilder); + + builder.indexRule("nt:base").property("fooProp").weight(20); + currentNodeState = builder.build(); + assertFalse(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME)); + assertTrue(currentNodeState.getBoolean(PROP_REFRESH_DEFN)); + + } + // modifying boost value shouldn't require reindexing because we use + // QueryTime Boosts and not index time boosts. Refer OAK-3367 for details + @Test + public void noReindexIfBoostPropAddedOrChanged() throws Exception { + builder.indexRule("nt:base").property("fooProp"); + + NodeState currentNodeState = builder.build(); + nodeBuilder = currentNodeState.builder(); + + //Unset the reindex flag first because first build would have set it . + nodeBuilder.setProperty(REINDEX_PROPERTY_NAME, false); + builder = new IndexDefinitionBuilder(nodeBuilder); + + // Add the property boost - this shouldn't cause reindex flag to set + builder.indexRule("nt:base").property("fooProp").boost(1.0f); + + currentNodeState = builder.build(); + + assertFalse(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME)); + assertTrue(currentNodeState.getBoolean(PROP_REFRESH_DEFN)); + + nodeBuilder = currentNodeState.builder(); + nodeBuilder.setProperty(PROP_REFRESH_DEFN,false); + + // Now change the value for boost - this also shouldn't lead to setting of reindex flag + builder = new IndexDefinitionBuilder(nodeBuilder); + + builder.indexRule("nt:base").property("fooProp").boost(2.0f); + currentNodeState = builder.build(); + assertFalse(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME)); + assertTrue(currentNodeState.getBoolean(PROP_REFRESH_DEFN)); + } + + @Test + public void noReindexWhenNameChangeOnIndexDefNode() throws Exception{ + builder.async("async", IndexConstants.INDEXING_MODE_NRT); + + NodeState currentNodeState = builder.build(); + nodeBuilder = currentNodeState.builder(); + + //Unset the reindex flag first because first build would have set it . + nodeBuilder.setProperty(REINDEX_PROPERTY_NAME, false); + + builder = new IndexDefinitionBuilder(nodeBuilder); + // Setter for this is not exposed in IndexDefintionBuilder + // but can be set explicitly via node builder - so a valid use case + nodeBuilder.setProperty("name","testIndex"); + + currentNodeState = builder.build(); + + assertFalse(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME)); + assertTrue(currentNodeState.getBoolean(PROP_REFRESH_DEFN)); + nodeBuilder = currentNodeState.builder(); + nodeBuilder.setProperty(PROP_REFRESH_DEFN,false); + + //Now test with changing the value - this too shouldn't set the reindexing flag + builder = new IndexDefinitionBuilder(nodeBuilder); + nodeBuilder.setProperty("name","testIndex2"); + + currentNodeState = builder.build(); + assertFalse(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME)); + assertTrue(currentNodeState.getBoolean(PROP_REFRESH_DEFN)); + } + // This is a node for configuration on how faceted search works + // Everything impacts querty time evauation - so no need of reindexing in case of changes + @Test + public void noReindexWhenFacetNodeAddedOrRemoved() throws Exception { + builder.indexRule("nt:base") + .property("foo1").facets(); + + NodeState currentNodeState = builder.build(); + nodeBuilder = currentNodeState.builder(); + + //Unset the reindex flag first because first build would have set it . + nodeBuilder.setProperty(REINDEX_PROPERTY_NAME, false); + builder = new IndexDefinitionBuilder(nodeBuilder); + //Add the facets child node now + builder.getBuilderTree().addChild(PROP_FACETS); + currentNodeState = builder.build(); + assertFalse(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME)); + assertTrue(currentNodeState.getBoolean(PROP_REFRESH_DEFN)); + + // Now test deleting the facets node should also not set the reindexing flag + currentNodeState = builder.build(); + nodeBuilder = currentNodeState.builder(); + + nodeBuilder.setProperty(PROP_REFRESH_DEFN,false); + builder = new IndexDefinitionBuilder(nodeBuilder); + builder.getBuilderTree().getChild(PROP_FACETS).remove(); + + currentNodeState = builder.build(); + assertFalse(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME)); + assertTrue(currentNodeState.getBoolean(PROP_REFRESH_DEFN)); + } + + @Test + public void noReindexWhenFacetConfigChanged_topChildren() throws Exception { + builder.indexRule("nt:base") + .property("foo1").facets(); + + builder.getBuilderTree().addChild(PROP_FACETS); + NodeState currentNodeState = builder.build(); + nodeBuilder = currentNodeState.builder(); + //Unset the reindex flag first because first build would have set it . + nodeBuilder.setProperty(REINDEX_PROPERTY_NAME, false); + builder = new IndexDefinitionBuilder(nodeBuilder); + + //Add top Children prop on facets node + builder.getBuilderTree().getChild(PROP_FACETS).setProperty(FulltextIndexConstants.PROP_FACETS_TOP_CHILDREN,100); + currentNodeState = builder.build(); + + assertFalse(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME)); + assertTrue(currentNodeState.getBoolean(PROP_REFRESH_DEFN)); + nodeBuilder = currentNodeState.builder(); + + //Now test with changing the value - this too shouldn't set the reindexing flag + nodeBuilder.setProperty(PROP_REFRESH_DEFN, false); + builder = new IndexDefinitionBuilder(nodeBuilder); + + builder.getBuilderTree().getChild(PROP_FACETS).setProperty(FulltextIndexConstants.PROP_FACETS_TOP_CHILDREN,200); + currentNodeState = builder.build(); + assertFalse(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME)); + assertTrue(currentNodeState.getBoolean(PROP_REFRESH_DEFN)); + } + + @Test + public void noReindexWhenFacetConfigChanged_secure() throws Exception { + builder.indexRule("nt:base") + .property("foo1").facets(); + + builder.getBuilderTree().addChild(PROP_FACETS); + + NodeState currentNodeState = builder.build(); + nodeBuilder = currentNodeState.builder(); + + //Unset the reindex flag first because first build would have set it . + nodeBuilder.setProperty(REINDEX_PROPERTY_NAME, false); + builder = new IndexDefinitionBuilder(nodeBuilder); + + //Add top secure prop on facets node + builder.getBuilderTree().getChild(PROP_FACETS).setProperty(FulltextIndexConstants.PROP_SECURE_FACETS,FulltextIndexConstants.PROP_SECURE_FACETS_VALUE_SECURE); + currentNodeState = builder.build(); + assertFalse(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME)); + assertTrue(currentNodeState.getBoolean(PROP_REFRESH_DEFN)); + nodeBuilder = currentNodeState.builder(); + nodeBuilder.setProperty(PROP_REFRESH_DEFN,false); + + //Now test with changing the value - this too shouldn't set the reindexing flag + builder = new IndexDefinitionBuilder(nodeBuilder); + + builder.getBuilderTree().getChild(PROP_FACETS).setProperty(FulltextIndexConstants.PROP_SECURE_FACETS,FulltextIndexConstants.PROP_SECURE_FACETS_VALUE_INSECURE); + currentNodeState = builder.build(); + assertFalse(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME)); + assertTrue(currentNodeState.getBoolean(PROP_REFRESH_DEFN)); + } + + @Test + public void noReindexWhenFacetConfigChanged_sampleSize() throws Exception { + builder.indexRule("nt:base") + .property("foo1").facets(); + + builder.getBuilderTree().addChild(PROP_FACETS); + + NodeState currentNodeState = builder.build(); + nodeBuilder = currentNodeState.builder(); + + //Unset the reindex flag first because first build would have set it . + nodeBuilder.setProperty(REINDEX_PROPERTY_NAME, false); + builder = new IndexDefinitionBuilder(nodeBuilder); + + //Add top sample size prop on facets node + builder.getBuilderTree().getChild(PROP_FACETS).setProperty(FulltextIndexConstants.PROP_STATISTICAL_FACET_SAMPLE_SIZE,1000); + currentNodeState = builder.build(); + assertTrue(currentNodeState.getBoolean(PROP_REFRESH_DEFN)); + assertFalse(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME)); + nodeBuilder = currentNodeState.builder(); + nodeBuilder.setProperty(PROP_REFRESH_DEFN,false); + + //Now test with changing the value - this too shouldn't set the reindexing flag + builder = new IndexDefinitionBuilder(nodeBuilder); + + builder.getBuilderTree().getChild(PROP_FACETS).setProperty(FulltextIndexConstants.PROP_STATISTICAL_FACET_SAMPLE_SIZE,2000); + currentNodeState = builder.build(); + assertFalse(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME)); + assertTrue(currentNodeState.getBoolean(PROP_REFRESH_DEFN)); + } + @Test public void propRuleCustomName() throws Exception{ builder.indexRule("nt:base").property("foo").property("bar");