IndexDefinition implements Aggregate.AggregateMapper { @Nullable public IndexingRule getApplicableIndexingRule(String primaryNodeType) { List<IndexingRule> rules = null; List<IndexingRule> r = indexRules.get(primaryNodeType); if (r != null) { rules = new ArrayList<IndexingRule>(); rules.addAll(r); } if (rules != null) { for (IndexingRule rule : rules) { if (rule.appliesTo(primaryNodeType)) { return rule; } } } return null; } IndexDefinition(NodeState root, NodeState defn, String indexPath); protected  IndexDefinition(NodeState root, NodeState defn, IndexFormatVersion version, String uid, String indexPath); boolean isTestMode(); static Builder newBuilder(NodeState root, NodeState defn, String indexPath); NodeState getDefinitionNodeState(); boolean isEnabled(); boolean isFullTextEnabled(); String getFunctionName(); boolean hasFunctionDefined(); int getBlobSize(); long getReindexCount(); long getEntryCount(); int getSuggesterUpdateFrequencyMinutes(); boolean isEntryCountDefined(); double getCostPerEntry(); double getCostPerExecution(); long getFulltextEntryCount(long numOfDocs); boolean isDeprecated(); IndexFormatVersion getVersion(); boolean isOfOldFormat(); boolean evaluatePathRestrictions(); boolean hasCustomTikaConfig(); InputStream getTikaConfig(); String getTikaMappedMimeType(String type); String getIndexName(); String[] getIndexTags(); int getMaxExtractLength(); String getScorerProviderName(); PathFilter getPathFilter(); @Nullable String[] getQueryPaths(); @Nullable String getUniqueId(); boolean isNRTIndexingEnabled(); boolean isSyncIndexingEnabled(); boolean hasSyncPropertyDefinitions(); boolean isPureNodeTypeIndex(); static boolean hasPersistedIndex(NodeState definition); static boolean isDisableStoredIndexDefinition(); static void setDisableStoredIndexDefinition(boolean disableStoredIndexDefinitionDefault); Set<String> getRelativeNodeNames(); boolean indexesRelativeNodes(); @Override String toString(); @Nullable Aggregate getAggregate(String nodeType); boolean hasMatchingNodeTypeReg(NodeState root); List<IndexingRule> getDefinedRules(); @Nullable IndexingRule getApplicableIndexingRule(String primaryNodeType); @Nullable IndexingRule getApplicableIndexingRule(NodeState state); Pattern getPropertyRegex(); boolean isSuggestEnabled(); boolean isSpellcheckEnabled(); String getIndexPath(); boolean isSuggestAnalyzed(); SecureFacetConfiguration getSecureFacetConfiguration(); int getNumberOfTopFacets(); static NodeBuilder updateDefinition(NodeBuilder indexDefn); static NodeBuilder updateDefinition(NodeBuilder indexDefn, String indexPath); static boolean supportsSyncOrNRTIndexing(NodeBuilder defn); static final int DEFAULT_BLOB_SIZE; static final long DEFAULT_ENTRY_COUNT; static final int DEFAULT_MAX_FIELD_LENGTH; static final int DEFAULT_MAX_EXTRACT_LENGTH; static final String INDEX_VERSION; static final String INDEX_DEFINITION_NODE; static final String STATUS_NODE; static final String STATUS_LAST_UPDATED; static final String CREATION_TIMESTAMP; static final String REINDEX_COMPLETION_TIMESTAMP; static final String FAILED_DOC_PATHS; static final String PROP_UID; static final int DEFAULT_SUGGESTER_UPDATE_FREQUENCY_MINUTES; static final OrderEntry NATIVE_SORT_ORDER; }
@Test public void propertyDefinition() throws Exception{ builder.child(PROP_NODE).child("foo").setProperty(FulltextIndexConstants.PROP_TYPE, PropertyType.TYPENAME_DATE); builder.setProperty(createProperty(INCLUDE_PROPERTY_NAMES, of("foo" , "bar"), STRINGS)); IndexDefinition idxDefn = new IndexDefinition(root, builder.getNodeState(), "/foo"); IndexDefinition.IndexingRule rule = idxDefn.getApplicableIndexingRule(NT_BASE); assertTrue(rule.isIndexed("foo")); assertTrue(rule.isIndexed("bar")); assertEquals(PropertyType.DATE, rule.getConfig("foo").getType()); }
@Test public void propertyDefinitionWithExcludes() throws Exception{ builder.child(PROP_NODE).child("foo").setProperty(FulltextIndexConstants.PROP_TYPE, PropertyType.TYPENAME_DATE); IndexDefinition idxDefn = new IndexDefinition(root, builder.getNodeState(), "/foo"); IndexDefinition.IndexingRule rule = idxDefn.getApplicableIndexingRule(NT_BASE); assertTrue(rule.isIndexed("foo")); assertTrue(rule.isIndexed("bar")); assertEquals(PropertyType.DATE, rule.getConfig("foo").getType()); }
@Test public void indexRuleSanity() throws Exception{ NodeBuilder rules = builder.child(INDEX_RULES); rules.child("nt:folder").setProperty(FulltextIndexConstants.FIELD_BOOST, 2.0); TestUtil.child(rules, "nt:folder/properties/prop1") .setProperty(FulltextIndexConstants.FIELD_BOOST, 3.0) .setProperty(FulltextIndexConstants.PROP_TYPE, PropertyType.TYPENAME_BOOLEAN); IndexDefinition defn = new IndexDefinition(root, builder.getNodeState(), "/foo"); assertNull(defn.getApplicableIndexingRule(asState(newNode("nt:base")))); IndexingRule rule1 = defn.getApplicableIndexingRule(asState(newNode("nt:folder"))); assertNotNull(rule1); assertEquals(2.0f, rule1.boost, 0); assertTrue(rule1.isIndexed("prop1")); assertFalse(rule1.isIndexed("prop2")); PropertyDefinition pd = rule1.getConfig("prop1"); assertEquals(3.0f, pd.boost, 0); assertEquals(PropertyType.BOOLEAN, pd.getType()); }
@Test public void indexRuleInheritance() throws Exception{ NodeBuilder rules = builder.child(INDEX_RULES); builder.setProperty(PROP_NAME, "testIndex"); rules.child("nt:hierarchyNode").setProperty(FulltextIndexConstants.FIELD_BOOST, 2.0); IndexDefinition defn = new IndexDefinition(root, builder.getNodeState(), "/foo"); assertNull(defn.getApplicableIndexingRule(asState(newNode("nt:base")))); assertNotNull(defn.getApplicableIndexingRule(asState(newNode("nt:hierarchyNode")))); assertNotNull(defn.getApplicableIndexingRule(asState(newNode("nt:folder")))); }
@Test public void indexRuleMixin() throws Exception{ NodeBuilder rules = builder.child(INDEX_RULES); rules.child("mix:title"); TestUtil.child(rules, "mix:title/properties/jcr:title") .setProperty(FulltextIndexConstants.FIELD_BOOST, 3.0); IndexDefinition defn = new IndexDefinition(root, builder.getNodeState(), "/foo"); assertNotNull(defn.getApplicableIndexingRule(asState(newNode("nt:folder", "mix:title")))); assertNull(defn.getApplicableIndexingRule(asState(newNode("nt:folder")))); }
@Test public void indexRuleMixinInheritance() throws Exception{ NodeBuilder rules = builder.child(INDEX_RULES); rules.child("mix:mimeType"); TestUtil.child(rules, "mix:mimeType/properties/jcr:mimeType") .setProperty(FulltextIndexConstants.FIELD_BOOST, 3.0); IndexDefinition defn = new IndexDefinition(root, builder.getNodeState(), "/foo"); assertNotNull(defn.getApplicableIndexingRule(asState(newNode("nt:folder", "mix:mimeType")))); assertNull(defn.getApplicableIndexingRule(asState(newNode("nt:folder")))); assertNotNull(defn.getApplicableIndexingRule(asState(newNode("nt:resource")))); }
@Test public void indexRuleInheritanceDisabled() throws Exception{ NodeBuilder rules = builder.child(INDEX_RULES); builder.setProperty(PROP_NAME, "testIndex"); rules.child("nt:hierarchyNode") .setProperty(FulltextIndexConstants.FIELD_BOOST, 2.0) .setProperty(FulltextIndexConstants.RULE_INHERITED, false); IndexDefinition defn = new IndexDefinition(root, builder.getNodeState(), "/foo"); assertNull(defn.getApplicableIndexingRule(asState(newNode("nt:base")))); assertNotNull(defn.getApplicableIndexingRule(asState(newNode("nt:hierarchyNode")))); assertNull("nt:folder should not be index as rule is not inheritable", defn.getApplicableIndexingRule(asState(newNode("nt:folder")))); }
@Test public void indexRuleWithPropertyRegEx() throws Exception{ NodeBuilder rules = builder.child(INDEX_RULES); rules.child("nt:folder"); TestUtil.child(rules, "nt:folder/properties/prop1") .setProperty(FulltextIndexConstants.FIELD_BOOST, 3.0); TestUtil.child(rules, "nt:folder/properties/prop2") .setProperty(PROP_NAME, "foo.*") .setProperty(FulltextIndexConstants.PROP_IS_REGEX, true) .setProperty(FulltextIndexConstants.FIELD_BOOST, 4.0); IndexDefinition defn = new IndexDefinition(root, builder.getNodeState(), "/foo"); IndexingRule rule1 = defn.getApplicableIndexingRule(asState(newNode("nt:folder"))); assertNotNull(rule1); assertTrue(rule1.isIndexed("prop1")); assertFalse(rule1.isIndexed("prop2")); assertTrue(rule1.isIndexed("fooProp")); PropertyDefinition pd = rule1.getConfig("fooProp2"); assertEquals(4.0f, pd.boost, 0); }
@Test public void indexRuleWithPropertyRegEx2() throws Exception{ NodeBuilder rules = builder.child(INDEX_RULES); rules.child("nt:folder"); TestUtil.child(rules, "nt:folder/properties/prop1") .setProperty(PROP_NAME, ".*") .setProperty(FulltextIndexConstants.PROP_IS_REGEX, true); TestUtil.child(rules, "nt:folder/properties/prop2") .setProperty(PROP_NAME, "metadata/.*") .setProperty(FulltextIndexConstants.PROP_IS_REGEX, true) .setProperty(FulltextIndexConstants.FIELD_BOOST, 4.0); IndexDefinition defn = new IndexDefinition(root, builder.getNodeState(), "/foo"); IndexingRule rule1 = defn.getApplicableIndexingRule(asState(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"); TestUtil.child(rules, "nt:folder/properties/prop1") .setProperty(PROP_NAME, "foo.*") .setProperty(FulltextIndexConstants.PROP_IS_REGEX, true) .setProperty(FulltextIndexConstants.FIELD_BOOST, 3.0); TestUtil.child(rules, "nt:folder/properties/prop2") .setProperty(PROP_NAME, ".*") .setProperty(FulltextIndexConstants.PROP_IS_REGEX, true) .setProperty(FulltextIndexConstants.FIELD_BOOST, 4.0); rules.child("nt:folder").child(PROP_NODE).setProperty(OAK_CHILD_ORDER, ImmutableList.of("prop2", "prop1"), NAMES); IndexDefinition defn = new IndexDefinition(root, builder.getNodeState(), "/foo"); IndexingRule rule1 = defn.getApplicableIndexingRule(asState(newNode("nt:folder"))); assertNotNull(rule1); assertTrue(rule1.isIndexed("prop1")); assertTrue(rule1.isIndexed("fooProp")); assertEquals(4.0f, rule1.getConfig("bazProp2").boost, 0); assertEquals(4.0f, rule1.getConfig("fooProp").boost, 0); rules.child("nt:folder").child(PROP_NODE).setProperty(OAK_CHILD_ORDER, ImmutableList.of("prop1", "prop2"), NAMES); defn = new IndexDefinition(root, builder.getNodeState(), "/foo"); rule1 = defn.getApplicableIndexingRule(asState(newNode("nt:folder"))); assertEquals(3.0f, rule1.getConfig("fooProp").boost, 0); }
@Test public void propertyConfigCaseInsensitive() throws Exception{ NodeBuilder rules = builder.child(INDEX_RULES); rules.child("nt:folder"); TestUtil.child(rules, "nt:folder/properties/foo") .setProperty(PROP_NAME, "Foo") .setProperty(FulltextIndexConstants.PROP_PROPERTY_INDEX, true); TestUtil.child(rules, "nt:folder/properties/bar") .setProperty(PROP_NAME, "BAR") .setProperty(FulltextIndexConstants.PROP_PROPERTY_INDEX, true); IndexDefinition defn = new IndexDefinition(root, builder.getNodeState(), "/foo"); IndexingRule rule1 = defn.getApplicableIndexingRule(asState(newNode("nt:folder"))); assertNotNull(rule1); assertTrue(rule1.isIndexed("Foo")); assertTrue(rule1.isIndexed("foo")); assertTrue(rule1.isIndexed("fOO")); assertTrue(rule1.isIndexed("bar")); assertFalse(rule1.isIndexed("baz")); }
@Test public void skipTokenization() throws Exception{ NodeBuilder rules = builder.child(INDEX_RULES); rules.child("nt:folder"); TestUtil.child(rules, "nt:folder/properties/prop2") .setProperty(PROP_NAME, ".*") .setProperty(FulltextIndexConstants.PROP_IS_REGEX, true) .setProperty(FulltextIndexConstants.PROP_ANALYZED, true); IndexDefinition defn = new IndexDefinition(root, builder.getNodeState(), "/foo"); IndexingRule rule = defn.getApplicableIndexingRule(asState(newNode("nt:folder"))); assertFalse(rule.getConfig("foo").skipTokenization("foo")); assertTrue(rule.getConfig(JcrConstants.JCR_UUID).skipTokenization(JcrConstants.JCR_UUID)); }
@Test public void nullCheckEnabledWithTestNode() throws Exception{ NodeBuilder rules = builder.child(INDEX_RULES); TestUtil.child(rules, "oak:TestNode/properties/prop2") .setProperty(PROP_NAME, "foo") .setProperty(FulltextIndexConstants.PROP_NULL_CHECK_ENABLED, true); root = registerTestNodeType(builder).getNodeState(); IndexDefinition idxDefn = new IndexDefinition(root, builder.getNodeState(), "/foo"); assertTrue(!idxDefn.getApplicableIndexingRule(TestUtil.NT_TEST).getNullCheckEnabledProperties().isEmpty()); }
@Test public void notNullCheckEnabledWithTestNode() throws Exception{ NodeBuilder rules = builder.child(INDEX_RULES); TestUtil.child(rules, "oak:TestNode/properties/prop2") .setProperty(PROP_NAME, "foo") .setProperty(FulltextIndexConstants.PROP_NOT_NULL_CHECK_ENABLED, true); root = registerTestNodeType(builder).getNodeState(); IndexDefinition idxDefn = new IndexDefinition(root, builder.getNodeState(), "/foo"); assertTrue(!idxDefn.getApplicableIndexingRule(TestUtil.NT_TEST).getNotNullCheckEnabledProperties().isEmpty()); }
@Test public void analyzedEnabledForBoostedField() throws Exception { NodeBuilder rules = builder.child(INDEX_RULES); rules.child("nt:folder"); TestUtil.child(rules, "nt:folder/properties/prop1") .setProperty(FulltextIndexConstants.FIELD_BOOST, 3.0) .setProperty(FulltextIndexConstants.PROP_NODE_SCOPE_INDEX, true); TestUtil.child(rules, "nt:folder/properties/prop2") .setProperty(FulltextIndexConstants.PROP_ANALYZED, true) .setProperty(FulltextIndexConstants.PROP_NODE_SCOPE_INDEX, true); TestUtil.child(rules, "nt:folder/properties/prop3") .setProperty(FulltextIndexConstants.PROP_PROPERTY_INDEX, true) .setProperty(FulltextIndexConstants.PROP_NODE_SCOPE_INDEX, true); IndexDefinition defn = new IndexDefinition(root, builder.getNodeState(), "/foo"); IndexingRule rule1 = defn.getApplicableIndexingRule(asState(newNode("nt:folder"))); assertNotNull(rule1); PropertyDefinition pd = rule1.getConfig("prop1"); assertEquals(3.0f, pd.boost, 0); assertTrue("Analyzed should be assumed to be true for boosted fields", pd.analyzed); assertFalse(rule1.getConfig("prop3").analyzed); assertEquals(2, rule1.getNodeScopeAnalyzedProps().size()); }
@Test public void nodeFullTextIndexed_Regex() throws Exception { NodeBuilder rules = builder.child(INDEX_RULES); rules.child("nt:folder"); TestUtil.child(rules, "nt:folder/properties/prop1") .setProperty(PROP_NAME, ".*") .setProperty(FulltextIndexConstants.PROP_ANALYZED, true) .setProperty(FulltextIndexConstants.PROP_IS_REGEX, true); IndexDefinition defn = new IndexDefinition(root, builder.getNodeState(), "/foo"); IndexingRule rule = defn.getApplicableIndexingRule(asState(newNode("nt:folder"))); assertNotNull(rule); assertFalse(rule.isNodeFullTextIndexed()); TestUtil.child(rules, "nt:folder/properties/prop1") .setProperty(FulltextIndexConstants.PROP_NODE_SCOPE_INDEX, true); defn = new IndexDefinition(root, builder.getNodeState(), "/foo"); rule = defn.getApplicableIndexingRule(asState(newNode("nt:folder"))); assertTrue(rule.isNodeFullTextIndexed()); assertTrue(rule.indexesAllNodesOfMatchingType()); }
@Test public void nodeFullTextIndexed_Simple() throws Exception { NodeBuilder rules = builder.child(INDEX_RULES); rules.child("nt:folder"); TestUtil.child(rules, "nt:folder/properties/prop1") .setProperty(PROP_NAME, "foo") .setProperty(FulltextIndexConstants.PROP_ANALYZED, true); IndexDefinition defn = new IndexDefinition(root, builder.getNodeState(), "/foo"); IndexingRule rule = defn.getApplicableIndexingRule(asState(newNode("nt:folder"))); assertNotNull(rule); assertFalse(rule.isNodeFullTextIndexed()); TestUtil.child(rules, "nt:folder/properties/prop1") .setProperty(FulltextIndexConstants.PROP_NODE_SCOPE_INDEX, true); defn = new IndexDefinition(root, builder.getNodeState(), "/foo"); rule = defn.getApplicableIndexingRule(asState(newNode("nt:folder"))); assertTrue(rule.isNodeFullTextIndexed()); assertTrue(rule.indexesAllNodesOfMatchingType()); }
@Test public void nodeFullTextIndexed_Aggregates() throws Exception { NodeBuilder rules = builder.child(INDEX_RULES); rules.child("nt:folder"); TestUtil.child(rules, "nt:folder/properties/prop1") .setProperty(PROP_NAME, "foo") .setProperty(FulltextIndexConstants.PROP_ANALYZED, true); NodeBuilder aggregates = builder.child(FulltextIndexConstants.AGGREGATES); NodeBuilder aggFolder = aggregates.child("nt:folder"); aggFolder.child("i1").setProperty(FulltextIndexConstants.AGG_PATH, "*"); IndexDefinition defn = new IndexDefinition(root, builder.getNodeState(), "/foo"); IndexingRule rule = defn.getApplicableIndexingRule(asState(newNode("nt:folder"))); assertNotNull(rule); assertTrue(rule.isNodeFullTextIndexed()); assertTrue(rule.indexesAllNodesOfMatchingType()); }
@Test public void nonIndexPropShouldHaveAllOtherConfigDisabled() throws Exception{ NodeBuilder rules = builder.child(INDEX_RULES); rules.child("nt:folder"); TestUtil.child(rules, "nt:folder/properties/prop1") .setProperty(PROP_NAME, "foo") .setProperty(FulltextIndexConstants.PROP_INDEX, false) .setProperty(FulltextIndexConstants.PROP_USE_IN_SUGGEST, true) .setProperty(FulltextIndexConstants.PROP_USE_IN_SPELLCHECK, true) .setProperty(FulltextIndexConstants.PROP_NULL_CHECK_ENABLED, true) .setProperty(FulltextIndexConstants.PROP_NOT_NULL_CHECK_ENABLED, true) .setProperty(FulltextIndexConstants.PROP_USE_IN_EXCERPT, true) .setProperty(FulltextIndexConstants.PROP_NODE_SCOPE_INDEX, true) .setProperty(FulltextIndexConstants.PROP_ORDERED, true) .setProperty(FulltextIndexConstants.PROP_ANALYZED, true); IndexDefinition defn = new IndexDefinition(root, builder.getNodeState(), "/foo"); IndexingRule rule = defn.getApplicableIndexingRule(asState(newNode("nt:folder"))); assertNotNull(rule); PropertyDefinition pd = rule.getConfig("foo"); assertFalse(pd.index); assertFalse(pd.nodeScopeIndex); assertFalse(pd.useInSuggest); assertFalse(pd.useInSpellcheck); assertFalse(pd.nullCheckEnabled); assertFalse(pd.notNullCheckEnabled); assertFalse(pd.stored); assertFalse(pd.ordered); assertFalse(pd.analyzed); }