jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexparvule...@apache.org
Subject svn commit: r1391071 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/lucene/ main/java/org/apache/jackrabbit/oak/spi/query/ test/java/org/apache/jackrabbit/oak/plugins/lucene/
Date Thu, 27 Sep 2012 15:57:44 GMT
Author: alexparvulescu
Date: Thu Sep 27 15:57:43 2012
New Revision: 1391071

URL: http://svn.apache.org/viewvc?rev=1391071&view=rev
Log:
OAK-340 Basic reindex support in the lucene index

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneEditor.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndex.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndexConstants.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneReindexHook.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexDefinitionImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexUtils.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/lucene/AbstractLuceneQueryTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneEditor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneEditor.java?rev=1391071&r1=1391070&r2=1391071&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneEditor.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneEditor.java
Thu Sep 27 15:57:43 2012
@@ -17,10 +17,10 @@
 package org.apache.jackrabbit.oak.plugins.lucene;
 
 import static org.apache.jackrabbit.oak.commons.PathUtils.concat;
+import static org.apache.jackrabbit.oak.commons.PathUtils.elements;
 import static org.apache.jackrabbit.oak.plugins.lucene.FieldFactory.newPathField;
 import static org.apache.jackrabbit.oak.plugins.lucene.FieldFactory.newPropertyField;
 import static org.apache.jackrabbit.oak.plugins.lucene.TermFactory.newPathTerm;
-import static org.apache.jackrabbit.oak.spi.query.IndexUtils.split;
 
 import java.io.IOException;
 
@@ -29,6 +29,7 @@ import javax.jcr.PropertyType;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.CoreValue;
 import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.plugins.memory.LongValue;
 import org.apache.jackrabbit.oak.spi.commit.CommitHook;
 import org.apache.jackrabbit.oak.spi.query.IndexDefinition;
 import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
@@ -71,10 +72,10 @@ class LuceneEditor implements CommitHook
         }
     }
 
-    private final String[] path;
+    private final Iterable<String> path;
 
     public LuceneEditor(IndexDefinition indexDefinition) {
-        this.path = split(indexDefinition.getPath(), INDEX_DATA_CHILD_NAME);
+        this.path = elements(indexDefinition.getPath());
     }
 
     /*
@@ -90,7 +91,7 @@ class LuceneEditor implements CommitHook
         for (String name : path) {
             builder = builder.getChildBuilder(name);
         }
-        Directory directory = new ReadWriteOakDirectory(builder);
+        Directory directory = new ReadWriteOakDirectory(builder.getChildBuilder(INDEX_DATA_CHILD_NAME));
 
         try {
             IndexWriter writer = new IndexWriter(directory, config);
@@ -107,6 +108,8 @@ class LuceneEditor implements CommitHook
 
                 diff.postProcess(after);
                 writer.commit();
+                builder.setProperty(INDEX_UPDATE,
+                        new LongValue(System.currentTimeMillis()));
             } finally {
                 writer.close();
             }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndex.java?rev=1391071&r1=1391070&r2=1391071&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndex.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndex.java
Thu Sep 27 15:57:43 2012
@@ -16,10 +16,10 @@
  */
 package org.apache.jackrabbit.oak.plugins.lucene;
 
+import static org.apache.jackrabbit.oak.commons.PathUtils.elements;
 import static org.apache.jackrabbit.oak.plugins.lucene.FieldNames.PATH;
 import static org.apache.jackrabbit.oak.plugins.lucene.FieldNames.PATH_SELECTOR;
 import static org.apache.jackrabbit.oak.plugins.lucene.TermFactory.newPathTerm;
-import static org.apache.jackrabbit.oak.spi.query.IndexUtils.split;
 
 import java.io.IOException;
 import java.util.ArrayList;
@@ -65,12 +65,11 @@ public class LuceneIndex implements Quer
 
     private final IndexDefinition index;
 
-    private final String[] indexDataPath;
+    private final Iterable<String> path;
 
     public LuceneIndex(IndexDefinition indexDefinition) {
         this.index = indexDefinition;
-        this.indexDataPath = split(indexDefinition.getPath(),
-                INDEX_DATA_CHILD_NAME);
+        this.path = elements(indexDefinition.getPath());
     }
 
     @Override
@@ -92,9 +91,15 @@ public class LuceneIndex implements Quer
     public Cursor query(Filter filter, String revisionId, NodeState root) {
 
         NodeBuilder builder = new ReadOnlyBuilder(root);
-        for (String name : indexDataPath) {
+        for (String name : path) {
             builder = builder.getChildBuilder(name);
         }
+        if (!builder.hasChildNode(INDEX_DATA_CHILD_NAME)) {
+            // index not initialized yet
+            return new PathCursor(Collections.<String> emptySet());
+        }
+        builder = builder.getChildBuilder(INDEX_DATA_CHILD_NAME);
+
         Directory directory = new ReadOnlyOakDirectory(builder);
         long s = System.currentTimeMillis();
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndexConstants.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndexConstants.java?rev=1391071&r1=1391070&r2=1391071&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndexConstants.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndexConstants.java
Thu Sep 27 15:57:43 2012
@@ -24,4 +24,6 @@ public interface LuceneIndexConstants {
 
     String INDEX_DATA_CHILD_NAME = ":data";
 
+    String INDEX_UPDATE = "indexUpdate";
+
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneReindexHook.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneReindexHook.java?rev=1391071&r1=1391070&r2=1391071&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneReindexHook.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneReindexHook.java
Thu Sep 27 15:57:43 2012
@@ -32,7 +32,13 @@ import org.slf4j.LoggerFactory;
  * A {@link CommitHook} that handles re-indexing and initial indexing of the
  * content.
  * 
- * Currently it triggers a full reindex on any detected index definition change.
+ * Currently it triggers a full reindex on any detected index definition change
+ * (excepting the properties) OR on removing the
+ * {@link LuceneIndexConstants#INDEX_UPDATE} property
+ * 
+ * Warning: This hook has to be placed before the updater {@link LuceneHook},
+ * otherwise it is going to miss the {@link LuceneIndexConstants#INDEX_UPDATE}
+ * change to null
  * 
  */
 public class LuceneReindexHook implements CommitHook, LuceneIndexConstants {
@@ -68,6 +74,10 @@ public class LuceneReindexHook implement
             if (!defsBefore.contains(def)) {
                 defsChanged.add(def);
             }
+            // verify initial state or forced reindex
+            if (def.getProperties().get(INDEX_UPDATE) == null) {
+                defsChanged.add(def);
+            }
         }
         if (defsChanged.isEmpty()) {
             return after;

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexDefinitionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexDefinitionImpl.java?rev=1391071&r1=1391070&r2=1391071&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexDefinitionImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexDefinitionImpl.java
Thu Sep 27 15:57:43 2012
@@ -82,8 +82,7 @@ public class IndexDefinitionImpl impleme
         final int prime = 31;
         int result = 1;
         result = prime * result + ((name == null) ? 0 : name.hashCode());
-        result = prime * result
-                + ((properties == null) ? 0 : properties.hashCode());
+        result = prime * result + ((path == null) ? 0 : path.hashCode());
         result = prime * result + ((type == null) ? 0 : type.hashCode());
         result = prime * result + (unique ? 1231 : 1237);
         return result;
@@ -103,10 +102,10 @@ public class IndexDefinitionImpl impleme
                 return false;
         } else if (!name.equals(other.name))
             return false;
-        if (properties == null) {
-            if (other.properties != null)
+        if (path == null) {
+            if (other.path != null)
                 return false;
-        } else if (!properties.equals(other.properties))
+        } else if (!path.equals(other.path))
             return false;
         if (type == null) {
             if (other.type != null)
@@ -117,4 +116,5 @@ public class IndexDefinitionImpl impleme
             return false;
         return true;
     }
+
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexUtils.java?rev=1391071&r1=1391070&r2=1391071&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexUtils.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexUtils.java
Thu Sep 27 15:57:43 2012
@@ -71,25 +71,6 @@ public class IndexUtils {
     }
 
     /**
-     * Splits a give path into its segments and optionally appends a new path to
-     * the resulting array
-     * 
-     * @return array containing the path segments
-     */
-    public static String[] split(String pathIn, String append) {
-        List<String> paths = new ArrayList<String>();
-        for (String p : pathIn.split("/")) {
-            if (p.trim().length() != 0) {
-                paths.add(p);
-            }
-        }
-        if (append != null && append.trim().length() != 0) {
-            paths.add(append);
-        }
-        return paths.toArray(new String[paths.size()]);
-    }
-
-    /**
      * @return the 'destination' node if the path exists, null if otherwise
      */
     public static NodeState getNode(NodeState nodeState, String destination) {

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/lucene/AbstractLuceneQueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/lucene/AbstractLuceneQueryTest.java?rev=1391071&r1=1391070&r2=1391071&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/lucene/AbstractLuceneQueryTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/lucene/AbstractLuceneQueryTest.java
Thu Sep 27 15:57:43 2012
@@ -65,8 +65,8 @@ public abstract class AbstractLuceneQuer
     protected ContentRepository createRepository() {
         QueryIndexProvider qip = new CompositeQueryIndexProvider(
                 new LuceneIndexProvider(DEFAULT_INDEX_HOME));
-        CommitHook ch = new CompositeHook(new LuceneHook(DEFAULT_INDEX_HOME),
-                new LuceneReindexHook(DEFAULT_INDEX_HOME));
+        CommitHook ch = new CompositeHook(new LuceneReindexHook(
+                DEFAULT_INDEX_HOME), new LuceneHook(DEFAULT_INDEX_HOME));
         return new ContentRepositoryImpl(new MicroKernelImpl(), qip, ch);
     }
 



Mime
View raw message