jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1355058 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/lucene/ main/java/org/apache/jackrabbit/oak/plugins/memory/ test/java/org/apache/jackrabbit/oak/plugins/lucene/
Date Thu, 28 Jun 2012 16:08:51 GMT
Author: jukka
Date: Thu Jun 28 16:08:50 2012
New Revision: 1355058

URL: http://svn.apache.org/viewvc?rev=1355058&view=rev
Log:
OAK-154: Full text search index

Convert LuceneObserver to a commit editor that can store the index inside the repository

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneEditor.java
      - copied, changed from r1355043, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneObserver.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneEditorTest.java
      - copied, changed from r1355043, jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneObserverTest.java
Removed:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneObserver.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneObserverTest.java
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/OakDirectory.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStore.java

Copied: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneEditor.java
(from r1355043, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneObserver.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneEditor.java?p2=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneEditor.java&p1=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneObserver.java&r1=1355043&r2=1355058&rev=1355058&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneObserver.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneEditor.java
Thu Jun 28 16:08:50 2012
@@ -20,13 +20,15 @@ import java.io.IOException;
 
 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.spi.commit.Observer;
+import org.apache.jackrabbit.oak.spi.commit.CommitEditor;
 import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.jackrabbit.oak.spi.state.NodeStateDiff;
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
+import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.analysis.standard.StandardAnalyzer;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
@@ -35,31 +37,33 @@ import org.apache.lucene.document.Field.
 import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.index.IndexWriterConfig;
 import org.apache.lucene.index.Term;
-import org.apache.lucene.store.Directory;
 import org.apache.lucene.util.Version;
 import org.apache.tika.Tika;
 import org.apache.tika.exception.TikaException;
 
-public class LuceneObserver implements Observer {
+public class LuceneEditor implements CommitEditor {
 
     private static final Tika TIKA = new Tika();
 
     private static final Version VERSION = Version.LUCENE_36;
 
-    private static final IndexWriterConfig CONFIG =
-            new IndexWriterConfig(VERSION, new StandardAnalyzer(VERSION));
+    private static final Analyzer ANALYZER = new StandardAnalyzer(VERSION);
 
-    private final Directory directory;
+    private final String[] path;
 
-    public LuceneObserver(Directory directory) {
-        this.directory = directory;
+    public LuceneEditor(String... path) {
+        this.path = path;
     }
 
     @Override
-    public void contentChanged(
-            NodeStore store, NodeState before, NodeState after) {
+    public NodeState editCommit(
+            NodeStore store, NodeState before, NodeState after)
+            throws CommitFailedException {
         try {
-            IndexWriter writer = new IndexWriter(directory, CONFIG);
+            OakDirectory directory = new OakDirectory(store, after, path);
+
+            IndexWriter writer = new IndexWriter(
+                    directory, new IndexWriterConfig(VERSION, ANALYZER));
             try {
                 LuceneDiff diff = new LuceneDiff(store, writer, "");
                 store.compare(before, after, diff);
@@ -68,8 +72,11 @@ public class LuceneObserver implements O
             } finally {
                 writer.close();
             }
+
+            return directory.getRoot();
         } catch (IOException e) {
-            e.printStackTrace();
+            throw new CommitFailedException(
+                    "Failed to update the full text search index", e);
         }
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/OakDirectory.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/OakDirectory.java?rev=1355058&r1=1355057&r2=1355058&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/OakDirectory.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/OakDirectory.java
Thu Jun 28 16:08:50 2012
@@ -34,8 +34,9 @@ import org.apache.jackrabbit.oak.spi.sta
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.IndexInput;
 import org.apache.lucene.store.IndexOutput;
+import org.apache.lucene.store.NoLockFactory;
 
-public class OakDirectory extends Directory {
+class OakDirectory extends Directory {
 
     private final NodeStore store;
 
@@ -49,7 +50,8 @@ public class OakDirectory extends Direct
 
     private NodeState directory;
 
-    private OakDirectory(NodeStore store, NodeState root, String... path) {
+    public OakDirectory(NodeStore store, NodeState root, String... path) {
+        this.lockFactory = NoLockFactory.getNoLockFactory();
         this.store = store;
         this.factory = store.getValueFactory();
         this.path = path;
@@ -169,10 +171,11 @@ public class OakDirectory extends Direct
             @Override
             public void readBytes(byte[] b, int offset, int len)
                     throws IOException {
-                if (offset < 0 || len < 0 || position + len > data.length) {
+                if (len < 0 || position + len > data.length) {
                     throw new IOException("Invalid byte range request");
                 } else {
                     System.arraycopy(data, position, b, offset, len);
+                    position += len;
                 }
             }
 
@@ -228,11 +231,11 @@ public class OakDirectory extends Direct
         }
 
         if (value != null) {
-            int size = (int) value.length();
-            byte[] buffer = new byte[size];
-
             InputStream stream = value.getNewStream();
             try {
+                byte[] buffer = new byte[(int) value.length()];
+
+                int size = 0;
                 do {
                     int n = stream.read(buffer, size, buffer.length - size);
                     if (n == -1) {
@@ -241,11 +244,11 @@ public class OakDirectory extends Direct
                     }
                     size += n;
                 } while (size < buffer.length);
+
+                return buffer;
             } finally {
                 stream.close();
             }
-
-            return buffer;
         } else {
             return new byte[0];
         }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStore.java?rev=1355058&r1=1355057&r2=1355058&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStore.java
Thu Jun 28 16:08:50 2012
@@ -29,6 +29,9 @@ public abstract class MemoryNodeStore ex
 
     @Override
     public NodeStateBuilder getBuilder(NodeState base) {
+        if (base == null) {
+            base = MemoryNodeState.EMPTY_NODE;
+        }
         return new MemoryNodeStateBuilder(base);
     }
 

Copied: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneEditorTest.java
(from r1355043, jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneObserverTest.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneEditorTest.java?p2=jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneEditorTest.java&p1=jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneObserverTest.java&r1=1355043&r2=1355058&rev=1355058&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneObserverTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneEditorTest.java
Thu Jun 28 16:08:50 2012
@@ -26,31 +26,27 @@ import org.apache.jackrabbit.oak.core.De
 import org.apache.jackrabbit.oak.core.RootImpl;
 import org.apache.jackrabbit.oak.kernel.KernelNodeStore;
 import org.apache.jackrabbit.oak.plugins.memory.MemoryValueFactory;
-import org.apache.jackrabbit.oak.spi.commit.EmptyEditor;
-import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.RAMDirectory;
 import org.junit.Test;
 
-public class LuceneObserverTest {
+public class LuceneEditorTest {
 
     @Test
     public void testLucene() throws Exception {
         MicroKernel mk = new MicroKernelImpl();
-        KernelNodeStore store = new KernelNodeStore(mk, new EmptyEditor());
+        KernelNodeStore store = new KernelNodeStore(
+                mk, new LuceneEditor("jcr:system", "oak:lucene"));
         Root root = new RootImpl(store, "");
         Tree tree = root.getTree("/");
+        System.out.println(store.getRoot());
 
-        NodeState before = store.getRoot();
         tree.setProperty("foo", MemoryValueFactory.INSTANCE.createValue("bar"));
         root.commit(DefaultConflictHandler.OURS);
-        NodeState after = store.getRoot();
-
-        Directory directory = new RAMDirectory();
-        LuceneObserver observer = new LuceneObserver(directory);
-        observer.contentChanged(store, before, after);
 
+        Directory directory = new OakDirectory(
+                store, store.getRoot(), "jcr:system", "oak:lucene");
+        System.out.println(store.getRoot());
         IndexReader reader = IndexReader.open(directory);
         try {
             assertEquals(1, reader.numDocs());



Mime
View raw message