jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexparvule...@apache.org
Subject svn commit: r1411601 - in /jackrabbit/oak/trunk/oak-lucene/src: main/java/org/apache/jackrabbit/oak/plugins/index/lucene/ test/java/org/apache/jackrabbit/oak/plugins/index/lucene/
Date Tue, 20 Nov 2012 09:39:18 GMT
Author: alexparvulescu
Date: Tue Nov 20 09:39:17 2012
New Revision: 1411601

URL: http://svn.apache.org/viewvc?rev=1411601&view=rev
Log:
OAK-154 Full text search index
 - tweaked child node handling in the lucene index (events fornew children, paths in the index)

Modified:
    jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexDiff.java
    jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexUpdate.java
    jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexTest.java

Modified: jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexDiff.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexDiff.java?rev=1411601&r1=1411600&r2=1411601&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexDiff.java
(original)
+++ jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexDiff.java
Tue Nov 20 09:39:17 2012
@@ -31,6 +31,7 @@ import org.apache.jackrabbit.oak.plugins
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.jackrabbit.oak.spi.state.NodeStateUtils;
+import org.apache.jackrabbit.oak.spi.state.ReadOnlyBuilder;
 
 /**
  * {@link IndexHook} implementation that is responsible for keeping the
@@ -142,8 +143,9 @@ public class LuceneIndexDiff implements 
             return;
         }
         for (LuceneIndexUpdate update : updates.values()) {
-            update.insert(concat(getPath(), name), node);
+            update.insert(concat(getPath(), name), new ReadOnlyBuilder(after));
         }
+        after.compareAgainstBaseState(MemoryNodeState.EMPTY_NODE, child(name));
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexUpdate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexUpdate.java?rev=1411601&r1=1411600&r2=1411601&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexUpdate.java
(original)
+++ jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexUpdate.java
Tue Nov 20 09:39:17 2012
@@ -16,7 +16,6 @@
  */
 package org.apache.jackrabbit.oak.plugins.index.lucene;
 
-import static org.apache.jackrabbit.oak.commons.PathUtils.concat;
 import static org.apache.jackrabbit.oak.plugins.index.lucene.FieldFactory.newPathField;
 import static org.apache.jackrabbit.oak.plugins.index.lucene.FieldFactory.newPropertyField;
 import static org.apache.jackrabbit.oak.plugins.index.lucene.TermFactory.newPathTerm;
@@ -34,10 +33,8 @@ import org.apache.jackrabbit.oak.api.Blo
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Type;
-import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
-import org.apache.jackrabbit.oak.spi.state.NodeStateUtils;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.index.IndexWriterConfig;
@@ -139,7 +136,10 @@ class LuceneIndexUpdate implements Close
     private void deleteSubtreeWriter(IndexWriter writer, String path)
             throws IOException {
         // TODO verify the removal of the entire sub-hierarchy
-         writer.deleteDocuments(newPathTerm(path));
+        if (!path.startsWith("/")) {
+            path = "/" + path;
+        }
+        writer.deleteDocuments(newPathTerm(path));
         if (!path.endsWith("/")) {
             path += "/";
         }
@@ -148,14 +148,17 @@ class LuceneIndexUpdate implements Close
 
     private void addSubtreeWriter(IndexWriter writer, String path,
             NodeState state) throws IOException {
-        writer.updateDocument(newPathTerm(path), makeDocument(path, state));
-        for (ChildNodeEntry entry : state.getChildNodeEntries()) {
-            if (NodeStateUtils.isHidden(entry.getName())) {
-                continue;
-            }
-            addSubtreeWriter(writer, concat(path, entry.getName()),
-                    entry.getNodeState());
+        if (!path.startsWith("/")) {
+            path = "/" + path;
         }
+        writer.updateDocument(newPathTerm(path), makeDocument(path, state));
+        // for (ChildNodeEntry entry : state.getChildNodeEntries()) {
+        // if (NodeStateUtils.isHidden(entry.getName())) {
+        // continue;
+        // }
+        // addSubtreeWriter(writer, concat(path, entry.getName()),
+        // entry.getNodeState(), paths);
+        // }
     }
 
     private static Document makeDocument(String path, NodeState state) {
@@ -193,4 +196,10 @@ class LuceneIndexUpdate implements Close
         remove.clear();
         insert.clear();
     }
+
+    @Override
+    public String toString() {
+        return "LuceneIndexUpdate [path=" + path + ", insert=" + insert
+                + ", remove=" + remove + "]";
+    }
 }

Modified: jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexTest.java?rev=1411601&r1=1411600&r2=1411601&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexTest.java
(original)
+++ jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexTest.java
Tue Nov 20 09:39:17 2012
@@ -16,10 +16,10 @@
  */
 package org.apache.jackrabbit.oak.plugins.index.lucene;
 
-import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
 import static junit.framework.Assert.assertEquals;
 import static junit.framework.Assert.assertFalse;
 import static junit.framework.Assert.assertTrue;
+import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
 
 import org.apache.jackrabbit.oak.plugins.index.IndexDefinition;
 import org.apache.jackrabbit.oak.plugins.index.IndexDefinitionImpl;
@@ -68,4 +68,43 @@ public class LuceneIndexTest implements 
         assertFalse(cursor.hasNext());
     }
 
+    @Test
+    public void testLucene2() throws Exception {
+        NodeState root = MemoryNodeState.EMPTY_NODE;
+
+        NodeBuilder builder = root.builder();
+        builder.child("oak:index").child("lucene")
+                .setProperty(JCR_PRIMARYTYPE, INDEX_DEFINITIONS_NODE_TYPE)
+                .setProperty("type", TYPE_LUCENE);
+
+        NodeState before = builder.getNodeState();
+        builder.setProperty("foo", "bar");
+        builder.child("a").setProperty("foo", "bar");
+        builder.child("a").child("b").setProperty("foo", "bar");
+        builder.child("a").child("b").child("c").setProperty("foo", "bar");
+
+        NodeState after = builder.getNodeState();
+
+        IndexHook l = new LuceneIndexDiff(builder);
+        after.compareAgainstBaseState(before, l);
+        l.apply();
+        l.close();
+
+        IndexDefinition testDef = new IndexDefinitionImpl("lucene",
+                TYPE_LUCENE, "/oak:index/lucene");
+        QueryIndex queryIndex = new LuceneIndex(testDef);
+        FilterImpl filter = new FilterImpl(null, null);
+        // filter.restrictPath("/", Filter.PathRestriction.EXACT);
+        filter.restrictProperty("foo", Operator.EQUAL,
+                PropertyValues.newString("bar"));
+        Cursor cursor = queryIndex.query(filter, builder.getNodeState());
+
+        assertTrue(cursor.hasNext());
+        assertEquals("/", cursor.next().getPath());
+        assertEquals("/a", cursor.next().getPath());
+        assertEquals("/a/b", cursor.next().getPath());
+        assertEquals("/a/b/c", cursor.next().getPath());
+        assertFalse(cursor.hasNext());
+    }
+
 }



Mime
View raw message