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/11/27 12:20:13 UTC

svn commit: r1642090 - in /jackrabbit/oak/branches/1.0: ./ oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/ oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/ oak-solr-core/src/main/resources/...

Author: tommaso
Date: Thu Nov 27 11:20:12 2014
New Revision: 1642090

URL: http://svn.apache.org/r1642090
Log:
OAK-1609 - backported to branch_1.0

Added:
    jackrabbit/oak/branches/1.0/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexEditorTest.java   (with props)
    jackrabbit/oak/branches/1.0/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrIndexQueryTestIT.java
      - copied, changed from r1642075, jackrabbit/oak/branches/1.0/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrIndexQueryTest.java
Removed:
    jackrabbit/oak/branches/1.0/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrIndexQueryTest.java
Modified:
    jackrabbit/oak/branches/1.0/   (props changed)
    jackrabbit/oak/branches/1.0/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexEditor.java
    jackrabbit/oak/branches/1.0/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndex.java
    jackrabbit/oak/branches/1.0/oak-solr-core/src/main/resources/solr/oak/conf/schema.xml
    jackrabbit/oak/branches/1.0/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndexTest.java
    jackrabbit/oak/branches/1.0/oak-solr-core/src/test/resources/solr/oak/conf/schema.xml

Propchange: jackrabbit/oak/branches/1.0/
------------------------------------------------------------------------------
  Reverse-merged /jackrabbit/oak/trunk:r1637880,1637886,1638705
  Merged /jackrabbit/oak/trunk:r1614689

Modified: jackrabbit/oak/branches/1.0/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexEditor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexEditor.java?rev=1642090&r1=1642089&r2=1642090&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.0/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexEditor.java (original)
+++ jackrabbit/oak/branches/1.0/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexEditor.java Thu Nov 27 11:20:12 2014
@@ -234,16 +234,11 @@ public class SolrIndexEditor implements 
         inputDocument.addField(configuration.getPathField(), path);
         for (PropertyState property : state.getProperties()) {
             // try to get the field to use for this property from configuration
-            String fieldName = configuration.getFieldNameFor(property.getType());
-            if (fieldName != null) {
-                inputDocument.addField(
-                        fieldName, property.getValue(property.getType()));
-            } else {
-                // or fallback to adding propertyName:stringValue(s)
-                if (property.isArray()) {
-                    for (String s : property.getValue(Type.STRINGS)) {
-                        inputDocument.addField(property.getName(), s);
-                    }
+            if (!configuration.getIgnoredProperties().contains(property.getName())) {
+                String fieldName = configuration.getFieldNameFor(property.getType());
+                if (fieldName != null) {
+                    inputDocument.addField(
+                            fieldName, property.getValue(property.getType()));
                 } else {
                     if (Type.BINARY.tag() == property.getType().tag()) {
                         inputDocument.addField(property.getName(), extractTextValues(property, state));

Modified: jackrabbit/oak/branches/1.0/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndex.java?rev=1642090&r1=1642089&r2=1642090&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.0/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndex.java (original)
+++ jackrabbit/oak/branches/1.0/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndex.java Thu Nov 27 11:20:12 2014
@@ -121,13 +121,22 @@ public class SolrQueryIndex implements F
         // 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())) {
+                || configuration.useForPropertyRestrictions()) && !hasIgnoredProperties(filter.getPropertyRestrictions())) {
             match++;
         }
 
         return match;
     }
 
+    private boolean hasIgnoredProperties(Collection<Filter.PropertyRestriction> propertyRestrictions) {
+        for (Filter.PropertyRestriction pr : propertyRestrictions) {
+            if (configuration.getIgnoredProperties().contains(pr.propertyName)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
     @Override
     public String getPlan(Filter filter, NodeState nodeState) {
         return getQuery(filter).toString();
@@ -196,8 +205,11 @@ public class SolrQueryIndex implements F
                         queryBuilder.append(nativeQueryString);
                     }
                 } else {
-                    if (!configuration.useForPropertyRestrictions() || pr.propertyName.contains("/") ||
-                            "rep:excerpt".equals(pr.propertyName)) {
+                    if (!configuration.useForPropertyRestrictions() // Solr index not used for properties
+                            || pr.propertyName.contains("/") // no child-level property restrictions
+                            || "rep:excerpt".equals(pr.propertyName) // rep:excerpt is handled by the query engine
+                            || configuration.getIgnoredProperties().contains(pr.propertyName) // property is explicitly ignored
+                            ) {
                         continue;
                     }
 

Modified: jackrabbit/oak/branches/1.0/oak-solr-core/src/main/resources/solr/oak/conf/schema.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-solr-core/src/main/resources/solr/oak/conf/schema.xml?rev=1642090&r1=1642089&r2=1642090&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.0/oak-solr-core/src/main/resources/solr/oak/conf/schema.xml (original)
+++ jackrabbit/oak/branches/1.0/oak-solr-core/src/main/resources/solr/oak/conf/schema.xml Thu Nov 27 11:20:12 2014
@@ -16,83 +16,84 @@
  limitations under the License.
 -->
 <schema name="minimal" version="1.5">
-  <types>
-    <fieldType name="string" class="solr.StrField"/>
-    <fieldType name="descendent_path" class="solr.TextField">
-      <analyzer type="index">
-        <tokenizer class="solr.PathHierarchyTokenizerFactory" delimiter="/" />
-        <filter class="solr.PatternCaptureGroupFilterFactory" pattern="((/).*)" preserve_original="false"/>
-        <filter class="solr.RemoveDuplicatesTokenFilterFactory" />
-      </analyzer>
-      <analyzer type="query">
-        <tokenizer class="solr.KeywordTokenizerFactory" />
-      </analyzer>
-    </fieldType>
-    <fieldType name="children_path" class="solr.TextField">
-      <analyzer type="index">
-        <tokenizer class="solr.KeywordTokenizerFactory"/>
-        <filter class="solr.ReverseStringFilterFactory" />
-        <filter class="solr.LengthFilterFactory" min="2" max="2147483647"/>
-        <filter class="solr.PatternReplaceFilterFactory" pattern="([^\/]+)(\/)" replacement="$2" replace="first"/>
-        <filter class="solr.PatternReplaceFilterFactory" pattern="(\/)(.+)" replacement="$2" replace="first"/>
-        <filter class="solr.ReverseStringFilterFactory" />
-      </analyzer>
-      <analyzer type="query">
-        <tokenizer class="solr.KeywordTokenizerFactory" />
-      </analyzer>
-    </fieldType>
-    <fieldType name="parent_path" class="solr.TextField">
-      <analyzer type="index">
-        <tokenizer class="solr.KeywordTokenizerFactory" />
-      </analyzer>
-      <analyzer type="query">
-        <tokenizer class="solr.KeywordTokenizerFactory"/>
-        <filter class="solr.ReverseStringFilterFactory" />
-        <filter class="solr.PatternReplaceFilterFactory" pattern="[^\/]+\/" replacement="" replace="first"/>
-        <filter class="solr.ReverseStringFilterFactory" />
-      </analyzer>
-    </fieldType>
-    <fieldType name="text_keepcase" class="solr.TextField" positionIncrementGap="100">
-      <analyzer type="index">
-        <tokenizer class="solr.StandardTokenizerFactory"/>
-      </analyzer>
-      <analyzer type="query">
-        <tokenizer class="solr.StandardTokenizerFactory"/>
-      </analyzer>
-    </fieldType>
-    <fieldType name="text_general" class="solr.TextField" positionIncrementGap="100">
-      <analyzer type="index">
-        <tokenizer class="solr.StandardTokenizerFactory"/>
-        <filter class="solr.LowerCaseFilterFactory"/>
-      </analyzer>
-      <analyzer type="query">
-        <tokenizer class="solr.StandardTokenizerFactory"/>
-        <filter class="solr.LowerCaseFilterFactory"/>
-      </analyzer>
-    </fieldType>
-
-    <fieldType name="boolean" class="solr.BoolField" sortMissingLast="true"/>
-
-    <fieldType name="int" class="solr.TrieIntField" precisionStep="0" positionIncrementGap="0"/>
-    <fieldType name="float" class="solr.TrieFloatField" precisionStep="0" positionIncrementGap="0"/>
-    <fieldType name="long" class="solr.TrieLongField" precisionStep="0" positionIncrementGap="0"/>
-    <fieldType name="double" class="solr.TrieDoubleField" precisionStep="0" positionIncrementGap="0"/>
-
-    <fieldType name="tint" class="solr.TrieIntField" precisionStep="8" positionIncrementGap="0"/>
-    <fieldType name="tfloat" class="solr.TrieFloatField" precisionStep="8" positionIncrementGap="0"/>
-    <fieldType name="tlong" class="solr.TrieLongField" precisionStep="8" positionIncrementGap="0"/>
-    <fieldType name="tdouble" class="solr.TrieDoubleField" precisionStep="8" positionIncrementGap="0"/>
-    <fieldType name="date" class="solr.TrieDateField" precisionStep="0" positionIncrementGap="0"/>
-
-    <fieldType name="tdate" class="solr.TrieDateField" precisionStep="6" positionIncrementGap="0"/>
-
-    <fieldtype name="binary" class="solr.BinaryField"/>
-
-    <fieldType name="pint" class="solr.IntField"/>
-    <fieldType name="plong" class="solr.LongField"/>
-    <fieldType name="pfloat" class="solr.FloatField"/>
-    <fieldType name="pdouble" class="solr.DoubleField"/>
-    <fieldType name="pdate" class="solr.DateField" sortMissingLast="true"/>
+    <types>
+        <fieldType name="string" class="solr.StrField"/>
+        <fieldType name="descendent_path" class="solr.TextField">
+            <analyzer type="index">
+                <tokenizer class="solr.PathHierarchyTokenizerFactory" delimiter="/"/>
+                <filter class="solr.PatternCaptureGroupFilterFactory" pattern="((/).*)" preserve_original="false"/>
+                <filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
+            </analyzer>
+            <analyzer type="query">
+                <tokenizer class="solr.KeywordTokenizerFactory"/>
+            </analyzer>
+        </fieldType>
+        <fieldType name="children_path" class="solr.TextField">
+            <analyzer type="index">
+                <tokenizer class="solr.KeywordTokenizerFactory"/>
+                <filter class="solr.ReverseStringFilterFactory"/>
+                <filter class="solr.LengthFilterFactory" min="2" max="2147483647"/>
+                <filter class="solr.PatternReplaceFilterFactory" pattern="([^\/]+)(\/)" replacement="$2"
+                        replace="first"/>
+                <filter class="solr.PatternReplaceFilterFactory" pattern="(\/)(.+)" replacement="$2" replace="first"/>
+                <filter class="solr.ReverseStringFilterFactory"/>
+            </analyzer>
+            <analyzer type="query">
+                <tokenizer class="solr.KeywordTokenizerFactory"/>
+            </analyzer>
+        </fieldType>
+        <fieldType name="parent_path" class="solr.TextField">
+            <analyzer type="index">
+                <tokenizer class="solr.KeywordTokenizerFactory"/>
+            </analyzer>
+            <analyzer type="query">
+                <tokenizer class="solr.KeywordTokenizerFactory"/>
+                <filter class="solr.ReverseStringFilterFactory"/>
+                <filter class="solr.PatternReplaceFilterFactory" pattern="[^\/]+\/" replacement="" replace="first"/>
+                <filter class="solr.ReverseStringFilterFactory"/>
+            </analyzer>
+        </fieldType>
+        <fieldType name="text_keepcase" class="solr.TextField" positionIncrementGap="100">
+            <analyzer type="index">
+                <tokenizer class="solr.StandardTokenizerFactory"/>
+            </analyzer>
+            <analyzer type="query">
+                <tokenizer class="solr.StandardTokenizerFactory"/>
+            </analyzer>
+        </fieldType>
+        <fieldType name="text_general" class="solr.TextField" positionIncrementGap="100">
+            <analyzer type="index">
+                <tokenizer class="solr.ClassicTokenizerFactory" maxTokenLength="100000"/>
+                <filter class="solr.LowerCaseFilterFactory"/>
+            </analyzer>
+            <analyzer type="query">
+                <tokenizer class="solr.ClassicTokenizerFactory" maxTokenLength="100000"/>
+                <filter class="solr.LowerCaseFilterFactory"/>
+            </analyzer>
+        </fieldType>
+
+        <fieldType name="boolean" class="solr.BoolField" sortMissingLast="true"/>
+
+        <fieldType name="int" class="solr.TrieIntField" precisionStep="0" positionIncrementGap="0"/>
+        <fieldType name="float" class="solr.TrieFloatField" precisionStep="0" positionIncrementGap="0"/>
+        <fieldType name="long" class="solr.TrieLongField" precisionStep="0" positionIncrementGap="0"/>
+        <fieldType name="double" class="solr.TrieDoubleField" precisionStep="0" positionIncrementGap="0"/>
+
+        <fieldType name="tint" class="solr.TrieIntField" precisionStep="8" positionIncrementGap="0"/>
+        <fieldType name="tfloat" class="solr.TrieFloatField" precisionStep="8" positionIncrementGap="0"/>
+        <fieldType name="tlong" class="solr.TrieLongField" precisionStep="8" positionIncrementGap="0"/>
+        <fieldType name="tdouble" class="solr.TrieDoubleField" precisionStep="8" positionIncrementGap="0"/>
+        <fieldType name="date" class="solr.TrieDateField" precisionStep="0" positionIncrementGap="0"/>
+
+        <fieldType name="tdate" class="solr.TrieDateField" precisionStep="6" positionIncrementGap="0"/>
+
+        <fieldtype name="binary" class="solr.BinaryField"/>
+
+        <fieldType name="pint" class="solr.IntField"/>
+        <fieldType name="plong" class="solr.LongField"/>
+        <fieldType name="pfloat" class="solr.FloatField"/>
+        <fieldType name="pdouble" class="solr.DoubleField"/>
+        <fieldType name="pdate" class="solr.DateField" sortMissingLast="true"/>
 
     <fieldType name="currency" class="solr.CurrencyField" precisionStep="8" defaultCurrency="USD" currencyConfig="currency.xml" />
     <fieldtype name="ignored" stored="false" indexed="false" multiValued="true" class="solr.StrField"/>

Added: jackrabbit/oak/branches/1.0/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexEditorTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexEditorTest.java?rev=1642090&view=auto
==============================================================================
--- jackrabbit/oak/branches/1.0/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexEditorTest.java (added)
+++ jackrabbit/oak/branches/1.0/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexEditorTest.java Thu Nov 27 11:20:12 2014
@@ -0,0 +1,99 @@
+/*
+ * 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.index;
+
+import javax.annotation.Nonnull;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.plugins.index.IndexUpdateCallback;
+import org.apache.jackrabbit.oak.plugins.index.solr.TestUtils;
+import org.apache.jackrabbit.oak.plugins.index.solr.configuration.CommitPolicy;
+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.plugins.memory.PropertyStates;
+import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.apache.solr.client.solrj.SolrQuery;
+import org.apache.solr.client.solrj.SolrServer;
+import org.apache.solr.client.solrj.response.QueryResponse;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+/**
+ * Testcase for {@link org.apache.jackrabbit.oak.plugins.index.solr.index.SolrIndexEditor}
+ */
+public class SolrIndexEditorTest {
+
+    @Test
+    public void testIndexedProperties() throws Exception {
+        NodeBuilder builder = mock(NodeBuilder.class);
+        SolrServer solrServer = TestUtils.createSolrServer();
+        OakSolrConfiguration configuration = TestUtils.getTestConfiguration();
+        IndexUpdateCallback callback = mock(IndexUpdateCallback.class);
+        SolrIndexEditor solrIndexEditor = new SolrIndexEditor(builder, solrServer, configuration, callback);
+        NodeState before = mock(NodeState.class);
+        NodeState after = mock(NodeState.class);
+        Iterable properties = new Iterable<PropertyState>() {
+            @Override
+            public Iterator<PropertyState> iterator() {
+                return Arrays.asList(PropertyStates.createProperty("foo1", "bar")).iterator();
+            }
+        };
+        when(after.getProperties()).thenReturn(properties);
+        solrIndexEditor.leave(before, after);
+        QueryResponse queryResponse = solrServer.query(new SolrQuery("foo1:*"));
+        assertEquals(1, queryResponse.getResults().getNumFound());
+    }
+
+    @Test
+    public void testIgnoredPropertiesNotIndexed() throws Exception {
+        NodeBuilder builder = mock(NodeBuilder.class);
+        SolrServer solrServer = TestUtils.createSolrServer();
+        OakSolrConfiguration configuration = new DefaultSolrConfiguration() {
+            @Nonnull
+            @Override
+            public Collection<String> getIgnoredProperties() {
+                return Arrays.asList("foo2");
+            }
+            @Nonnull
+            @Override
+            public CommitPolicy getCommitPolicy() {
+                return CommitPolicy.HARD;
+            }
+        };
+        IndexUpdateCallback callback = mock(IndexUpdateCallback.class);
+        SolrIndexEditor solrIndexEditor = new SolrIndexEditor(builder, solrServer, configuration, callback);
+        NodeState before = mock(NodeState.class);
+        NodeState after = mock(NodeState.class);
+        Iterable properties = new Iterable<PropertyState>() {
+            @Override
+            public Iterator<PropertyState> iterator() {
+                return Arrays.asList(PropertyStates.createProperty("foo2", "bar")).iterator();
+            }
+        };
+        when(after.getProperties()).thenReturn(properties);
+        solrIndexEditor.leave(before, after);
+        QueryResponse queryResponse = solrServer.query(new SolrQuery("foo2:*"));
+        assertEquals(0, queryResponse.getResults().getNumFound());
+    }
+}

Propchange: jackrabbit/oak/branches/1.0/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexEditorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: jackrabbit/oak/branches/1.0/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrIndexQueryTestIT.java (from r1642075, jackrabbit/oak/branches/1.0/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrIndexQueryTest.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrIndexQueryTestIT.java?p2=jackrabbit/oak/branches/1.0/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrIndexQueryTestIT.java&p1=jackrabbit/oak/branches/1.0/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrIndexQueryTest.java&r1=1642075&r2=1642090&rev=1642090&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.0/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrIndexQueryTest.java (original)
+++ jackrabbit/oak/branches/1.0/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrIndexQueryTestIT.java Thu Nov 27 11:20:12 2014
@@ -35,7 +35,6 @@ import org.apache.jackrabbit.oak.spi.que
 import org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider;
 import org.apache.solr.client.solrj.SolrServer;
 import org.junit.After;
-import org.junit.Assume;
 import org.junit.Ignore;
 import org.junit.Test;
 
@@ -49,7 +48,7 @@ import static org.junit.Assume.assumeTru
 /**
  * General query extensive testcase for {@link SolrQueryIndex}
  */
-public class SolrIndexQueryTest extends AbstractQueryTest {
+public class SolrIndexQueryTestIT extends AbstractQueryTest {
 
     private SolrServer solrServer;
 
@@ -378,9 +377,7 @@ public class SolrIndexQueryTest extends 
         test.addChild("a").setProperty("name", "/parent/child/node");
         root.commit();
 
-        StringBuffer stmt = new StringBuffer();
-        stmt.append("//*[jcr:contains(., '/parent/child')]");
-        assertQuery(stmt.toString(), "xpath", ImmutableList.of("/test/a"));
+        assertQuery("//*[jcr:contains(., '/parent/child')]", "xpath", ImmutableList.of("/test/a"));
 
     }
 
@@ -392,9 +389,7 @@ public class SolrIndexQueryTest extends 
         a.setProperty("name", "/segment1/segment2/segment3");
         root.commit();
 
-        StringBuffer stmt = new StringBuffer();
-        stmt.append("//*[jcr:contains(., '/segment1/segment2')]");
-        assertQuery(stmt.toString(), "xpath", ImmutableList.of("/test/a"));
+        assertQuery("//*[jcr:contains(., '/segment1/segment2')]", "xpath", ImmutableList.of("/test/a"));
 
     }
 
@@ -418,9 +413,7 @@ public class SolrIndexQueryTest extends 
 
         root.commit();
 
-        StringBuffer stmt = new StringBuffer();
-        stmt.append("//*[jcr:contains(., 'media') and (@p = 'dam/smartcollection' or @p = 'dam/collection') ]");
-        assertQuery(stmt.toString(), "xpath",
+        assertQuery("//*[jcr:contains(., 'media') and (@p = 'dam/smartcollection' or @p = 'dam/collection') ]", "xpath",
                 ImmutableList.of(one.getPath(), two.getPath()));
     }
 }

Modified: jackrabbit/oak/branches/1.0/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndexTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndexTest.java?rev=1642090&r1=1642089&r2=1642090&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.0/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndexTest.java (original)
+++ jackrabbit/oak/branches/1.0/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndexTest.java Thu Nov 27 11:20:12 2014
@@ -16,20 +16,27 @@
  */
 package org.apache.jackrabbit.oak.plugins.index.solr.query;
 
+import java.util.Arrays;
+import java.util.Collection;
 import java.util.Collections;
 
+import org.apache.jackrabbit.oak.plugins.index.solr.TestUtils;
 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.Operator;
 import org.apache.jackrabbit.oak.query.ast.SelectorImpl;
 import org.apache.jackrabbit.oak.query.index.FilterImpl;
+import org.apache.jackrabbit.oak.spi.query.Cursor;
 import org.apache.jackrabbit.oak.spi.query.Filter;
 import org.apache.jackrabbit.oak.spi.query.PropertyValues;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.solr.client.solrj.SolrServer;
+import org.apache.solr.common.SolrInputDocument;
 import org.junit.Test;
 
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.mock;
@@ -77,7 +84,7 @@ public class SolrQueryIndexTest {
         SelectorImpl selector = new SelectorImpl(root, "a");
 
         SolrServer solrServer = mock(SolrServer.class);
-        OakSolrConfiguration configuration = new DefaultSolrConfiguration(){
+        OakSolrConfiguration configuration = new DefaultSolrConfiguration() {
             @Override
             public boolean useForPathRestrictions() {
                 return true;
@@ -114,7 +121,7 @@ public class SolrQueryIndexTest {
         SelectorImpl selector = new SelectorImpl(root, "a");
 
         SolrServer solrServer = mock(SolrServer.class);
-        OakSolrConfiguration configuration = new DefaultSolrConfiguration(){
+        OakSolrConfiguration configuration = new DefaultSolrConfiguration() {
             @Override
             public boolean useForPropertyRestrictions() {
                 return true;
@@ -151,7 +158,7 @@ public class SolrQueryIndexTest {
         SelectorImpl selector = new SelectorImpl(root, "a");
 
         SolrServer solrServer = mock(SolrServer.class);
-        OakSolrConfiguration configuration = new DefaultSolrConfiguration(){
+        OakSolrConfiguration configuration = new DefaultSolrConfiguration() {
             @Override
             public boolean useForPrimaryTypes() {
                 return true;
@@ -164,4 +171,89 @@ public class SolrQueryIndexTest {
         double cost = solrQueryIndex.getCost(filter, root);
         assertTrue(10 == cost);
     }
+
+    @Test
+    public void testCostWithPropertyRestrictionsEnabledButPropertyIgnored() throws Exception {
+        NodeState root = mock(NodeState.class);
+        when(root.getNames(any(String.class))).thenReturn(Collections.<String>emptySet());
+        SelectorImpl selector = new SelectorImpl(root, "a");
+
+        SolrServer solrServer = mock(SolrServer.class);
+        OakSolrConfiguration configuration = new DefaultSolrConfiguration() {
+            @Override
+            public boolean useForPropertyRestrictions() {
+                return true;
+            }
+
+            @Override
+            public Collection<String> getIgnoredProperties() {
+                return Arrays.asList("name");
+            }
+        };
+        SolrQueryIndex solrQueryIndex = new SolrQueryIndex("solr", solrServer, configuration);
+
+        FilterImpl filter = new FilterImpl(selector, "select * from [nt:base] as a where name = 'hello')", new QueryEngineSettings());
+        filter.restrictProperty("name", Operator.EQUAL, PropertyValues.newString("hello"));
+        double cost = solrQueryIndex.getCost(filter, root);
+        assertTrue(Double.POSITIVE_INFINITY == cost);
+    }
+
+    @Test
+    public void testQueryOnIgnoredExistingProperty() throws Exception {
+        NodeState root = mock(NodeState.class);
+        when(root.getNames(any(String.class))).thenReturn(Collections.<String>emptySet());
+        SelectorImpl selector = new SelectorImpl(root, "a");
+
+        SolrServer solrServer = TestUtils.createSolrServer();
+        SolrInputDocument document = new SolrInputDocument();
+        document.addField("path_exact", "/a/b");
+        document.addField("name", "hello");
+        solrServer.add(document);
+        solrServer.commit();
+        OakSolrConfiguration configuration = new DefaultSolrConfiguration() {
+            @Override
+            public boolean useForPropertyRestrictions() {
+                return true;
+            }
+
+            @Override
+            public Collection<String> getIgnoredProperties() {
+                return Arrays.asList("name");
+            }
+        };
+        SolrQueryIndex solrQueryIndex = new SolrQueryIndex("solr", solrServer, configuration);
+
+        FilterImpl filter = new FilterImpl(selector, "select * from [nt:base] as a where name = 'hello')", new QueryEngineSettings());
+        filter.restrictProperty("name", Operator.EQUAL, PropertyValues.newString("hello"));
+        String plan = solrQueryIndex.getPlan(filter, root);
+        assertNotNull(plan);
+        assertTrue(plan.contains("q=*%3A*")); // querying on property name is not possible, then falling back to a match all query
+    }
+
+    @Test
+    public void testQueryOnExistingProperty() throws Exception {
+        NodeState root = mock(NodeState.class);
+        when(root.getNames(any(String.class))).thenReturn(Collections.<String>emptySet());
+        SelectorImpl selector = new SelectorImpl(root, "a");
+
+        SolrServer solrServer = TestUtils.createSolrServer();
+        SolrInputDocument document = new SolrInputDocument();
+        document.addField("path_exact", "/a/b");
+        document.addField("name", "hello");
+        solrServer.add(document);
+        solrServer.commit();
+        OakSolrConfiguration configuration = new DefaultSolrConfiguration() {
+            @Override
+            public boolean useForPropertyRestrictions() {
+                return true;
+            }
+        };
+        SolrQueryIndex solrQueryIndex = new SolrQueryIndex("solr", solrServer, configuration);
+
+        FilterImpl filter = new FilterImpl(selector, "select * from [nt:base] as a where name = 'hello')", new QueryEngineSettings());
+        filter.restrictProperty("name", Operator.EQUAL, PropertyValues.newString("hello"));
+        String plan = solrQueryIndex.getPlan(filter, root);
+        assertNotNull(plan);
+        assertTrue(plan.contains("q=name%3Ahello")); // query gets converted to a fielded query on name field
+    }
 }

Modified: jackrabbit/oak/branches/1.0/oak-solr-core/src/test/resources/solr/oak/conf/schema.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-solr-core/src/test/resources/solr/oak/conf/schema.xml?rev=1642090&r1=1642089&r2=1642090&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.0/oak-solr-core/src/test/resources/solr/oak/conf/schema.xml (original)
+++ jackrabbit/oak/branches/1.0/oak-solr-core/src/test/resources/solr/oak/conf/schema.xml Thu Nov 27 11:20:12 2014
@@ -114,6 +114,7 @@
         <field name="_version_" type="long" indexed="true" stored="true"/>
         <field name=":path" type="string" indexed="true" stored="false"/>
 
+        <field name="jcr:data" type="binary"  indexed="true"  stored="false" multiValued="true"/>
         <dynamicField name="*_i"  type="int"    indexed="true"  stored="true"/>
         <dynamicField name="*_is" type="int"    indexed="true"  stored="true"  multiValued="true"/>
         <dynamicField name="*_s"  type="string"  indexed="true"  stored="true" />