public Collection<String> collectIndexNodePaths(Filter filter) { return collectIndexNodePaths(filter, true); }
public static IndexLookup getLuceneIndexLookup(NodeState root) { return new IndexLookup(root, LUCENE_INDEX_DEFINITION_PREDICATE); } }
@Override public List<IndexPlan> getPlans(Filter filter, List<OrderEntry> sortOrder, NodeState rootState) { Collection<String> indexPaths = new IndexLookup(rootState, getIndexDefinitionPredicate()) .collectIndexNodePaths(filter); List<IndexPlan> plans = Lists.newArrayListWithCapacity(indexPaths.size()); for (String path : indexPaths) { IndexNode indexNode = null; try { indexNode = acquireIndexNode(path); if (indexNode != null) { IndexPlan plan = new FulltextIndexPlanner(indexNode, path, filter, sortOrder).getPlan(); if (plan != null) { plans.add(plan); } } } catch (Exception e) { LOG.error("Error getting plan for {}", path); LOG.error("Exception:", e); } finally { if (indexNode != null) { indexNode.release(); } } } return plans; }
private void collectIndexNodePaths(NodeState nodeState, String parentPath, Collection<String> paths) { NodeState state = nodeState.getChildNode(INDEX_DEFINITIONS_NAME); for (ChildNodeEntry entry : state.getChildNodeEntries()) { if (definitionPredicate.test(entry.getNodeState())) { paths.add(createIndexNodePath(parentPath, entry.getName())); } } }
public Collection<String> collectIndexNodePaths(Filter filter, boolean recurse) { Set<String> paths = Sets.newHashSet(); collectIndexNodePaths(root, "/", paths); if (recurse) { StringBuilder sb = new StringBuilder(); NodeState nodeState = root; for (String element : PathUtils.elements(filter.getPath())) { nodeState = nodeState.getChildNode(element); collectIndexNodePaths(nodeState, sb.append("/").append(element).toString(), paths); } } return paths; }
public static IndexLookup getLuceneIndexLookup(NodeState root) { return new IndexLookup(root, LUCENE_INDEX_DEFINITION_PREDICATE); } }
@Test public void collectPathOnRootNode() throws Exception{ NodeBuilder index = builder.child(INDEX_DEFINITIONS_NAME); newLuceneIndexDefinition(index, "l1", of(TYPENAME_STRING)); newLuceneIndexDefinition(index, "l2", of(TYPENAME_STRING)); IndexLookup lookup = LuceneIndexLookupUtil.getLuceneIndexLookup(builder.getNodeState()); FilterImpl f = FilterImpl.newTestInstance(); f.restrictPath("/", Filter.PathRestriction.EXACT); assertEquals(of("/oak:index/l1", "/oak:index/l2"), lookup.collectIndexNodePaths(f)); }
/** * Returns the path of the first Lucene index node which supports * fulltext search */ public static String getOldFullTextIndexPath(NodeState root, Filter filter, IndexTracker tracker) { Collection<String> indexPaths = getLuceneIndexLookup(root).collectIndexNodePaths(filter, false); LuceneIndexNode indexNode = null; for (String path : indexPaths) { try { indexNode = tracker.acquireIndexNode(path); if (indexNode != null && indexNode.getDefinition().isFullTextEnabled() && indexNode.getDefinition().getVersion() == IndexFormatVersion.V1) { return path; } } finally { if (indexNode != null) { indexNode.release(); } } } return null; }
/** * Returns the path of the first Lucene index node which supports * fulltext search */ public static String getOldFullTextIndexPath(NodeState root, Filter filter, IndexTracker tracker) { Collection<String> indexPaths = getLuceneIndexLookup(root).collectIndexNodePaths(filter, false); LuceneIndexNode indexNode = null; for (String path : indexPaths) { try { indexNode = tracker.acquireIndexNode(path); if (indexNode != null && indexNode.getDefinition().isFullTextEnabled() && indexNode.getDefinition().getVersion() == IndexFormatVersion.V1) { return path; } } finally { if (indexNode != null) { indexNode.release(); } } } return null; }
@Test public void collectPathOnSubNode() throws Exception{ NodeBuilder index = builder.child(INDEX_DEFINITIONS_NAME); newLuceneIndexDefinition(index, "l1", of(TYPENAME_STRING)); index = builder.child("a").child(INDEX_DEFINITIONS_NAME); newLuceneIndexDefinition(index, "l2", of(TYPENAME_STRING)); index = builder.child("a").child("b").child(INDEX_DEFINITIONS_NAME); newLuceneIndexDefinition(index, "l3", of(TYPENAME_STRING)); IndexLookup lookup = LuceneIndexLookupUtil.getLuceneIndexLookup(builder.getNodeState()); FilterImpl f = FilterImpl.newTestInstance(); f.restrictPath("/a", Filter.PathRestriction.EXACT); assertEquals(of("/oak:index/l1", "/a/oak:index/l2"), lookup.collectIndexNodePaths(f)); f.restrictPath("/a/b", Filter.PathRestriction.EXACT); assertEquals(of("/oak:index/l1", "/a/oak:index/l2", "/a/b/oak:index/l3"), lookup.collectIndexNodePaths(f)); } }