You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by to...@apache.org on 2014/06/11 15:28:06 UTC

svn commit: r1601888 - in /jackrabbit/oak/trunk/oak-solr-core/src: main/java/org/apache/jackrabbit/oak/plugins/index/solr/configuration/ main/java/org/apache/jackrabbit/oak/plugins/index/solr/osgi/ main/java/org/apache/jackrabbit/oak/plugins/index/solr...

Author: tommaso
Date: Wed Jun 11 13:28:06 2014
New Revision: 1601888

URL: http://svn.apache.org/r1601888
Log:
OAK-1875 - configurable filter restrictions to be used by SolrQueryIndex

Added:
    jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndexTest.java   (with props)
Modified:
    jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/configuration/DefaultSolrConfiguration.java
    jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/configuration/OakSolrConfiguration.java
    jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/configuration/OakSolrNodeStateConfiguration.java
    jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/configuration/SolrServerConfigurationDefaults.java
    jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/osgi/OakSolrConfigurationProviderService.java
    jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndex.java
    jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/TestUtils.java
    jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexHookIT.java

Modified: jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/configuration/DefaultSolrConfiguration.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/configuration/DefaultSolrConfiguration.java?rev=1601888&r1=1601887&r2=1601888&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/configuration/DefaultSolrConfiguration.java (original)
+++ jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/configuration/DefaultSolrConfiguration.java Wed Jun 11 13:28:06 2014
@@ -87,4 +87,19 @@ public class DefaultSolrConfiguration im
         return SolrServerConfigurationDefaults.ROWS;
     }
 
+    @Override
+    public boolean useForPropertyRestrictions() {
+        return SolrServerConfigurationDefaults.PROPERTY_RESTRICTIONS;
+    }
+
+    @Override
+    public boolean useForPrimaryTypes() {
+        return SolrServerConfigurationDefaults.PRIMARY_TYPES;
+    }
+
+    @Override
+    public boolean useForPathRestrictions() {
+        return SolrServerConfigurationDefaults.PATH_RESTRICTIONS;
+    }
+
 }

Modified: jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/configuration/OakSolrConfiguration.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/configuration/OakSolrConfiguration.java?rev=1601888&r1=1601887&r2=1601888&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/configuration/OakSolrConfiguration.java (original)
+++ jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/configuration/OakSolrConfiguration.java Wed Jun 11 13:28:06 2014
@@ -31,14 +31,14 @@ public interface OakSolrConfiguration {
      * @param propertyType the {@link org.apache.jackrabbit.oak.api.Type} to be indexed / searched
      * @return a <code>String</code> representing the Solr field to be used for the given {@link org.apache.jackrabbit.oak.api.Type}.
      */
-    public String getFieldNameFor(Type<?> propertyType);
+    String getFieldNameFor(Type<?> propertyType);
 
     /**
      * Provide the field name for indexing / searching paths
      *
      * @return a <code>String</code> representing the Solr field to be used for paths.
      */
-    public String getPathField();
+    String getPathField();
 
     /**
      * Provide a field name to search over for the given {@link org.apache.jackrabbit.oak.spi.query.Filter.PathRestriction}
@@ -46,7 +46,7 @@ public interface OakSolrConfiguration {
      * @param pathRestriction the {@link org.apache.jackrabbit.oak.spi.query.Filter.PathRestriction} used for filtering search results
      * @return the field name as a <code>String</code> to be used by Solr for the given restriction
      */
-    public String getFieldForPathRestriction(Filter.PathRestriction pathRestriction);
+    String getFieldForPathRestriction(Filter.PathRestriction pathRestriction);
 
     /**
      * Provide a field name to search over for the given {@link org.apache.jackrabbit.oak.spi.query.Filter.PropertyRestriction}
@@ -54,25 +54,50 @@ public interface OakSolrConfiguration {
      * @param propertyRestriction the {@link org.apache.jackrabbit.oak.spi.query.Filter.PropertyRestriction} used for filtering search results
      * @return the field name as a <code>String</code> to be used by Solr for the given restriction
      */
-    public String getFieldForPropertyRestriction(Filter.PropertyRestriction propertyRestriction);
+    String getFieldForPropertyRestriction(Filter.PropertyRestriction propertyRestriction);
 
     /**
      * Provide the commit policy to be used with the underlying Solr instance
      *
      * @return a {@link org.apache.jackrabbit.oak.plugins.index.solr.configuration.CommitPolicy}
      */
-    public CommitPolicy getCommitPolicy();
+    CommitPolicy getCommitPolicy();
 
     /**
      * Provide a field name that is used as the default "catch all" field for searching over all the data
+     *
      * @return a <code>String</code> representing the Solr field to be used as "catch all" field
      */
-    public String getCatchAllField();
+    String getCatchAllField();
 
     /**
      * Provide the number of documents (rows) to be fetched for each Solr query
      *
      * @return an <code>int</code> for the setting of Solr rows parameter
      */
-    public int getRows();
+    int getRows();
+
+    /**
+     * Define if the Solr index should be used to address property restrictions
+     *
+     * @return <code>true</code> if {@link org.apache.jackrabbit.oak.plugins.index.solr.query.SolrQueryIndex} should be used
+     * for {@link org.apache.jackrabbit.oak.spi.query.Filter.PropertyRestriction}s
+     */
+    boolean useForPropertyRestrictions();
+
+    /**
+     * Define if the Solr index should be used to filter by primary types
+     *
+     * @return <code>true</code> if {@link org.apache.jackrabbit.oak.plugins.index.solr.query.SolrQueryIndex} should be used
+     * for filtering by primary types
+     */
+    boolean useForPrimaryTypes();
+
+    /**
+     * Define if the Solr index should be used to filter by path restrictions
+     *
+     * @return <code>true</code> if {@link org.apache.jackrabbit.oak.plugins.index.solr.query.SolrQueryIndex} should be used
+     * for filtering by {@link org.apache.jackrabbit.oak.spi.query.Filter.PathRestriction}s
+     */
+    boolean useForPathRestrictions();
 }

Modified: jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/configuration/OakSolrNodeStateConfiguration.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/configuration/OakSolrNodeStateConfiguration.java?rev=1601888&r1=1601887&r2=1601888&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/configuration/OakSolrNodeStateConfiguration.java (original)
+++ jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/configuration/OakSolrNodeStateConfiguration.java Wed Jun 11 13:28:06 2014
@@ -104,6 +104,33 @@ public abstract class OakSolrNodeStateCo
         return getIntValueFor(Properties.ROWS, SolrServerConfigurationDefaults.ROWS);
     }
 
+    @Override
+    public boolean useForPropertyRestrictions() {
+        return getBooleanValueFor(Properties.PROPERTY_RESTRICIONS, SolrServerConfigurationDefaults.PROPERTY_RESTRICTIONS);
+    }
+
+    @Override
+    public boolean useForPrimaryTypes() {
+        return getBooleanValueFor(Properties.PRIMARY_TYPES, SolrServerConfigurationDefaults.PRIMARY_TYPES);
+    }
+
+    @Override
+    public boolean useForPathRestrictions() {
+        return getBooleanValueFor(Properties.PATH_RESTRICTIONS, SolrServerConfigurationDefaults.PATH_RESTRICTIONS);
+    }
+
+    private boolean getBooleanValueFor(String propertyName, boolean defaultValue) {
+        boolean value = defaultValue;
+        NodeState configurationNodeState = getConfigurationNodeState();
+        if (configurationNodeState.exists()) {
+            PropertyState property = configurationNodeState.getProperty(propertyName);
+            if (property != null) {
+                value = property.getValue(Type.BOOLEAN);
+            }
+        }
+        return value;
+    }
+
     private int getIntValueFor(String propertyName, int defaultValue) {
         long value = defaultValue;
         NodeState configurationNodeState = getConfigurationNodeState();
@@ -145,7 +172,6 @@ public abstract class OakSolrNodeStateCo
      * Properties that may be retrieved from the configuration {@link org.apache.jackrabbit.oak.spi.state.NodeState}.
      */
     public final class Properties {
-
         public static final String SOLRHOME_PATH = "solrHomePath";
         public static final String SOLRCONFIG_PATH = "solrConfigPath";
         public static final String CONTEXT = "solrContext";
@@ -158,5 +184,8 @@ public abstract class OakSolrNodeStateCo
         public static final String CATCHALL_FIELD = "catchAllField";
         public static final String COMMIT_POLICY = "commitPolicy";
         public static final String ROWS = "rows";
+        public static final String PROPERTY_RESTRICIONS = "propertyRestrictions";
+        public static final String PRIMARY_TYPES = "primaryTypes";
+        public static final String PATH_RESTRICTIONS = "pathRestrictions";
     }
 }

Modified: jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/configuration/SolrServerConfigurationDefaults.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/configuration/SolrServerConfigurationDefaults.java?rev=1601888&r1=1601887&r2=1601888&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/configuration/SolrServerConfigurationDefaults.java (original)
+++ jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/configuration/SolrServerConfigurationDefaults.java Wed Jun 11 13:28:06 2014
@@ -37,4 +37,7 @@ public class SolrServerConfigurationDefa
     public static final String CATCHALL_FIELD = "catch_all";
 
     public static final int ROWS = 100000;
+    public static final boolean PROPERTY_RESTRICTIONS = false;
+    public static final boolean PATH_RESTRICTIONS = false;
+    public static final boolean PRIMARY_TYPES = false;
 }

Modified: jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/osgi/OakSolrConfigurationProviderService.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/osgi/OakSolrConfigurationProviderService.java?rev=1601888&r1=1601887&r2=1601888&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/osgi/OakSolrConfigurationProviderService.java (original)
+++ jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/osgi/OakSolrConfigurationProviderService.java Wed Jun 11 13:28:06 2014
@@ -42,6 +42,9 @@ public class OakSolrConfigurationProvide
     private static final String DEFAULT_PATH_FIELD = SolrServerConfigurationDefaults.PATH_FIELD_NAME;
     private static final String DEFAULT_CATCHALL_FIELD = SolrServerConfigurationDefaults.CATCHALL_FIELD;
     private static final int DEFAULT_ROWS = SolrServerConfigurationDefaults.ROWS;
+    private static final boolean DEFAULT_PATH_RESTRICTIONS = SolrServerConfigurationDefaults.PATH_RESTRICTIONS;
+    private static final boolean DEFAULT_PROPERTY_RESTRICTIONS = SolrServerConfigurationDefaults.PROPERTY_RESTRICTIONS;
+    private static final boolean DEFAULT_PRIMARY_TYPES_RESTRICTIONS = SolrServerConfigurationDefaults.PRIMARY_TYPES;
 
     @Property(value = DEFAULT_DESC_FIELD, label = "field for descendants search")
     private static final String PATH_DESCENDANTS_FIELD = "path.desc.field";
@@ -77,6 +80,15 @@ public class OakSolrConfigurationProvide
     private static final String ROWS = "rows";
 
 
+    @Property(boolValue = DEFAULT_PATH_RESTRICTIONS, label = "path restrictions")
+    private static final String PATH_RESTRICTIONS = "path.restrictions";
+
+    @Property(boolValue = DEFAULT_PROPERTY_RESTRICTIONS, label = "property restrictions")
+    private static final String PROPERTY_RESTRICTIONS = "property.restrictions";
+
+    @Property(boolValue = DEFAULT_PRIMARY_TYPES_RESTRICTIONS, label = "primary types restrictions")
+    private static final String PRIMARY_TYPES_RESTRICTIONS = "primarytypes.restrictions";
+
     private String pathChildrenFieldName;
     private String pathParentFieldName;
     private String pathDescendantsFieldName;
@@ -84,9 +96,13 @@ public class OakSolrConfigurationProvide
     private String catchAllField;
     private CommitPolicy commitPolicy;
     private int rows;
+    private boolean useForPathRestrictions;
+    private boolean useForPropertyRestrictions;
+    private boolean useForPrimaryTypes;
 
     private OakSolrConfiguration oakSolrConfiguration;
 
+
     @Activate
     protected void activate(ComponentContext componentContext) throws Exception {
         pathChildrenFieldName = String.valueOf(componentContext.getProperties().get(PATH_CHILDREN_FIELD));
@@ -96,6 +112,9 @@ public class OakSolrConfigurationProvide
         catchAllField = String.valueOf(componentContext.getProperties().get(CATCH_ALL_FIELD));
         rows = Integer.parseInt(String.valueOf(componentContext.getProperties().get(ROWS)));
         commitPolicy = CommitPolicy.valueOf(String.valueOf(componentContext.getProperties().get(COMMIT_POLICY)));
+        useForPathRestrictions = Boolean.valueOf(String.valueOf(componentContext.getProperties().get(PATH_RESTRICTIONS)));
+        useForPropertyRestrictions = Boolean.valueOf(String.valueOf(componentContext.getProperties().get(PROPERTY_RESTRICTIONS)));
+        useForPrimaryTypes = Boolean.valueOf(String.valueOf(componentContext.getProperties().get(PRIMARY_TYPES_RESTRICTIONS)));
     }
 
     @Override
@@ -152,6 +171,21 @@ public class OakSolrConfigurationProvide
                 public int getRows() {
                     return rows;
                 }
+
+                @Override
+                public boolean useForPropertyRestrictions() {
+                    return useForPropertyRestrictions;
+                }
+
+                @Override
+                public boolean useForPrimaryTypes() {
+                    return useForPrimaryTypes;
+                }
+
+                @Override
+                public boolean useForPathRestrictions() {
+                    return useForPathRestrictions;
+                }
             };
         }
         return oakSolrConfiguration;

Modified: jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndex.java?rev=1601888&r1=1601887&r2=1601888&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndex.java (original)
+++ jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndex.java Wed Jun 11 13:28:06 2014
@@ -28,7 +28,6 @@ import javax.annotation.CheckForNull;
 import com.google.common.collect.AbstractIterator;
 import com.google.common.collect.Queues;
 import com.google.common.collect.Sets;
-import org.apache.jackrabbit.JcrConstants;
 import org.apache.jackrabbit.oak.api.PropertyValue;
 import org.apache.jackrabbit.oak.plugins.index.aggregate.NodeAggregator;
 import org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration;
@@ -92,19 +91,40 @@ public class SolrQueryIndex implements F
 
     @Override
     public double getCost(Filter filter, NodeState root) {
-        if (filter.getFullTextConstraint() == null && filter.getFulltextConditions() == null ||
-                (filter.getPropertyRestrictions() != null && filter.getPropertyRestrictions().size() == 1 && filter.getPropertyRestriction(JcrConstants.JCR_UUID) != null)) {
-            return Double.POSITIVE_INFINITY;
-        }
-        int cost = 10;
-        Collection<Filter.PropertyRestriction> restrictions = filter.getPropertyRestrictions();
-        if (restrictions != null) {
-            cost /= 5;
+        // cost is inverse proportional to the number of matching restrictions, infinite if no restriction matches
+        return 10d / getMatchingFilterRestrictions(filter);
+    }
+
+    private int getMatchingFilterRestrictions(Filter filter) {
+        int match = 0;
+
+        // full text expressions OR full text conditions defined
+        if (filter.getFullTextConstraint() != null || (filter.getFulltextConditions() != null
+                && filter.getFulltextConditions().size() > 0)) {
+            match++; // full text queries have usually a significant recall
+        }
+
+        // path restriction defined AND path restrictions handled
+        if (filter.getPathRestriction() != null &&
+                !Filter.PathRestriction.NO_RESTRICTION.equals(filter.getPathRestriction())
+                && configuration.useForPathRestrictions()) {
+            match++;
+        }
+
+        // primary type restriction defined AND primary type restriction handled
+        if (filter.getPrimaryTypes() != null && filter.getPrimaryTypes().size() > 0
+                && configuration.useForPrimaryTypes()) {
+            match++;
         }
-        if (filter.getPathRestriction() != null) {
-            cost /= 2;
+
+        // property restriction OR native language property restriction defined AND property restriction handled
+        if (filter.getPropertyRestrictions() != null && filter.getPropertyRestrictions().size() > 0
+                && (filter.getPropertyRestriction(NATIVE_SOLR_QUERY) != null || filter.getPropertyRestriction(NATIVE_LUCENE_QUERY) != null
+                || configuration.useForPropertyRestrictions())) {
+            match++;
         }
-        return cost;
+
+        return match;
     }
 
     @Override
@@ -175,12 +195,8 @@ public class SolrQueryIndex implements F
                         queryBuilder.append(nativeQueryString);
                     }
                 } else {
-                    if (pr.propertyName.contains("/")) {
-                        // cannot handle child-level property restrictions
-                        continue;
-                    }
-
-                    if ("rep:excerpt".equals(pr.propertyName)) {
+                    if (!configuration.useForPropertyRestrictions() || pr.propertyName.contains("/") ||
+                            "rep:excerpt".equals(pr.propertyName)) {
                         continue;
                     }
 
@@ -226,30 +242,34 @@ public class SolrQueryIndex implements F
             }
         }
 
-        String[] pts = filter.getPrimaryTypes().toArray(new String[filter.getPrimaryTypes().size()]);
-        for (int i = 0; i < pts.length; i++) {
-            String pt = pts[i];
-            if (i == 0) {
-                queryBuilder.append("(");
-            }
-            if (i > 0 && i < pts.length) {
-                queryBuilder.append("OR ");
-            }
-            queryBuilder.append("jcr\\:primaryType").append(':').append(partialEscape(pt)).append(" ");
-            if (i == pts.length - 1) {
-                queryBuilder.append(")");
-                queryBuilder.append(' ');
+        if (configuration.useForPrimaryTypes()) {
+            String[] pts = filter.getPrimaryTypes().toArray(new String[filter.getPrimaryTypes().size()]);
+            for (int i = 0; i < pts.length; i++) {
+                String pt = pts[i];
+                if (i == 0) {
+                    queryBuilder.append("(");
+                }
+                if (i > 0 && i < pts.length) {
+                    queryBuilder.append("OR ");
+                }
+                queryBuilder.append("jcr\\:primaryType").append(':').append(partialEscape(pt)).append(" ");
+                if (i == pts.length - 1) {
+                    queryBuilder.append(")");
+                    queryBuilder.append(' ');
+                }
             }
         }
 
-        Filter.PathRestriction pathRestriction = filter.getPathRestriction();
-        if (pathRestriction != null) {
-            String path = purgePath(filter);
-            String fieldName = configuration.getFieldForPathRestriction(pathRestriction);
-            if (fieldName != null) {
-                queryBuilder.append(fieldName);
-                queryBuilder.append(':');
-                queryBuilder.append(path);
+        if (configuration.useForPathRestrictions()) {
+            Filter.PathRestriction pathRestriction = filter.getPathRestriction();
+            if (pathRestriction != null) {
+                String path = purgePath(filter);
+                String fieldName = configuration.getFieldForPathRestriction(pathRestriction);
+                if (fieldName != null) {
+                    queryBuilder.append(fieldName);
+                    queryBuilder.append(':');
+                    queryBuilder.append(path);
+                }
             }
         }
 

Modified: jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/TestUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/TestUtils.java?rev=1601888&r1=1601887&r2=1601888&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/TestUtils.java (original)
+++ jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/TestUtils.java Wed Jun 11 13:28:06 2014
@@ -62,6 +62,21 @@ public class TestUtils
             public CommitPolicy getCommitPolicy() {
                 return CommitPolicy.HARD;
             }
+
+            @Override
+            public boolean useForPropertyRestrictions() {
+                return true;
+            }
+
+            @Override
+            public boolean useForPrimaryTypes() {
+                return true;
+            }
+
+            @Override
+            public boolean useForPathRestrictions() {
+                return true;
+            }
         };
     }
 

Modified: jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexHookIT.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexHookIT.java?rev=1601888&r1=1601887&r2=1601888&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexHookIT.java (original)
+++ jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexHookIT.java Wed Jun 11 13:28:06 2014
@@ -83,7 +83,7 @@ public class SolrIndexHookIT extends Sol
                 .setProperty("type", "solr");
 
         NodeState before = builder.getNodeState();
-        builder.setProperty("foo", "bar");
+        builder.child("test").setProperty("foo", "bar");
         NodeState after = builder.getNodeState();
 
         NodeState indexed = hook.processCommit(before, after, CommitInfo.EMPTY);
@@ -97,7 +97,7 @@ public class SolrIndexHookIT extends Sol
         assertTrue("no results found", cursor.hasNext());
         IndexRow next = cursor.next();
         assertNotNull("first returned item should not be null", next);
-        assertEquals("/", next.getPath());
+        assertEquals("/test", next.getPath());
         assertNotNull(next.getValue("foo"));
         assertEquals(PropertyValues.newString("[bar]"), next.getValue("foo"));
         assertFalse(cursor.hasNext());
@@ -113,7 +113,7 @@ public class SolrIndexHookIT extends Sol
                 .setProperty("type", "solr");
 
         NodeState before = builder.getNodeState();
-        builder.setProperty("foo", "bar");
+        builder.child("test").setProperty("foo", "bar");
         builder.child("a").setProperty("foo", "bar");
         builder.child("a").child("b").setProperty("foo", "bar");
         builder.child("a").child("b").child("c").setProperty("foo", "bar");
@@ -133,7 +133,7 @@ public class SolrIndexHookIT extends Sol
         while (cursor.hasNext()) {
             paths.add(cursor.next().getPath());
         }
-        assertTrue(paths.remove("/"));
+        assertTrue(paths.remove("/test"));
         assertTrue(paths.remove("/a"));
         assertTrue(paths.remove("/a/b"));
         assertTrue(paths.remove("/a/b/c"));

Added: jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndexTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndexTest.java?rev=1601888&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndexTest.java (added)
+++ jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndexTest.java Wed Jun 11 13:28:06 2014
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.plugins.index.solr.query;
+
+import org.apache.jackrabbit.oak.plugins.index.solr.configuration.DefaultSolrConfiguration;
+import org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration;
+import org.apache.jackrabbit.oak.query.QueryEngineSettings;
+import org.apache.jackrabbit.oak.query.ast.SelectorImpl;
+import org.apache.jackrabbit.oak.query.index.FilterImpl;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.apache.solr.client.solrj.SolrServer;
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+
+/**
+ * Testcase for {@link org.apache.jackrabbit.oak.plugins.index.solr.query.SolrQueryIndex}
+ */
+public class SolrQueryIndexTest {
+
+    @Test
+    public void testCostWithNoRestrictions() throws Exception {
+        NodeState root = mock(NodeState.class);
+        SelectorImpl selector = mock(SelectorImpl.class);
+
+        SolrServer solrServer = mock(SolrServer.class);
+        OakSolrConfiguration configuration = new DefaultSolrConfiguration();
+        SolrQueryIndex solrQueryIndex = new SolrQueryIndex("solr", solrServer, configuration);
+
+        FilterImpl filter = new FilterImpl(selector, "", new QueryEngineSettings());
+        double cost = solrQueryIndex.getCost(filter, root);
+        assertTrue(Double.POSITIVE_INFINITY == cost);
+    }
+}

Propchange: jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndexTest.java
------------------------------------------------------------------------------
    svn:eol-style = native