Author: tommaso
Date: Tue Feb  2 10:23:51 2016
New Revision: 1728070

URL: http://svn.apache.org/viewvc?rev=1728070&view=rev
Log:
OAK-3968 - fixing wrong initialization for used/ignored proprties from OSGi 
configuration, minor adjustments

Modified:
    
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/FilterQueryParser.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/query/SolrIndexQueryTestIT.java

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=1728070&r1=1728069&r2=1728070&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
 Tue Feb  2 10:23:51 2016
@@ -148,6 +148,7 @@ public class OakSolrConfigurationProvide
         typeMappings = 
PropertiesUtil.toStringArray(componentContext.getProperties().get(TYPE_MAPPINGS));
         ignoredProperties = 
PropertiesUtil.toStringArray(componentContext.getProperties().get(IGNORED_PROPERTIES));
         usedProperties = 
PropertiesUtil.toStringArray(componentContext.getProperties().get(USED_PROPERTIES));
+        System.err.println(">>>"+usedProperties.length);
         propertyMappings = 
PropertiesUtil.toStringArray(componentContext.getProperties().get(PROPERTY_MAPPINGS));
         collapseJcrContentNodes = 
Boolean.valueOf(String.valueOf(componentContext.getProperties().get(COLLAPSE_JCR_CONTENT_NODES)));
     }
@@ -260,7 +261,7 @@ public class OakSolrConfigurationProvide
                 @Nonnull
                 @Override
                 public Collection<String> getIgnoredProperties() {
-                    if (ignoredProperties != null && ignoredProperties.length 
> 0) {
+                    if (ignoredProperties != null && ignoredProperties.length 
> 0 && ignoredProperties[0].length() > 0) {
                         return Arrays.asList(ignoredProperties);
                     } else {
                         return Collections.emptyList();
@@ -270,7 +271,7 @@ public class OakSolrConfigurationProvide
                 @Nonnull
                 @Override
                 public Collection<String> getUsedProperties() {
-                    if (usedProperties != null && usedProperties.length > 0) {
+                    if (usedProperties != null && usedProperties.length > 0 && 
usedProperties[0].length() > 0) {
                         return Arrays.asList(usedProperties);
                     } else {
                         return Collections.emptyList();

Modified: 
jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/FilterQueryParser.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/FilterQueryParser.java?rev=1728070&r1=1728069&r2=1728070&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/FilterQueryParser.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/FilterQueryParser.java
 Tue Feb  2 10:23:51 2016
@@ -166,7 +166,7 @@ class FilterQueryParser {
                         queryBuilder.append(nativeQueryString);
                     }
                 } else {
-                    if (SolrQueryIndex.isIgnoredProperty(pr.propertyName, 
configuration)) {
+                    if (SolrQueryIndex.isIgnoredProperty(pr, configuration)) {
                         continue;
                     }
 

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=1728070&r1=1728069&r2=1728070&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
 Tue Feb  2 10:23:51 2016
@@ -170,7 +170,7 @@ public class SolrQueryIndex implements F
 
     private static boolean 
hasIgnoredProperties(Collection<Filter.PropertyRestriction> 
propertyRestrictions, OakSolrConfiguration configuration) {
         for (Filter.PropertyRestriction pr : propertyRestrictions) {
-            if (isIgnoredProperty(pr.propertyName, configuration)) {
+            if (isIgnoredProperty(pr, configuration)) {
                 return true;
             }
         }
@@ -499,16 +499,17 @@ public class SolrQueryIndex implements F
         }
     }
 
-    static boolean isIgnoredProperty(String propertyName, OakSolrConfiguration 
configuration) {
-        return !(NATIVE_LUCENE_QUERY.equals(propertyName) || 
NATIVE_SOLR_QUERY.equals(propertyName)) &&
-                (!configuration.useForPropertyRestrictions() // Solr index not 
used for properties
-                        || (configuration.getUsedProperties().size() > 0 && 
!configuration.getUsedProperties().contains(propertyName)) // not explicitly 
contained in the used properties
-                        || propertyName.contains("/") // no child-level 
property restrictions
-                        || QueryImpl.REP_EXCERPT.equals(propertyName) // 
rep:excerpt is not handled at the property level
-                        || 
QueryImpl.OAK_SCORE_EXPLANATION.equals(propertyName) // score explain is not 
handled at the property level
-                        || QueryImpl.REP_FACET.equals(propertyName) // 
rep:facet is not handled at the property level
-                        || 
QueryConstants.RESTRICTION_LOCAL_NAME.equals(propertyName)
-                        || 
configuration.getIgnoredProperties().contains(propertyName));
+    static boolean isIgnoredProperty(Filter.PropertyRestriction property, 
OakSolrConfiguration configuration) {
+        if (NATIVE_LUCENE_QUERY.equals(property.propertyName) || 
NATIVE_SOLR_QUERY.equals(property.propertyName)) {
+               return false;
+        } else return (!configuration.useForPropertyRestrictions() // Solr 
index not used for properties
+                        || (configuration.getUsedProperties().size() > 0 && 
!configuration.getUsedProperties().contains(property.propertyName)) // not 
explicitly contained in the used properties
+                        || property.propertyName.contains("/") // no 
child-level property restrictions
+                        || QueryImpl.REP_EXCERPT.equals(property.propertyName) 
// rep:excerpt is not handled at the property level
+                        || 
QueryImpl.OAK_SCORE_EXPLANATION.equals(property.propertyName) // score explain 
is not handled at the property level
+                        || QueryImpl.REP_FACET.equals(property.propertyName) 
// rep:facet is not handled at the property level
+                        || 
QueryConstants.RESTRICTION_LOCAL_NAME.equals(property.propertyName)
+                        || 
configuration.getIgnoredProperties().contains(property.propertyName));
     }
 
     @Override

Modified: 
jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrIndexQueryTestIT.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrIndexQueryTestIT.java?rev=1728070&r1=1728069&r2=1728070&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrIndexQueryTestIT.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrIndexQueryTestIT.java
 Tue Feb  2 10:23:51 2016
@@ -16,19 +16,11 @@
  */
 package org.apache.jackrabbit.oak.plugins.index.solr.query;
 
-import static java.util.Arrays.asList;
-import static org.apache.jackrabbit.oak.api.Type.STRINGS;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assume.assumeTrue;
-
+import javax.jcr.query.Query;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.Iterator;
 
-import javax.jcr.query.Query;
-
 import com.google.common.collect.ImmutableList;
 import org.apache.jackrabbit.JcrConstants;
 import org.apache.jackrabbit.oak.Oak;
@@ -46,10 +38,15 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TestName;
 
+import static java.util.Arrays.asList;
+import static org.apache.jackrabbit.oak.api.Type.STRINGS;
+import static org.junit.Assert.*;
+import static org.junit.Assume.assumeTrue;
+
 /**
  * General query extensive testcase for {@link SolrQueryIndex}
  */
-    public class SolrIndexQueryTestIT extends AbstractQueryTest {
+public class SolrIndexQueryTestIT extends AbstractQueryTest {
 
     @Rule
     public TestName name = new TestName();
@@ -58,10 +55,10 @@ import org.junit.rules.TestName;
     protected void createTestIndexNode() throws Exception {
         Tree index = root.getTree("/");
         Tree solrIndexNode = createTestIndexNode(index, SolrQueryIndex.TYPE);
-        solrIndexNode.setProperty("pathRestrictions",true);
-        solrIndexNode.setProperty("propertyRestrictions",true);
-        solrIndexNode.setProperty("primaryTypes",true);
-        solrIndexNode.setProperty("commitPolicy","hard");
+        solrIndexNode.setProperty("pathRestrictions", true);
+        solrIndexNode.setProperty("propertyRestrictions", true);
+        solrIndexNode.setProperty("primaryTypes", true);
+        solrIndexNode.setProperty("commitPolicy", "hard");
         Tree server = solrIndexNode.addChild("server");
         server.setProperty("solrServerType", "embedded");
         server.setProperty("solrHomePath", "target/" + name.getMethodName());
@@ -93,7 +90,7 @@ import org.junit.rules.TestName;
     public void sql2() throws Exception {
         test("sql2.txt");
     }
-    
+
     @Test
     public void sql2FullText() throws Exception {
         test("sql2-fulltext.txt");
@@ -314,10 +311,10 @@ import org.junit.rules.TestName;
         }
         assertEquals(
                 "/test/b " +
-                "/test/d " +
-                "/test/e " + 
-                "/test/f " +
-                "/test/h ", list);
+                        "/test/d " +
+                        "/test/e " +
+                        "/test/f " +
+                        "/test/h ", list);
     }
 
     @Test
@@ -502,7 +499,7 @@ import org.junit.rules.TestName;
         assertEquals("/test/b", result.next());
         assertFalse(result.hasNext());
     }
-    
+
     @Test
     public void testOrderByJcrScore() throws Exception {
         Tree index = root.getTree("/oak:index/" + TEST_INDEX_NAME);
@@ -511,18 +508,18 @@ import org.junit.rules.TestName;
         index.setProperty("rows", 10000);
         index.setProperty("reindex", true);
         root.commit();
-        
+
         Tree content = root.getTree("/").addChild("content");
         Tree a = content.addChild("a");
         a.setProperty(JcrConstants.JCR_PRIMARYTYPE, 
JcrConstants.NT_UNSTRUCTURED, Type.NAME);
         a.setProperty("type", "doc doc doc");
         root.commit();
-                
+
         String statement = "select [jcr:path], [jcr:score], [rep:excerpt] " +
-            "from [nt:unstructured] as a " + 
-            "where contains(*, 'doc') " +
-            "and isdescendantnode(a, '/content') " +
-            "order by [jcr:score] desc";
+                "from [nt:unstructured] as a " +
+                "where contains(*, 'doc') " +
+                "and isdescendantnode(a, '/content') " +
+                "order by [jcr:score] desc";
 
         Iterator<String> results = executeQuery(statement, Query.JCR_SQL2, 
true).iterator();
         assertTrue(results.hasNext());
@@ -624,4 +621,34 @@ import org.junit.rules.TestName;
         assertEquals("/test/content/sample2/jcr:content", result.next());
         assertFalse(result.hasNext());
     }
+
+    @Test
+    public void testNotNullAndNative() throws Exception {
+        Tree index = root.getTree("/oak:index/" + TEST_INDEX_NAME);
+        assertTrue(index.exists());
+
+        index.setProperty("rows", 10000);
+        index.setProperty("reindex", true);
+        root.commit();
+
+        Tree content = root.getTree("/").addChild("content");
+        Tree a = content.addChild("a");
+        a.setProperty(JcrConstants.JCR_PRIMARYTYPE, 
JcrConstants.NT_UNSTRUCTURED, Type.NAME);
+        a.setProperty("foo", "doc doc doc");
+        a.setProperty("loc", "2");
+        Tree b = content.addChild("b");
+        b.setProperty(JcrConstants.JCR_PRIMARYTYPE, 
JcrConstants.NT_UNSTRUCTURED, Type.NAME);
+        b.setProperty("foo", "bye bye bye");
+        b.setProperty("loc", "1");
+        root.commit();
+
+        String query = "select [jcr:path] from [nt:base] where 
native('solr','select?q=loc:*') AND foo IS NOT NULL";
+
+        Iterator<String> results = executeQuery(query, Query.JCR_SQL2, 
true).iterator();
+        assertTrue(results.hasNext());
+        assertEquals("/content/a", results.next());
+        assertTrue(results.hasNext());
+        assertEquals("/content/b", results.next());
+        assertFalse(results.hasNext());
+    }
 }


Reply via email to