jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1430194 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2: Property2IndexLookup.java strategy/ContentMirrorStoreStrategy.java strategy/IndexStoreStrategy.java
Date Tue, 08 Jan 2013 09:51:33 GMT
Author: thomasm
Date: Tue Jan  8 09:51:33 2013
New Revision: 1430194

URL: http://svn.apache.org/viewvc?rev=1430194&view=rev
Log:
OAK-537 Property2Index: assume the index exists

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexLookup.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/ContentMirrorStoreStrategy.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/IndexStoreStrategy.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexLookup.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexLookup.java?rev=1430194&r1=1430193&r2=1430194&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexLookup.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexLookup.java
Tue Jan  8 09:51:33 2013
@@ -81,7 +81,7 @@ public class Property2IndexLookup {
         NodeState node = root;
         Iterator<String> it = PathUtils.elements(path).iterator();
         while (true) {
-            if (getIndexDefinitionNode(node, name) != null) {
+            if (getIndexDataNode(node, name) != null) {
                 return true;
             }
             if (!it.hasNext()) {
@@ -114,12 +114,11 @@ public class Property2IndexLookup {
      * @return the set of matched paths
      */
     public Set<String> find(String name, PropertyValue value) {
-        NodeState state = getIndexDefinitionNode(root, name);
-        if (state == null || state.getChildNode(":index") == null) {
+        NodeState state = getIndexDataNode(root, name);
+        if (state == null) {
             throw new IllegalArgumentException("No index for " + name);
         }
         Set<String> paths = Sets.newHashSet();
-        state = state.getChildNode(":index");
         if (value == null) {
             paths.addAll(store.find(state, null));
         } else {
@@ -131,11 +130,10 @@ public class Property2IndexLookup {
     public double getCost(String name, PropertyValue value) {
         // TODO the cost method is currently reading all the data - 
         // is not supposed to do that, it is only supposed to estimate
-        NodeState state = getIndexDefinitionNode(root, name);
-        if (state == null || state.getChildNode(":index") == null) {
+        NodeState state = getIndexDataNode(root, name);
+        if (state == null) {
             return Double.POSITIVE_INFINITY;
         }
-        state = state.getChildNode(":index");
         double cost;
         if (value == null) {
             cost = store.count(state, null);
@@ -146,14 +144,15 @@ public class Property2IndexLookup {
     }
 
     /**
-     * Get the node with the index definition node for the given property.
+     * Get the node with the index data for the given property, if there is an
+     * applicable index with data.
      * 
      * @param name the property name
-     * @return the node where the index definition is stored, or null if no
-     *         index definition node was found
+     * @return the node where the index data is stored, or null if no index
+     *         definition or index data node was found
      */
     @Nullable
-    private static NodeState getIndexDefinitionNode(NodeState node, String name) {
+    private static NodeState getIndexDataNode(NodeState node, String name) {
         NodeState state = node.getChildNode(INDEX_DEFINITIONS_NAME);
         if (state != null) {
             for (ChildNodeEntry entry : state.getChildNodeEntries()) {
@@ -165,7 +164,11 @@ public class Property2IndexLookup {
                 if (names != null) {
                     for (int i = 0; i < names.count(); i++) {
                         if (name.equals(names.getValue(Type.STRING, i))) {
-                            return entry.getNodeState();
+                            NodeState indexDef = entry.getNodeState();
+                            NodeState index = indexDef.getChildNode(":index");
+                            if (index != null) {
+                                return index;
+                            }
                         }
                     }
                 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/ContentMirrorStoreStrategy.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/ContentMirrorStoreStrategy.java?rev=1430194&r1=1430193&r2=1430194&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/ContentMirrorStoreStrategy.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/ContentMirrorStoreStrategy.java
Tue Jan  8 09:51:33 2013
@@ -123,9 +123,6 @@ public class ContentMirrorStoreStrategy 
     }
 
     static int countMatchingLeaves(NodeState state) {
-        if (state == null) {
-            return 0;
-        }
         int count = 0;
         if (state.getProperty("match") != null) {
             count++;
@@ -140,11 +137,8 @@ public class ContentMirrorStoreStrategy 
     public Set<String> find(NodeState index, Iterable<String> values) {
         Set<String> paths = new HashSet<String>();
         if (values == null) {
-            if (index != null) {
-                // We have an entry for this value, so use it
-                for (ChildNodeEntry child : index.getChildNodeEntries()) {
-                    getMatchingPaths(child.getNodeState(), "", paths);
-                }
+            for (ChildNodeEntry child : index.getChildNodeEntries()) {
+                getMatchingPaths(child.getNodeState(), "", paths);
             }
         } else {
             for (String p : values) {
@@ -178,7 +172,10 @@ public class ContentMirrorStoreStrategy 
             count += countMatchingLeaves(index);
         } else {
             for (String p : values) {
-                count += countMatchingLeaves(index.getChildNode(p));
+                NodeState s = index.getChildNode(p);
+                if (s != null) {
+                    count += countMatchingLeaves(s);
+                }
             }
         }
         return count;

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/IndexStoreStrategy.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/IndexStoreStrategy.java?rev=1430194&r1=1430193&r2=1430194&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/IndexStoreStrategy.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/IndexStoreStrategy.java
Tue Jan  8 09:51:33 2013
@@ -55,7 +55,7 @@ public interface IndexStoreStrategy {
     /**
      * Search for a given set of values
      * 
-     * @param index index node
+     * @param index index node (may not be null)
      * @param values values to look for (null to check for property existence)
      * @return the set of paths corresponding to the given values
      */
@@ -65,7 +65,7 @@ public interface IndexStoreStrategy {
      * Count the occurrence of a given set of values. Used in calculating the
      * cost of an index.
      * 
-     * @param index the index node
+     * @param index the index node (may not be null)
      * @param values values to look for (null to check for property existence)
      * @return the aggregated count of occurrences for each provided value
      */



Mime
View raw message