jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexparvule...@apache.org
Subject svn commit: r1521152 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/aggregate/AggregateIndex.java oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexAggregationTest.java
Date Mon, 09 Sep 2013 15:09:47 GMT
Author: alexparvulescu
Date: Mon Sep  9 15:09:46 2013
New Revision: 1521152

URL: http://svn.apache.org/r1521152
Log:
OAK-828 Full-text support for index aggregates
 - added fix to prevent duplication of aggregation results


Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/aggregate/AggregateIndex.java
    jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexAggregationTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/aggregate/AggregateIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/aggregate/AggregateIndex.java?rev=1521152&r1=1521151&r2=1521152&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/aggregate/AggregateIndex.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/aggregate/AggregateIndex.java
Mon Sep  9 15:09:46 2013
@@ -16,8 +16,10 @@
  */
 package org.apache.jackrabbit.oak.plugins.index.aggregate;
 
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.NoSuchElementException;
+import java.util.Set;
 
 import org.apache.jackrabbit.oak.query.index.FilterImpl;
 import org.apache.jackrabbit.oak.query.index.IndexRowImpl;
@@ -28,6 +30,8 @@ import org.apache.jackrabbit.oak.spi.que
 import org.apache.jackrabbit.oak.spi.query.QueryIndex.FulltextQueryIndex;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 
+import com.google.common.base.Predicate;
+import com.google.common.base.Predicates;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterators;
 
@@ -101,10 +105,22 @@ public class AggregateIndex implements F
 
         private boolean init;
         private boolean closed;
-        private Iterator<String> aggregates;
 
+        /**
+         * current item of the cursor
+         */
         private String item;
 
+        /**
+         * all of the item's known aggregates
+         */
+        private Iterator<String> aggregates;
+
+        /**
+         * should enforce uniqueness of the aggregated paths
+         */
+        private Set<String> seenPaths = new HashSet<String>();
+
         public AggregationCursor(Cursor cursor, NodeAggregator aggregator,
                 NodeState rootState) {
             this.cursor = cursor;
@@ -131,8 +147,10 @@ public class AggregateIndex implements F
             if (cursor.hasNext()) {
                 IndexRow row = cursor.next();
                 String path = row.getPath();
-                aggregates = Iterators.concat(ImmutableSet.of(path).iterator(),
-                        aggregator.getParents(rootState, path));
+                aggregates = Iterators.filter(Iterators.concat(
+                        ImmutableSet.of(path).iterator(),
+                        aggregator.getParents(rootState, path)), Predicates
+                        .not(Predicates.in(seenPaths)));
                 fetchNext();
                 return;
             }
@@ -144,6 +162,7 @@ public class AggregateIndex implements F
             if (!hasNext()) {
                 throw new NoSuchElementException();
             }
+            seenPaths.add(item);
             init = false;
             return new IndexRowImpl(item);
         }

Modified: jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexAggregationTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexAggregationTest.java?rev=1521152&r1=1521151&r2=1521152&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexAggregationTest.java
(original)
+++ jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexAggregationTest.java
Mon Sep  9 15:09:46 2013
@@ -278,4 +278,24 @@ public class LuceneIndexAggregationTest 
 
     }
 
+    @Test
+    public void testPreventDoubleAggregation() throws Exception {
+        Tree file = root.getTree("/").addChild("myFile");
+        file.setProperty(JCR_PRIMARYTYPE, NT_FILE, Type.NAME);
+        file.setProperty("jcr:title", "fox");
+
+        Tree resource = file.addChild(JCR_CONTENT);
+        resource.setProperty(JCR_PRIMARYTYPE, "nt:resource", Type.NAME);
+        resource.setProperty("jcr:lastModified", Calendar.getInstance());
+        resource.setProperty("jcr:encoding", "UTF-8");
+        resource.setProperty("jcr:mimeType", "text/plain");
+        resource.setProperty(binaryProperty(JCR_DATA,
+                "the quick brown fox jumps over the lazy dog."));
+        root.commit();
+
+        String matchChildSimple = "//element(*, nt:file)[( jcr:contains(., 'fox') )]";
+        assertQuery(matchChildSimple, "xpath",
+                ImmutableList.of("/myFile"));
+    }
+
 }



Mime
View raw message