PropertyIndexLookup { @Nullable NodeState getIndexNode(NodeState node, String propertyName, Filter filter) { NodeState fallback = null; NodeState state = node.getChildNode(INDEX_DEFINITIONS_NAME); for (ChildNodeEntry entry : state.getChildNodeEntries()) { NodeState index = entry.getNodeState(); PropertyState type = index.getProperty(TYPE_PROPERTY_NAME); if (type == null || type.isArray() || !getType().equals(type.getValue(Type.STRING))) { continue; } if (contains(getNames(index, PROPERTY_NAMES), propertyName)) { NodeState indexContent = index.getChildNode(INDEX_CONTENT_NODE_NAME); if (!indexContent.exists()) { continue; } Set<String> supertypes = getSuperTypes(filter); if (index.hasProperty(DECLARING_NODE_TYPES)) { if (supertypes != null) { for (String typeName : getNames(index, DECLARING_NODE_TYPES)) { if (supertypes.contains(typeName)) { return index; } } } } else if (supertypes == null) { return index; } else if (fallback == null) { fallback = index; } } } return fallback; } PropertyIndexLookup(NodeState root);  PropertyIndexLookup(NodeState root, MountInfoProvider mountInfoProvider); boolean isIndexed(String propertyName, String path, Filter filter); Iterable<String> query(Filter filter, String propertyName,
            PropertyValue value); double getCost(Filter filter, String propertyName, PropertyValue value); static final double COST_OVERHEAD; }
@Test public void getIndexNodeForNamedDeclaringNodeTypes() throws Exception { rootBuilder.child(INDEX_DEFINITIONS_NAME).child("nodetype") .setProperty(PropertyStates.createProperty(DECLARING_NODE_TYPES, DECL_NODE_TYPES, NAMES)); commit(); Filter f = createFilter(root, "nt:unstructured"); assertNotNull("declaringNodeTypes with Name[] must find index node", new PropertyIndexLookup(root).getIndexNode(root, JCR_PRIMARYTYPE, f)); }
@Test public void getIndexNodeForStringDeclaringNodeTypes() throws Exception { rootBuilder.child(INDEX_DEFINITIONS_NAME).child("nodetype") .setProperty(PropertyStates.createProperty(DECLARING_NODE_TYPES, DECL_NODE_TYPES, STRINGS)); commit(); Filter f = createFilter(root, "nt:unstructured"); assertNotNull("declaringNodeTypes with String[] should also find index node", new PropertyIndexLookup(root).getIndexNode(root, JCR_PRIMARYTYPE, f)); }
@Test public void getIndexNodeForStringPropertyNames() throws Exception { rootBuilder.child(INDEX_DEFINITIONS_NAME).child("nodetype") .removeProperty(PROPERTY_NAMES) .setProperty(PropertyStates.createProperty(PROPERTY_NAMES, PROP_NAMES, STRINGS)); commit(); Filter f = createFilter(root, "nt:unstructured"); assertNotNull("propertyNames with String[] should also find index node", new PropertyIndexLookup(root).getIndexNode(root, JCR_PRIMARYTYPE, f)); }