private PropertyDefinition pd(String propName){ IndexDefinition defn = new IndexDefinition(root, defnb.build(), indexPath); return defn.getApplicableIndexingRule("nt:base").getConfig(propName); } }
@Nullable private IndexPlan.Builder defaultPlan() { // With OAK-7947 lucene indexes return a non-null index node to delay reading index files // While IndexNode could have a status check method but for now we are using this work-around // to check null on {@code getIndexStatistics()} as proxy indicator // (this could be avoided by returning lazy statistics) if (indexNode.getIndexStatistics() == null) { return null; } return new IndexPlan.Builder() .setCostPerExecution(definition.getCostPerExecution()) .setCostPerEntry(definition.getCostPerEntry()) .setFulltextIndex(definition.isFullTextEnabled()) .setIncludesNodeData(false) // we should not include node data .setFilter(filter) .setPathPrefix(getPathPrefix()) .setSupportsPathRestriction(definition.evaluatePathRestrictions()) .setDelayed(true) //Lucene is always async .setDeprecated(definition.isDeprecated()) .setAttribute(FulltextIndex.ATTR_PLAN_RESULT, result) .setEstimatedEntryCount(estimatedEntryCount()) .setPlanName(indexPath); }
private long estimatedEntryCount_Compat(int numOfDocs) { //Other index only compete in case of property indexes. For fulltext //index return true count so as to allow multiple property indexes //to be compared fairly FullTextExpression ft = filter.getFullTextConstraint(); if (ft != null && definition.isFullTextEnabled()){ return definition.getFulltextEntryCount(numOfDocs); } return Math.min(definition.getEntryCount(), numOfDocs); }
public IndexDefinition build(){ if (version == null){ version = determineIndexFormatVersion(defn); } if (uid == null){ uid = determineUniqueId(defn); if (uid == null && !IndexDefinition.hasPersistedIndex(defn)){ uid = DEFAULT_UID; } } NodeState indexDefnStateToUse = defn; if (!reindexMode){ indexDefnStateToUse = getIndexDefinitionState(defn); } return createInstance(indexDefnStateToUse); }
private Set<MediaType> getNonIndexedMediaTypes() { InputStream configStream = null; String configSource = null; try { if (definition.hasCustomTikaConfig()) { configSource = String.format("Custom config at %s", definition.getIndexPath()); configStream = definition.getTikaConfig(); } else { URL configUrl = FulltextIndexEditorContext.class.getResource("tika-config.xml"); configSource = "Default : tika-config.xml"; if (configUrl != null) { configStream = configUrl.openStream(); } } if (configStream != null) { return TikaParserConfig.getNonIndexedMediaTypes(configStream); } } catch (TikaException | IOException | SAXException e) { log.warn("Tika configuration not available : " + configSource, e); } finally { IOUtils.closeQuietly(configStream); } return Collections.emptySet(); }
@Test public void propertyRegExAndRelativeProperty() throws Exception{ NodeBuilder defnb = newFTIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "foo", "lucene", of(TYPENAME_STRING), of("foo"), "async"); IndexDefinition defn = new IndexDefinition(root, defnb.getNodeState(), "/foo"); assertTrue(defn.isOfOldFormat()); NodeBuilder updated = IndexDefinition.updateDefinition(defnb.getNodeState().builder()); IndexDefinition defn2 = new IndexDefinition(root, updated.getNodeState(), "/foo"); IndexingRule rule = defn2.getApplicableIndexingRule(asState(newNode("nt:base"))); assertNotNull(rule.getConfig("foo")); assertNull("Property regex used should not allow relative properties", rule.getConfig("foo/bar")); }
IndexDefinition defn = node.getDefinition(); return Collections.singletonList(planBuilder(filter) .setEstimatedEntryCount(defn.getFulltextEntryCount(node.getIndexStatistics().numDocs())) .setCostPerExecution(defn.getCostPerExecution()) .setCostPerEntry(defn.getCostPerEntry()) .setDeprecated(defn.isDeprecated()) .setAttribute(ATTR_INDEX_PATH, indexPath) .setDeprecated(defn.isDeprecated()) .build());
@Test public void costConfig() throws Exception { NodeBuilder defnb = newFTPropertyIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "foo", "lucene", of("foo"), "async"); IndexDefinition defn = new IndexDefinition(root, defnb.getNodeState(), "/foo"); assertEquals(1.0, defn.getCostPerEntry(), 0); assertEquals(1.0, defn.getCostPerExecution(), 0); assertEquals(IndexDefinition.DEFAULT_ENTRY_COUNT, defn.getEntryCount()); assertFalse(defn.isEntryCountDefined()); defnb.setProperty(FulltextIndexConstants.COST_PER_ENTRY, 2.0); defnb.setProperty(FulltextIndexConstants.COST_PER_EXECUTION, 3.0); defnb.setProperty(IndexConstants.ENTRY_COUNT_PROPERTY_NAME, 500); IndexDefinition defn2 = new IndexDefinition(root, defnb.getNodeState(), "/foo"); assertEquals(2.0, defn2.getCostPerEntry(), 0); assertEquals(3.0, defn2.getCostPerExecution(), 0); assertEquals(500, defn2.getEntryCount()); }
@Test public void fullTextEnabled() throws Exception{ IndexDefinition idxDefn = new IndexDefinition(root, builder.getNodeState(), "/foo"); IndexDefinition.IndexingRule rule = idxDefn.getApplicableIndexingRule(NT_BASE); assertTrue("By default fulltext is enabled", idxDefn.isFullTextEnabled()); assertTrue("By default everything is indexed", rule.isIndexed("foo")); assertTrue("Property types need to be defined", rule.includePropertyType(PropertyType.DATE)); assertTrue("For fulltext storage is enabled", rule.getConfig("foo").stored); assertFalse(rule.getConfig("foo").skipTokenization("foo")); assertTrue(rule.getConfig("jcr:uuid").skipTokenization("jcr:uuid")); }
if (!definition.getVersion().isAtLeast(IndexFormatVersion.V2)){ log.trace("Index is old format. Not supported"); return null; if (ft != null && !definition.isFullTextEnabled()) { return null; filter.getPath(), definition.getQueryPaths()); return null; if (definition.hasFunctionDefined() && filter.getPropertyRestriction(definition.getFunctionName()) != null) { return getNativeFunctionPlanBuilder(indexingRule.getBaseNodeType()); if (useActualEntryCount && !definition.isEntryCountDefined()) { int maxPossibleNumDocs = getMaxPossibleNumDocs(result.propDefns, filter); if (maxPossibleNumDocs >= 0) { return plan.setCostPerEntry(definition.getCostPerEntry() / costPerEntryFactor);
private boolean areAllTypesIndexed() { IndexingRule ntBaseRule = getApplicableIndexingRule(NT_BASE); return ntBaseRule != null; }
@Test public void uniqueIsSync() throws Exception{ IndexDefinitionBuilder defnb = new IndexDefinitionBuilder(); 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); }
protected IndexDefinition createInstance(NodeState indexDefnStateToUse) { return new IndexDefinition(root, indexDefnStateToUse, version, uid, indexPath); } }
@Test public void regexAllProps() { IndexDefinitionBuilder builder = new IndexDefinitionBuilder(); 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())); }
private static TikaConfigHolder initializeTikaConfig(@Nullable IndexDefinition definition) { ClassLoader current = Thread.currentThread().getContextClassLoader(); InputStream configStream = null; String configSource = null; try { Thread.currentThread().setContextClassLoader(FulltextIndexEditorContext.class.getClassLoader()); if (definition != null && definition.hasCustomTikaConfig()) { log.debug("[{}] Using custom tika config", definition.getIndexName()); configSource = "Custom config at " + definition.getIndexPath(); configStream = definition.getTikaConfig(); } else { URL configUrl = FulltextIndexEditorContext.class.getResource("tika-config.xml"); if (configUrl != null) { configSource = configUrl.toString(); configStream = configUrl.openStream(); } } if (configStream != null) { return new TikaConfigHolder(new TikaConfig(configStream), configSource); } } catch (TikaException | IOException | SAXException e) { log.warn("Tika configuration not available : " + configSource, e); } finally { IOUtils.closeQuietly(configStream); Thread.currentThread().setContextClassLoader(current); } return new TikaConfigHolder(TikaConfig.getDefaultConfig(), "Default Config"); }
@Test public void indexNameIsIndexPath() throws Exception { NodeBuilder index = builder.child(INDEX_DEFINITIONS_NAME); newLucenePropertyIndexDefinition(index, "lucene", ImmutableSet.of("foo"), null); NodeState before = builder.getNodeState(); builder.setProperty("foo", "bar"); NodeState after = builder.getNodeState(); NodeState indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY); String indexPath = "/oak:index/lucene"; IndexDefinition defn = new IndexDefinition(root, indexed.getChildNode("oak:index").getChildNode("lucene"), indexPath); assertEquals(indexPath, defn.getIndexName()); assertEquals(indexPath, defn.getIndexPath()); }
@Test public void testSuggestDisabled() throws Exception { NodeBuilder rules = builder.child(INDEX_RULES); TestUtil.child(rules, "oak:TestNode/properties/prop2") .setProperty(PROP_NAME, "foo"); root = registerTestNodeType(builder).getNodeState(); IndexDefinition idxDefn = new IndexDefinition(root, builder.getNodeState(), "/foo"); assertFalse(idxDefn.isSuggestEnabled()); }
@Test public void randomSeedWithoutOneInDef() { long seed1 = new IndexDefinition(root, root, "/foo").getSecureFacetConfiguration().getRandomSeed(); long seed2 = new IndexDefinition(root, root, "/foo").getSecureFacetConfiguration().getRandomSeed(); assertNotEquals(seed1, seed2); } }
@Test public void simpleAggregateConfig() throws Exception{ 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"); Aggregate agg = defn.getAggregate("nt:folder"); assertNotNull(agg); assertEquals(1, agg.getIncludes().size()); }
@Test public void defaultConfig() throws Exception{ IndexDefinition idxDefn = new IndexDefinition(root, builder.getNodeState(), "/foo"); assertFalse(idxDefn.hasSyncPropertyDefinitions()); }