Index: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndex.java =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndex.java (revision 1403294) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndex.java (working copy) @@ -38,6 +38,8 @@ import com.google.common.base.Charsets; import com.google.common.collect.Sets; +import static org.apache.jackrabbit.oak.commons.PathUtils.isAbsolute; + /** * Provides a QueryIndex that does lookups against a property index * @@ -168,7 +170,7 @@ @Override public IndexRow currentRow() { // TODO support jcr:score and possibly rep:exceprt - return new IndexRowImpl(path); + return new IndexRowImpl(isAbsolute(path) ? path : "/" + path); } } Index: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexHook.java =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexHook.java (revision 1403294) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexHook.java (working copy) @@ -57,7 +57,7 @@ } } - return after; + return builder.getNodeState(); } Index: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexLookup.java =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexLookup.java (revision 1403294) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexLookup.java (working copy) @@ -20,6 +20,8 @@ import java.util.Set; +import javax.annotation.Nullable; + import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.api.PropertyValue; import org.apache.jackrabbit.oak.api.Type; @@ -63,12 +65,8 @@ * @param path lookup path */ public boolean isIndexed(String name, String path) { - NodeState state = root.getChildNode(INDEX_DEFINITIONS_NAME); - if (state != null) { - state = state.getChildNode(name); - if (state != null) { - return true; - } + if (getIndexDefinitionNode(name) != null) { + return true; } if (path.startsWith("/")) { @@ -109,24 +107,18 @@ public Set find(String name, PropertyValue value) { Set paths = Sets.newHashSet(); - PropertyState property = null; - NodeState state = root.getChildNode(INDEX_DEFINITIONS_NAME); - if (state != null) { - state = state.getChildNode(name); - if (state != null) { - state = state.getChildNode(":index"); - if (state != null) { - //TODO what happens when I search using an mvp? - property = state.getProperty(PropertyIndex.encode(value).get(0)); + PropertyState property; + NodeState state = getIndexDefinitionNode(name); + if (state != null && state.getChildNode(":index") != null) { + state = state.getChildNode(":index"); + //TODO what happens when I search using an mvp? + property = state.getProperty(PropertyIndex.encode(value).get(0)); + if (property != null) { + // We have an entry for this value, so use it + for (String path : property.getValue(Type.STRINGS)) { + paths.add(path); } } - } - - if (property != null) { - // We have an index for this property, so use it - for (String path : property.getValue(Type.STRINGS)) { - paths.add(path); - } } else { // No index available, so first check this node for a match property = root.getProperty(name); @@ -154,4 +146,22 @@ return paths; } + @Nullable + private NodeState getIndexDefinitionNode(String name) { + NodeState state = root.getChildNode(INDEX_DEFINITIONS_NAME); + if (state != null) { + for (ChildNodeEntry entry : state.getChildNodeEntries()) { + PropertyState names = entry.getNodeState().getProperty("propertyNames"); + if (names != null) { + for (int i = 0; i < names.count(); i++) { + if (name.equals(names.getValue(Type.STRING, i))) { + return entry.getNodeState(); + } + } + } + } + } + return null; + } + } \ No newline at end of file Index: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/InitialContent.java =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/InitialContent.java (revision 1403294) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/InitialContent.java (working copy) @@ -93,6 +93,7 @@ .setProperty("jcr:primaryType", "oak:queryIndexDefinition", Type.NAME) .setProperty("type", "property") .setProperty("propertyNames", "jcr:uuid") + .setProperty("reindex", true) .setProperty("unique", true); index.child("primaryType") .setProperty("jcr:primaryType", "oak:queryIndexDefinition", Type.NAME) Index: oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexTest.java =================================================================== --- oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexTest.java (revision 1403294) +++ oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexTest.java (working copy) @@ -37,7 +37,9 @@ // Add index definition NodeBuilder builder = root.builder(); - builder.child("oak:index").child("foo"); + builder.child("oak:index").child("foo") + .setProperty("jcr:primaryType", "oak:queryIndexDefinition", Type.NAME) + .setProperty("propertyNames", "foo"); NodeState before = builder.getNodeState(); // Add some content and process it through the property index hook