private boolean canEvalPathRestrictions(IndexingRule rule) { //Opt out if one is looking for all children for '/' as its equivalent to //NO_RESTRICTION if (filter.getPathRestriction() == Filter.PathRestriction.NO_RESTRICTION || (filter.getPathRestriction() == Filter.PathRestriction.ALL_CHILDREN && PathUtils.denotesRoot(filter.getPath())) ){ return false; } //If no other restrictions is provided and query is pure //path restriction based then need to be sure that index definition at least //allows indexing all the path for given nodeType return definition.evaluatePathRestrictions() && rule.indexesAllNodesOfMatchingType(); }
switch (filter.getPathRestriction()) { case ALL_CHILDREN: if (defn.evaluatePathRestrictions()) { if ("/".equals(path)) { break; if (defn.evaluatePathRestrictions()) { BooleanQuery bq = new BooleanQuery(); bq.add(new BooleanClause(new TermQuery(newAncestorTerm(path)), BooleanClause.Occur.MUST));
switch (filter.getPathRestriction()) { case ALL_CHILDREN: if (defn.evaluatePathRestrictions()) { if ("/".equals(path)) { break; if (defn.evaluatePathRestrictions()) { BooleanQuery bq = new BooleanQuery(); bq.add(new BooleanClause(new TermQuery(newAncestorTerm(path)), BooleanClause.Occur.MUST));
private static Query addDescendantClauseIfRequired(Query query, IndexPlan plan) { Filter filter = plan.getFilter(); if (filter.getPathRestriction() == Filter.PathRestriction.ALL_CHILDREN) { String path = getPathRestriction(plan); if (!PathUtils.denotesRoot(path)) { if (getPlanResult(plan).indexDefinition.evaluatePathRestrictions()) { BooleanQuery compositeQuery = new BooleanQuery(); compositeQuery.add(query, BooleanClause.Occur.MUST); Query pathQuery = new TermQuery(newAncestorTerm(path)); compositeQuery.add(pathQuery, BooleanClause.Occur.MUST); query = compositeQuery; } else { LOG.warn("Descendant clause could not be added without path restrictions enabled. Plan: {}", plan); } } } return query; }
@Override public String[] getIndexedPaths(String indexPath, int maxLevel, int maxPathCount) throws IOException { LuceneIndexNode indexNode = null; try { if(indexPath == null){ indexPath = "/"; } indexNode = indexTracker.acquireIndexNode(indexPath); if (indexNode != null) { IndexDefinition defn = indexNode.getDefinition(); if (!defn.evaluatePathRestrictions()){ String msg = String.format("Index at [%s] does not have [%s] enabled. So paths statistics cannot " + "be determined for this index", indexPath, FulltextIndexConstants.EVALUATE_PATH_RESTRICTION); return createMsg(msg); } IndexSearcher searcher = indexNode.getSearcher(); return determineIndexedPaths(searcher, maxLevel, maxPathCount); } } finally { if (indexNode != null) { indexNode.release(); } } return new String[0]; }
@Override public String[] getIndexedPaths(String indexPath, int maxLevel, int maxPathCount) throws IOException { LuceneIndexNode indexNode = null; try { if(indexPath == null){ indexPath = "/"; } indexNode = indexTracker.acquireIndexNode(indexPath); if (indexNode != null) { IndexDefinition defn = indexNode.getDefinition(); if (!defn.evaluatePathRestrictions()){ String msg = String.format("Index at [%s] does not have [%s] enabled. So paths statistics cannot " + "be determined for this index", indexPath, FulltextIndexConstants.EVALUATE_PATH_RESTRICTION); return createMsg(msg); } IndexSearcher searcher = indexNode.getSearcher(); return determineIndexedPaths(searcher, maxLevel, maxPathCount); } } finally { if (indexNode != null) { indexNode.release(); } } return new String[0]; }
private static Query addDescendantClauseIfRequired(Query query, IndexPlan plan) { Filter filter = plan.getFilter(); if (filter.getPathRestriction() == Filter.PathRestriction.ALL_CHILDREN) { String path = getPathRestriction(plan); if (!PathUtils.denotesRoot(path)) { if (getPlanResult(plan).indexDefinition.evaluatePathRestrictions()) { BooleanQuery compositeQuery = new BooleanQuery(); compositeQuery.add(query, BooleanClause.Occur.MUST); Query pathQuery = new TermQuery(newAncestorTerm(path)); compositeQuery.add(pathQuery, BooleanClause.Occur.MUST); query = compositeQuery; } else { LOG.warn("Descendant clause could not be added without path restrictions enabled. Plan: {}", plan); } } } return query; }
if (definition.evaluatePathRestrictions()){ indexAncestors(document, path);
@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); }