jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tomm...@apache.org
Subject svn commit: r1567870 - in /jackrabbit/oak/trunk/oak-solr-core/src: main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/ main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/ test/java/org/apache/jackrabbit/oak/plugins/index/solr/ test/...
Date Thu, 13 Feb 2014 09:35:27 GMT
Author: tommaso
Date: Thu Feb 13 09:35:27 2014
New Revision: 1567870

URL: http://svn.apache.org/r1567870
Log:
OAK-1421 - add support for primary type filtering in Solr index

Modified:
    jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexEditor.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
    jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrIndexQueryTest.java
    jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryEngineIT.java

Modified: jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexEditor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexEditor.java?rev=1567870&r1=1567869&r2=1567870&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexEditor.java
(original)
+++ jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexEditor.java
Thu Feb 13 09:35:27 2014
@@ -16,10 +16,7 @@
  */
 package org.apache.jackrabbit.oak.plugins.index.solr.index;
 
-import static org.apache.jackrabbit.oak.commons.PathUtils.concat;
-
 import java.io.IOException;
-
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Type;
@@ -35,6 +32,8 @@ import org.apache.solr.client.solrj.Solr
 import org.apache.solr.client.solrj.SolrServerException;
 import org.apache.solr.common.SolrInputDocument;
 
+import static org.apache.jackrabbit.oak.commons.PathUtils.concat;
+
 /**
  * Index editor for keeping a Solr index up to date.
  */

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=1567870&r1=1567869&r2=1567870&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
Thu Feb 13 09:35:27 2014
@@ -77,7 +77,10 @@ public class SolrQueryIndex implements Q
 
         StringBuilder queryBuilder = new StringBuilder();
 
-        // TODO : handle node type restriction
+        for (String pt : filter.getPrimaryTypes()) {
+            queryBuilder.append("jcr\\:primaryType").append(':').append(partialEscape(pt));
+        }
+
         Filter.PathRestriction pathRestriction = filter.getPathRestriction();
         if (pathRestriction != null) {
             String path = purgePath(filter);
@@ -100,7 +103,7 @@ public class SolrQueryIndex implements Q
         if (propertyRestrictions != null && !propertyRestrictions.isEmpty()) {
             for (Filter.PropertyRestriction pr : propertyRestrictions) {
                 if (pr.propertyName.contains("/")) {
-                    // lucene cannot handle child-level property restrictions
+                    // cannot handle child-level property restrictions
                     continue;
                 }
                 String first = null;
@@ -153,8 +156,8 @@ public class SolrQueryIndex implements Q
         solrQuery.setQuery(escapedQuery);
 
         if (log.isDebugEnabled()) {
-            log.debug(new StringBuilder("JCR query: \n" + filter.getQueryStatement() + "
\nhas been converted to Solr query: \n").
-                    append(solrQuery.toString()).toString());
+            log.debug("JCR query {} has been converted to Solr query {}",
+                    filter.getQueryStatement(), solrQuery.toString());
         }
 
         return solrQuery;

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=1567870&r1=1567869&r2=1567870&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
Thu Feb 13 09:35:27 2014
@@ -17,7 +17,6 @@
 package org.apache.jackrabbit.oak.plugins.index.solr;
 
 import java.io.File;
-
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.plugins.index.solr.configuration.CommitPolicy;
 import org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration;
@@ -34,13 +33,14 @@ import org.apache.solr.core.CoreContaine
 public class TestUtils
         implements SolrServerProvider, OakSolrConfigurationProvider {
 
-    static final String SOLR_HOME_PATH = "target/test-classes/solr";
-    static final String SOLRCONFIG_PATH = "target/test-classes/solr/solr.xml";
+    static final String SOLR_HOME_PATH = "/solr";
+    static final String SOLRCONFIG_PATH = "/solr/solr.xml";
 
     public static SolrServer createSolrServer() {
-        CoreContainer coreContainer = new CoreContainer(SOLR_HOME_PATH);
+        String homePath = SolrServerProvider.class.getResource(SOLR_HOME_PATH).getFile();
+        CoreContainer coreContainer = new CoreContainer(homePath);
         try {
-            coreContainer.load(SOLR_HOME_PATH, new File(SOLRCONFIG_PATH));
+            coreContainer.load(homePath, new File(SolrServerProvider.class.getResource(SOLRCONFIG_PATH).getFile()));
         } catch (Exception e) {
             throw new IllegalStateException(e);
         }

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=1567870&r1=1567869&r2=1567870&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
Thu Feb 13 09:35:27 2014
@@ -16,19 +16,11 @@
  */
 package org.apache.jackrabbit.oak.plugins.index.solr.index;
 
-import static com.google.common.collect.Sets.newHashSet;
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertFalse;
-import static junit.framework.Assert.assertNotNull;
-import static junit.framework.Assert.assertTrue;
-import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
-import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
-
 import java.util.Set;
-
 import org.apache.jackrabbit.oak.plugins.index.solr.SolrBaseTest;
 import org.apache.jackrabbit.oak.plugins.index.solr.query.SolrQueryIndex;
 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.commit.CommitInfo;
 import org.apache.jackrabbit.oak.spi.query.Cursor;
@@ -40,6 +32,15 @@ import org.apache.jackrabbit.oak.spi.sta
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.junit.Test;
 
+import static com.google.common.collect.Sets.newHashSet;
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertTrue;
+import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
+import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
+import static org.mockito.Mockito.mock;
+
 public class SolrIndexHookIT extends SolrBaseTest {
 
     @Test
@@ -58,7 +59,7 @@ public class SolrIndexHookIT extends Sol
         NodeState indexed = hook.processCommit(before, after, CommitInfo.EMPTY);
 
         QueryIndex queryIndex = new SolrQueryIndex("solr", server, configuration);
-        FilterImpl filter = new FilterImpl(null, null);
+        FilterImpl filter = new FilterImpl(mock(SelectorImpl.class), "");
         filter.restrictPath("/newnode", Filter.PathRestriction.EXACT);
         filter.restrictProperty("prop", Operator.EQUAL,
                 PropertyValues.newString("val"));
@@ -87,7 +88,7 @@ public class SolrIndexHookIT extends Sol
         NodeState indexed = hook.processCommit(before, after, CommitInfo.EMPTY);
 
         QueryIndex queryIndex = new SolrQueryIndex("solr", server, configuration);
-        FilterImpl filter = new FilterImpl(null, null);
+        FilterImpl filter = new FilterImpl(mock(SelectorImpl.class), "");
         filter.restrictProperty("foo", Operator.EQUAL,
                 PropertyValues.newString("bar"));
         Cursor cursor = queryIndex.query(filter, indexed);
@@ -121,7 +122,7 @@ public class SolrIndexHookIT extends Sol
         NodeState indexed = hook.processCommit(before, after, CommitInfo.EMPTY);
 
         QueryIndex queryIndex = new SolrQueryIndex("solr", server, configuration);
-        FilterImpl filter = new FilterImpl(null, null);
+        FilterImpl filter = new FilterImpl(mock(SelectorImpl.class), "");
         filter.restrictProperty("foo", Operator.EQUAL,
                 PropertyValues.newString("bar"));
         filter.restrictFulltextCondition("bar");

Modified: jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrIndexQueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrIndexQueryTest.java?rev=1567870&r1=1567869&r2=1567870&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrIndexQueryTest.java
(original)
+++ jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrIndexQueryTest.java
Thu Feb 13 09:35:27 2014
@@ -16,14 +16,7 @@
  */
 package org.apache.jackrabbit.oak.plugins.index.solr.query;
 
-import static java.util.Arrays.asList;
-import static junit.framework.Assert.assertEquals;
-import static org.apache.jackrabbit.oak.api.Type.STRINGS;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
 import java.util.Iterator;
-
 import org.apache.jackrabbit.oak.Oak;
 import org.apache.jackrabbit.oak.api.ContentRepository;
 import org.apache.jackrabbit.oak.api.Tree;
@@ -37,9 +30,14 @@ import org.junit.After;
 import org.junit.Ignore;
 import org.junit.Test;
 
+import static java.util.Arrays.asList;
+import static junit.framework.Assert.assertEquals;
+import static org.apache.jackrabbit.oak.api.Type.STRINGS;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
 /**
- * General query extensive testcase for {@link SolrQueryIndex} and {@link
- * org.apache.jackrabbit.oak.plugins.index.solr.index.SolrIndexDiff}
+ * General query extensive testcase for {@link SolrQueryIndex}
  */
 public class SolrIndexQueryTest extends AbstractQueryTest {
 

Modified: jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryEngineIT.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryEngineIT.java?rev=1567870&r1=1567869&r2=1567870&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryEngineIT.java
(original)
+++ jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryEngineIT.java
Thu Feb 13 09:35:27 2014
@@ -16,15 +16,13 @@
  */
 package org.apache.jackrabbit.oak.plugins.index.solr.query;
 
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertFalse;
-import static junit.framework.Assert.assertNotNull;
-import static junit.framework.Assert.assertTrue;
-
+import java.util.HashSet;
+import java.util.Set;
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.plugins.index.solr.SolrBaseTest;
 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;
@@ -32,27 +30,129 @@ import org.apache.jackrabbit.oak.spi.que
 import org.apache.jackrabbit.oak.spi.query.QueryIndex;
 import org.junit.Test;
 
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
 /**
- * Integration test for {@link org.apache.jackrabbit.oak.plugins.index.solr.query.SolrQueryIndex}
and {@link org.apache.jackrabbit.oak.plugins.index.solr.index.SolrCommitHook} working
+ * Integration test for {@link org.apache.jackrabbit.oak.plugins.index.solr.query.SolrQueryIndex}
working
  * together
  */
 public class SolrQueryEngineIT extends SolrBaseTest {
 
     @Test
-    public void testSolrQueryEngine() throws Exception {
+    public void testExactPathFiltering() throws Exception {
         Root root = createRoot();
         Tree tree = root.getTree("/");
-        tree.addChild("somenode").setProperty("foo", "bar");
+        tree.addChild("somenode");
+        tree.addChild("someothernode");
         root.commit();
 
         QueryIndex index = new SolrQueryIndex("solr", server, configuration);
-        FilterImpl filter = new FilterImpl(null, null);
+        FilterImpl filter = new FilterImpl(mock(SelectorImpl.class), "");
         filter.restrictPath("/somenode", Filter.PathRestriction.EXACT);
+        Cursor cursor = index.query(filter, store.getRoot());
+        assertNotNull(cursor);
+        assertTrue(cursor.hasNext());
+        assertEquals("/somenode", cursor.next().getPath());
+        assertFalse(cursor.hasNext());
+    }
+
+    @Test
+    public void testDirectChildrenPathFiltering() throws Exception {
+        Root root = createRoot();
+        Tree tree = root.getTree("/");
+        Tree parent = tree.addChild("somenode");
+        parent.addChild("child1");
+        Tree child2 = parent.addChild("child2");
+        child2.addChild("descendant");
+        Tree someothernode = tree.addChild("someothernode");
+        someothernode.addChild("someotherchild");
+        root.commit();
+
+        QueryIndex index = new SolrQueryIndex("solr", server, configuration);
+        FilterImpl filter = new FilterImpl(mock(SelectorImpl.class), "");
+        filter.restrictPath("/somenode", Filter.PathRestriction.DIRECT_CHILDREN);
+        Cursor cursor = index.query(filter, store.getRoot());
+        assertNotNull(cursor);
+        assertTrue(cursor.hasNext());
+        assertEquals("/somenode/child1", cursor.next().getPath());
+        assertTrue(cursor.hasNext());
+        assertEquals("/somenode/child2", cursor.next().getPath());
+        assertFalse(cursor.hasNext());
+    }
+
+    @Test
+    public void testAllChildrenPathFiltering() throws Exception {
+        Root root = createRoot();
+        Tree tree = root.getTree("/");
+        Tree parent = tree.addChild("somenode");
+        parent.addChild("child1");
+        Tree child2 = parent.addChild("child2");
+        child2.addChild("descendant");
+        Tree someothernode = tree.addChild("someothernode");
+        someothernode.addChild("someotherchild");
+        root.commit();
+
+        QueryIndex index = new SolrQueryIndex("solr", server, configuration);
+        FilterImpl filter = new FilterImpl(mock(SelectorImpl.class), "");
+        filter.restrictPath("/somenode", Filter.PathRestriction.ALL_CHILDREN);
+        Cursor cursor = index.query(filter, store.getRoot());
+        assertNotNull(cursor);
+        assertTrue(cursor.hasNext());
+        assertEquals("/somenode/child1", cursor.next().getPath());
+        assertTrue(cursor.hasNext());
+        assertEquals("/somenode/child2/descendant", cursor.next().getPath());
+        assertTrue(cursor.hasNext());
+        assertEquals("/somenode/child2", cursor.next().getPath());
+        assertTrue(cursor.hasNext());
+        assertEquals("/somenode", cursor.next().getPath());
+        assertFalse(cursor.hasNext());
+    }
+
+    @Test
+    public void testPropertyFiltering() throws Exception {
+        Root root = createRoot();
+        Tree tree = root.getTree("/");
+        tree.addChild("somenode").setProperty("foo", "bar");
+        tree.addChild("someothernode").setProperty("foo", "bard");
+        tree.addChild("anotherone").setProperty("foo", "a fool's bar");
+        root.commit();
+
+        QueryIndex index = new SolrQueryIndex("solr", server, configuration);
+        FilterImpl filter = new FilterImpl(mock(SelectorImpl.class), "");
         filter.restrictProperty("foo", Operator.EQUAL, PropertyValues.newString("bar"));
         Cursor cursor = index.query(filter, store.getRoot());
         assertNotNull(cursor);
         assertTrue(cursor.hasNext());
         assertEquals("/somenode", cursor.next().getPath());
+        assertTrue(cursor.hasNext());
+        assertEquals("/anotherone", cursor.next().getPath());
+        assertFalse(cursor.hasNext());
+    }
+
+    @Test
+    public void testPrimaryTypeFiltering() throws Exception {
+        Root root = createRoot();
+        Tree tree = root.getTree("/");
+        tree.addChild("asamplenode").setProperty("jcr:primaryType", "nt:unstructured");
+        tree.addChild("afoldernode").setProperty("jcr:primaryType", "nt:folder");
+        tree.addChild("anothersamplenode").setProperty("jcr:primaryType", "nt:unstructured");
+        root.commit();
+
+        QueryIndex index = new SolrQueryIndex("solr", server, configuration);
+        SelectorImpl selector = mock(SelectorImpl.class);
+        Set<String> primaryTypes = new HashSet<String>();
+        primaryTypes.add("nt:folder");
+        when(selector.getPrimaryTypes()).thenReturn(primaryTypes);
+        FilterImpl filter = new FilterImpl(selector, "select * from [nt:folder]");
+        Cursor cursor = index.query(filter, store.getRoot());
+        assertNotNull(cursor);
+        assertTrue(cursor.hasNext());
+        assertEquals("/afoldernode", cursor.next().getPath());
         assertFalse(cursor.hasNext());
     }
 



Mime
View raw message