LuceneIndexDefinition extends IndexDefinition { public static Builder newBuilder(NodeState root, NodeState defn, String indexPath){ return (Builder)new Builder() .root(root) .defn(defn) .indexPath(indexPath); } LuceneIndexDefinition(NodeState root, NodeState defn, String indexPath);   LuceneIndexDefinition(NodeState root, NodeState defn, IndexFormatVersion version, String uid, String indexPath); static Builder newBuilder(NodeState root, NodeState defn, String indexPath); boolean saveDirListing(); @Nullable Codec getCodec(); @NotNull MergePolicy getMergePolicy(); Analyzer getAnalyzer();  }
@Test public void uniqueIdForFreshIndex() throws Exception{ IndexDefinition defn = IndexDefinition.newBuilder(root, builder.getNodeState(), "/foo").build(); assertEquals("0", defn.getUniqueId()); builder.child(":status"); defn = IndexDefinition.newBuilder(root, builder.getNodeState(),"/foo").build(); assertNull(defn.getUniqueId()); }
@Test public void nodeTypeChange() throws Exception{ IndexDefinition defn = IndexDefinition.newBuilder(root, builder.getNodeState(), "/foo").build(); NodeBuilder b2 = root.builder(); TestUtil.registerNodeType(b2, TestUtil.TEST_NODE_TYPE); NodeState root2 = b2.getNodeState(); NodeBuilder b3 = root.builder(); b3.child("x"); NodeState root3 = b3.getNodeState(); assertFalse(defn.hasMatchingNodeTypeReg(root2)); assertTrue(defn.hasMatchingNodeTypeReg(root3)); }
@Test public void uniqueIsSync() throws Exception{ LuceneIndexDefinitionBuilder defnb = new LuceneIndexDefinitionBuilder(); defnb.indexRule("nt:base").property("foo").unique(); IndexDefinition defn = IndexDefinition.newBuilder(root, defnb.build(), "/foo").build(); assertTrue(defn.getApplicableIndexingRule("nt:base").getConfig("foo").sync); assertTrue(defn.getApplicableIndexingRule("nt:base").getConfig("foo").unique); assertTrue(defn.getApplicableIndexingRule("nt:base").getConfig("foo").propertyIndex); }
@Test public void syncIsProperty() throws Exception{ LuceneIndexDefinitionBuilder defnb = new LuceneIndexDefinitionBuilder(); defnb.indexRule("nt:base").property("foo").sync(); IndexDefinition defn = IndexDefinition.newBuilder(root, defnb.build(), "/foo").build(); assertTrue(defn.getApplicableIndexingRule("nt:base").getConfig("foo").sync); assertTrue(defn.getApplicableIndexingRule("nt:base").getConfig("foo").propertyIndex); }
@Test public void syncPropertyDefinitions() throws Exception{ LuceneIndexDefinitionBuilder defnb = new LuceneIndexDefinitionBuilder(); defnb.indexRule("nt:base").property("foo").sync(); IndexDefinition defn = IndexDefinition.newBuilder(root, defnb.build(), "/foo").build(); assertTrue(defn.hasSyncPropertyDefinitions()); }
@Test public void nodeTypeIndexed() throws Exception{ TestUtil.registerNodeType(builder, testNodeTypeDefn); root = builder.getNodeState(); LuceneIndexDefinitionBuilder defnb = new LuceneIndexDefinitionBuilder(); defnb.nodeTypeIndex(); defnb.indexRule("oak:TestSuperType"); IndexDefinition defn = IndexDefinition.newBuilder(root, defnb.build(), "/foo").build(); assertFalse(defn.hasSyncPropertyDefinitions()); IndexingRule ruleSuper = getRule(defn, "oak:TestSuperType"); assertNotNull(ruleSuper); assertTrue(defn.isPureNodeTypeIndex()); assertTrue(ruleSuper.getConfig(JcrConstants.JCR_PRIMARYTYPE).propertyIndex); assertTrue(ruleSuper.getConfig(JcrConstants.JCR_MIXINTYPES).propertyIndex); assertTrue(ruleSuper.indexesAllNodesOfMatchingType()); assertNotNull(getRule(defn, "oak:TestTypeA")); assertTrue(getRule(defn, "oak:TestTypeA").indexesAllNodesOfMatchingType()); assertNotNull(getRule(defn, "oak:TestTypeB")); assertNull(getRule(defn, "oak:TestMixA")); }
@Test public void nodeTypeIndexedSync() throws Exception{ TestUtil.registerNodeType(builder, testNodeTypeDefn); root = builder.getNodeState(); LuceneIndexDefinitionBuilder defnb = new LuceneIndexDefinitionBuilder(); defnb.nodeTypeIndex(); defnb.indexRule("oak:TestSuperType").sync(); IndexDefinition defn = IndexDefinition.newBuilder(root, defnb.build(), "/foo").build(); assertTrue(defn.hasSyncPropertyDefinitions()); IndexingRule ruleSuper = getRule(defn, "oak:TestSuperType"); assertNotNull(ruleSuper); assertTrue(defn.isPureNodeTypeIndex()); assertTrue(ruleSuper.getConfig(JcrConstants.JCR_PRIMARYTYPE).propertyIndex); assertTrue(ruleSuper.getConfig(JcrConstants.JCR_PRIMARYTYPE).sync); assertTrue(ruleSuper.getConfig(JcrConstants.JCR_MIXINTYPES).propertyIndex); assertTrue(ruleSuper.getConfig(JcrConstants.JCR_MIXINTYPES).sync); assertTrue(ruleSuper.indexesAllNodesOfMatchingType()); }
@Test public void nodeTypeIndexed_IgnoreOtherProps() throws Exception{ TestUtil.registerNodeType(builder, testNodeTypeDefn); root = builder.getNodeState(); LuceneIndexDefinitionBuilder defnb = new LuceneIndexDefinitionBuilder(); defnb.nodeTypeIndex(); defnb.indexRule("oak:TestSuperType").sync(); defnb.indexRule("oak:TestSuperType").property("foo").propertyIndex(); IndexDefinition defn = IndexDefinition.newBuilder(root, defnb.build(), "/foo").build(); IndexingRule ruleSuper = getRule(defn, "oak:TestSuperType"); assertNotNull(ruleSuper); assertNull(ruleSuper.getConfig("foo")); assertNotNull(ruleSuper.getConfig(JcrConstants.JCR_PRIMARYTYPE)); assertNotNull(ruleSuper.getConfig(JcrConstants.JCR_MIXINTYPES)); }
@Test public void nodeTypeIndexed_IgnoreAggregates() throws Exception{ TestUtil.registerNodeType(builder, testNodeTypeDefn); root = builder.getNodeState(); LuceneIndexDefinitionBuilder defnb = new LuceneIndexDefinitionBuilder(); defnb.nodeTypeIndex(); defnb.indexRule("oak:TestSuperType").sync(); defnb.aggregateRule("oak:TestSuperType").include("*"); IndexDefinition defn = IndexDefinition.newBuilder(root, defnb.build(), "/foo").build(); IndexingRule ruleSuper = getRule(defn, "oak:TestSuperType"); assertNotNull(ruleSuper); assertNull(ruleSuper.getConfig("foo")); assertTrue(ruleSuper.getAggregate().getIncludes().isEmpty()); assertNotNull(ruleSuper.getConfig(JcrConstants.JCR_PRIMARYTYPE)); assertNotNull(ruleSuper.getConfig(JcrConstants.JCR_MIXINTYPES)); }
@Test public void nodeTypeIndex_mixin() throws Exception{ TestUtil.registerNodeType(builder, testNodeTypeDefn); root = builder.getNodeState(); LuceneIndexDefinitionBuilder defnb = new LuceneIndexDefinitionBuilder(); defnb.nodeTypeIndex(); defnb.indexRule("oak:TestMixA"); IndexDefinition defn = IndexDefinition.newBuilder(root, defnb.build(), "/foo").build(); assertFalse(defn.hasSyncPropertyDefinitions()); assertNotNull(getRule(defn, "oak:TestTypeB")); assertTrue(getRule(defn, "oak:TestTypeB").indexesAllNodesOfMatchingType()); assertNotNull(getRule(defn, "oak:TestMixA")); assertTrue(getRule(defn, "oak:TestMixA").indexesAllNodesOfMatchingType()); assertNull(getRule(defn, "oak:TestTypeA")); assertNull(getRule(defn, "oak:TestSuperType")); }
@Test public void mixinAndPrimaryType() throws Exception{ TestUtil.registerNodeType(builder, testNodeTypeDefn); root = builder.getNodeState(); LuceneIndexDefinitionBuilder defnb = new LuceneIndexDefinitionBuilder(); 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); }
@Test public void relativeNodeNames_None() { LuceneIndexDefinitionBuilder defnb = new LuceneIndexDefinitionBuilder(); defnb.indexRule("nt:base").property("foo").propertyIndex(); IndexDefinition defn = IndexDefinition.newBuilder(root, defnb.build(), "/foo").build(); assertTrue(defn.getRelativeNodeNames().isEmpty()); assertFalse(defn.indexesRelativeNodes()); }
@Test public void relativeNodeNames_RelativeProp() { LuceneIndexDefinitionBuilder defnb = new LuceneIndexDefinitionBuilder(); defnb.indexRule("nt:base").property("jcr:content/foo").propertyIndex(); defnb.indexRule("nt:base").property("bar").propertyIndex(); IndexDefinition defn = IndexDefinition.newBuilder(root, defnb.build(), "/foo").build(); assertThat(defn.getRelativeNodeNames(), containsInAnyOrder("jcr:content")); assertTrue(defn.indexesRelativeNodes()); }
@Test public void relativeNodeNames_Aggregate() { LuceneIndexDefinitionBuilder defnb = new LuceneIndexDefinitionBuilder(); defnb.indexRule("nt:base").property("jcr:content/foo").propertyIndex(); defnb.aggregateRule("nt:base").include("jcr:content/metadata"); defnb.aggregateRule("nt:base").include("jcr:content/metadata/type/*"); defnb.aggregateRule("nt:base").include("*"); IndexDefinition defn = IndexDefinition.newBuilder(root, defnb.build(), "/foo").build(); assertThat(defn.getRelativeNodeNames(), containsInAnyOrder("jcr:content", "metadata", "type")); assertTrue(defn.indexesRelativeNodes()); }
@Test public void regexAllProps() { LuceneIndexDefinitionBuilder builder = new LuceneIndexDefinitionBuilder(); builder.indexRule("nt:base").property("p"); builder.indexRule("nt:base").property("all", FulltextIndexConstants.REGEX_ALL_PROPS, true); IndexDefinition def = IndexDefinition.newBuilder(root, builder.build(), "/foo").build(); IndexingRule rule = def.getApplicableIndexingRule(root); assertNotNull(rule); PropertyDefinition pd = rule.getConfig("p"); assertNotNull(pd); assertFalse(pd.isRegexp); assertFalse(pd.relative); assertEquals(0, pd.ancestors.length); pd = rule.getConfig("all"); assertNotNull(pd); assertTrue(pd.isRegexp); assertFalse(pd.relative); assertEquals(0, pd.ancestors.length); assertThat(rule.getAggregate().getIncludes(), is(empty())); assertFalse(rule.getAggregate().hasNodeAggregates()); List<Aggregate.Matcher> matchers = rule.getAggregate() .createMatchers(new TestRoot("/")); assertThat(matchers, is(empty())); assertThat(def.getRelativeNodeNames(), is(empty())); }