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,30 +107,35 @@ 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); - if (property != null){ - if(PropertyValues.match(property, value)){ + if (property != null) { + if (value.isArray()) { + // let query engine handle multi-valued look ups + // simply return all nodes that have this property paths.add(""); + } else { + // does it match any of the values of this property? + for (int i = 0; i < property.count(); i++) { + if (property.getValue(value.getType(), i).equals(value.getValue(value.getType()))) { + paths.add(""); + // no need to check for more matches in this property + break; + } + } } } @@ -154,4 +157,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,9 +93,12 @@ .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) + .setProperty("type", "property") + .setProperty("reindex", true) .setProperty("propertyNames", "jcr:primaryType"); // FIXME: user-mgt related unique properties (rep:authorizableId, rep:principalName) are implementation detail and not generic for repo // FIXME OAK-396: rep:principalName only needs to be unique if defined with user/group nodes -> add defining nt-info to uniqueness constraint otherwise ac-editing will fail. @@ -103,11 +106,13 @@ .setProperty("jcr:primaryType", "oak:queryIndexDefinition", Type.NAME) .setProperty("type", "property") .setProperty("propertyNames", "rep:authorizableId") + .setProperty("reindex", true) .setProperty("unique", true); index.child("principalName") .setProperty("jcr:primaryType", "oak:queryIndexDefinition", Type.NAME) .setProperty("type", "property") .setProperty("propertyNames", "rep:principalName") + .setProperty("reindex", true) .setProperty("unique", true); } try { 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