TraversingIndex implements QueryIndex { @Override public double getCost(Filter filter, NodeState rootState) { if (filter.getFullTextConstraint() != null) { return Double.POSITIVE_INFINITY; } if (filter.containsNativeConstraint()) { return Double.POSITIVE_INFINITY; } Filter.PropertyRestriction facetRestriction = filter.getPropertyRestriction(REP_FACET); if (facetRestriction != null) { return Double.POSITIVE_INFINITY; } if (filter.isAlwaysFalse()) { return 0; } String path = filter.getPath(); PathRestriction restriction = filter.getPathRestriction(); switch (restriction) { case EXACT: return 1; case PARENT: if (PathUtils.denotesRoot(path)) { return 0; } return 1; case NO_RESTRICTION: case ALL_CHILDREN: case DIRECT_CHILDREN: break; default: throw new IllegalArgumentException("Unknown restriction: " + restriction); } if (!path.startsWith(JoinConditionImpl.SPECIAL_PATH_PREFIX)) { String testPath = path; if (restriction == PathRestriction.NO_RESTRICTION) { testPath = "/"; } long count = NodeCounter.getEstimatedNodeCount(rootState, testPath, true); if (count >= 0) { if (restriction == PathRestriction.DIRECT_CHILDREN) { count = count / 2; } return count; } } double nodeCount = 100000000; double nodeCountChildren = 100000; switch (restriction) { case NO_RESTRICTION: break; case ALL_CHILDREN: if (!PathUtils.denotesRoot(path)) { int depth = PathUtils.getDepth(path); for (int i = depth; i > 0; i--) { nodeCount = Math.max(nodeCountChildren * 2 - depth, nodeCount / 10); } } break; case DIRECT_CHILDREN: nodeCount = nodeCountChildren; break; default: throw new IllegalArgumentException("Unknown restriction: " + restriction); } return nodeCount; }  @Override double getMinimumCost(); @Override Cursor query(Filter filter, NodeState rootState); boolean isPotentiallySlow(Filter filter, NodeState rootState); @Override double getCost(Filter filter, NodeState rootState); @Override String getPlan(Filter filter, NodeState rootState); @Override String getIndexName();  }
@Test public void testFacets() { TraversingIndex traversingIndex = new TraversingIndex(); Filter mockFilter = mock(Filter.class); when(mockFilter.getPropertyRestriction(REP_FACET)).thenReturn(mock(Filter.PropertyRestriction.class)); Assert.assertEquals(traversingIndex.getCost(mockFilter, null), Double.POSITIVE_INFINITY, 0.001); }