lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jan...@apache.org
Subject svn commit: r1487777 [26/50] - in /lucene/dev/branches/security: ./ dev-tools/ dev-tools/eclipse/dot.settings/ dev-tools/idea/.idea/ dev-tools/idea/.idea/libraries/ dev-tools/idea/lucene/replicator/ dev-tools/maven/ dev-tools/maven/lucene/ dev-tools/ma...
Date Thu, 30 May 2013 07:53:46 GMT
Modified: lucene/dev/branches/security/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyReader.java?rev=1487777&r1=1487776&r2=1487777&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyReader.java (original)
+++ lucene/dev/branches/security/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyReader.java Thu May 30 07:53:18 2013
@@ -1,12 +1,16 @@
 package org.apache.lucene.facet.taxonomy.directory;
 
 import java.io.IOException;
+import java.util.Arrays;
+import java.util.HashSet;
 import java.util.Random;
+import java.util.Set;
 
 import org.apache.lucene.analysis.MockAnalyzer;
 import org.apache.lucene.facet.FacetTestCase;
 import org.apache.lucene.facet.taxonomy.CategoryPath;
 import org.apache.lucene.facet.taxonomy.TaxonomyReader;
+import org.apache.lucene.facet.taxonomy.TaxonomyReader.ChildrenIterator;
 import org.apache.lucene.facet.taxonomy.TaxonomyWriter;
 import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.index.IndexWriterConfig;
@@ -461,5 +465,69 @@ public class TestDirectoryTaxonomyReader
     
     src.close();
   }
+
+  @Test
+  public void testGetChildren() throws Exception {
+    Directory dir = newDirectory();
+    DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(dir);
+    int numCategories = atLeast(10);
+    int numA = 0, numB = 0;
+    Random random = random();
+    for (int i = 0; i < numCategories; i++) {
+      if (random.nextBoolean()) {
+        taxoWriter.addCategory(new CategoryPath("a", Integer.toString(i)));
+        ++numA;
+      } else {
+        taxoWriter.addCategory(new CategoryPath("b", Integer.toString(i)));
+        ++numB;
+      }
+    }
+    // add category with no children
+    taxoWriter.addCategory(new CategoryPath("c"));
+    taxoWriter.close();
+    
+    DirectoryTaxonomyReader taxoReader = new DirectoryTaxonomyReader(dir);
+
+    // non existing category
+    ChildrenIterator it = taxoReader.getChildren(taxoReader.getOrdinal(new CategoryPath("invalid")));
+    assertEquals(TaxonomyReader.INVALID_ORDINAL, it.next());
+
+    // a category with no children
+    it = taxoReader.getChildren(taxoReader.getOrdinal(new CategoryPath("c")));
+    assertEquals(TaxonomyReader.INVALID_ORDINAL, it.next());
+
+    // arbitrary negative ordinal
+    it = taxoReader.getChildren(-2);
+    assertEquals(TaxonomyReader.INVALID_ORDINAL, it.next());
+
+    // root's children
+    Set<String> roots = new HashSet<String>(Arrays.asList("a", "b", "c"));
+    it = taxoReader.getChildren(TaxonomyReader.ROOT_ORDINAL);
+    while (!roots.isEmpty()) {
+      CategoryPath root = taxoReader.getPath(it.next());
+      assertEquals(1, root.length);
+      assertTrue(roots.remove(root.components[0]));
+    }
+    assertEquals(TaxonomyReader.INVALID_ORDINAL, it.next());
+    
+    for (int i = 0; i < 2; i++) {
+      CategoryPath cp = i == 0 ? new CategoryPath("a") : new CategoryPath("b");
+      int ordinal = taxoReader.getOrdinal(cp);
+      it = taxoReader.getChildren(ordinal);
+      int numChildren = 0;
+      int child;
+      while ((child = it.next()) != TaxonomyReader.INVALID_ORDINAL) {
+        CategoryPath path = taxoReader.getPath(child);
+        assertEquals(2, path.length);
+        assertEquals(path.components[0], i == 0 ? "a" : "b");
+        ++numChildren;
+      }
+      int expected = i == 0 ? numA : numB;
+      assertEquals("invalid num children", expected, numChildren);
+    }
+    taxoReader.close();
+    
+    dir.close();
+  }
   
 }

Modified: lucene/dev/branches/security/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyWriter.java?rev=1487777&r1=1487776&r2=1487777&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyWriter.java (original)
+++ lucene/dev/branches/security/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyWriter.java Thu May 30 07:53:18 2013
@@ -359,5 +359,58 @@ public class TestDirectoryTaxonomyWriter
     taxoWriter.close();
     dir.close();
   }
+
+  @Test
+  public void testCommitNoEmptyCommits() throws Exception {
+    // LUCENE-4972: DTW used to create empty commits even if no changes were made
+    Directory dir = newDirectory();
+    DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(dir);
+    taxoWriter.addCategory(new CategoryPath("a"));
+    taxoWriter.commit();
+    
+    long gen1 = SegmentInfos.getLastCommitGeneration(dir);
+    taxoWriter.commit();
+    long gen2 = SegmentInfos.getLastCommitGeneration(dir);
+    assertEquals("empty commit should not have changed the index", gen1, gen2);
+    
+    taxoWriter.close();
+    dir.close();
+  }
+  
+  @Test
+  public void testCloseNoEmptyCommits() throws Exception {
+    // LUCENE-4972: DTW used to create empty commits even if no changes were made
+    Directory dir = newDirectory();
+    DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(dir);
+    taxoWriter.addCategory(new CategoryPath("a"));
+    taxoWriter.commit();
+    
+    long gen1 = SegmentInfos.getLastCommitGeneration(dir);
+    taxoWriter.close();
+    long gen2 = SegmentInfos.getLastCommitGeneration(dir);
+    assertEquals("empty commit should not have changed the index", gen1, gen2);
+    
+    taxoWriter.close();
+    dir.close();
+  }
+  
+  @Test
+  public void testPrepareCommitNoEmptyCommits() throws Exception {
+    // LUCENE-4972: DTW used to create empty commits even if no changes were made
+    Directory dir = newDirectory();
+    DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(dir);
+    taxoWriter.addCategory(new CategoryPath("a"));
+    taxoWriter.prepareCommit();
+    taxoWriter.commit();
+    
+    long gen1 = SegmentInfos.getLastCommitGeneration(dir);
+    taxoWriter.prepareCommit();
+    taxoWriter.commit();
+    long gen2 = SegmentInfos.getLastCommitGeneration(dir);
+    assertEquals("empty commit should not have changed the index", gen1, gen2);
+    
+    taxoWriter.close();
+    dir.close();
+  }
   
 }

Modified: lucene/dev/branches/security/lucene/facet/src/test/org/apache/lucene/facet/util/TestFacetsPayloadMigrationReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/facet/src/test/org/apache/lucene/facet/util/TestFacetsPayloadMigrationReader.java?rev=1487777&r1=1487776&r2=1487777&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/facet/src/test/org/apache/lucene/facet/util/TestFacetsPayloadMigrationReader.java (original)
+++ lucene/dev/branches/security/lucene/facet/src/test/org/apache/lucene/facet/util/TestFacetsPayloadMigrationReader.java Thu May 30 07:53:18 2013
@@ -229,7 +229,7 @@ public class TestFacetsPayloadMigrationR
       FacetIndexingParams fip) throws Exception {
     DirectoryReader indexReader = DirectoryReader.open(indexDir);
     TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);
-    IndexSearcher searcher = new IndexSearcher(indexReader);
+    IndexSearcher searcher = newSearcher(indexReader);
 
     assertFalse("index should not have deletions", indexReader.hasDeletions());
     

Modified: lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/AbstractDistinctValuesCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/AbstractDistinctValuesCollector.java?rev=1487777&r1=1487776&r2=1487777&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/AbstractDistinctValuesCollector.java (original)
+++ lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/AbstractDistinctValuesCollector.java Thu May 30 07:53:18 2013
@@ -57,7 +57,7 @@ public abstract class AbstractDistinctVa
 
     public GroupCount(GROUP_VALUE_TYPE groupValue) {
       this.groupValue = groupValue;
-      this.uniqueValues = new HashSet<GROUP_VALUE_TYPE>();
+      this.uniqueValues = new HashSet<>();
     }
   }
 

Modified: lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/AbstractFirstPassGroupingCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/AbstractFirstPassGroupingCollector.java?rev=1487777&r1=1487776&r2=1487777&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/AbstractFirstPassGroupingCollector.java (original)
+++ lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/AbstractFirstPassGroupingCollector.java Thu May 30 07:53:18 2013
@@ -85,7 +85,7 @@ abstract public class AbstractFirstPassG
     }
 
     spareSlot = topNGroups;
-    groupMap = new HashMap<GROUP_VALUE_TYPE, CollectedSearchGroup<GROUP_VALUE_TYPE>>(topNGroups);
+    groupMap = new HashMap<>(topNGroups);
   }
 
   /**
@@ -113,7 +113,7 @@ abstract public class AbstractFirstPassG
       buildSortedSet();
     }
 
-    final Collection<SearchGroup<GROUP_VALUE_TYPE>> result = new ArrayList<SearchGroup<GROUP_VALUE_TYPE>>();
+    final Collection<SearchGroup<GROUP_VALUE_TYPE>> result = new ArrayList<>();
     int upto = 0;
     final int sortFieldCount = groupSort.getSort().length;
     for(CollectedSearchGroup<GROUP_VALUE_TYPE> group : orderedGroups) {
@@ -121,7 +121,7 @@ abstract public class AbstractFirstPassG
         continue;
       }
       //System.out.println("  group=" + (group.groupValue == null ? "null" : group.groupValue.utf8ToString()));
-      SearchGroup<GROUP_VALUE_TYPE> searchGroup = new SearchGroup<GROUP_VALUE_TYPE>();
+      SearchGroup<GROUP_VALUE_TYPE> searchGroup = new SearchGroup<>();
       searchGroup.groupValue = group.groupValue;
       if (fillFields) {
         searchGroup.sortValues = new Object[sortFieldCount];
@@ -193,7 +193,7 @@ abstract public class AbstractFirstPassG
         // just keep collecting them
 
         // Add a new CollectedSearchGroup:
-        CollectedSearchGroup<GROUP_VALUE_TYPE> sg = new CollectedSearchGroup<GROUP_VALUE_TYPE>();
+        CollectedSearchGroup<GROUP_VALUE_TYPE> sg = new CollectedSearchGroup<>();
         sg.groupValue = copyDocGroupValue(groupValue, null);
         sg.comparatorSlot = groupMap.size();
         sg.topDoc = docBase + doc;
@@ -311,7 +311,7 @@ abstract public class AbstractFirstPassG
       }
     };
 
-    orderedGroups = new TreeSet<CollectedSearchGroup<GROUP_VALUE_TYPE>>(comparator);
+    orderedGroups = new TreeSet<>(comparator);
     orderedGroups.addAll(groupMap.values());
     assert orderedGroups.size() > 0;
 

Modified: lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/AbstractGroupFacetCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/AbstractGroupFacetCollector.java?rev=1487777&r1=1487776&r2=1487777&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/AbstractGroupFacetCollector.java (original)
+++ lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/AbstractGroupFacetCollector.java Thu May 30 07:53:18 2013
@@ -46,7 +46,7 @@ public abstract class AbstractGroupFacet
     this.groupField = groupField;
     this.facetField = facetField;
     this.facetPrefix = facetPrefix;
-    segmentResults = new ArrayList<SegmentResult>();
+    segmentResults = new ArrayList<>();
   }
 
   /**
@@ -148,7 +148,7 @@ public abstract class AbstractGroupFacet
     private int currentMin;
 
     public GroupedFacetResult(int size, int minCount, boolean orderByCount, int totalCount, int totalMissingCount) {
-      this.facetEntries = new TreeSet<FacetEntry>(orderByCount ? orderByCountAndValue : orderByValue);
+      this.facetEntries = new TreeSet<>(orderByCount ? orderByCountAndValue : orderByValue);
       this.totalMissingCount = totalMissingCount;
       this.totalCount = totalCount;
       maxSize = size;
@@ -183,16 +183,16 @@ public abstract class AbstractGroupFacet
      * @return a list of facet entries to be rendered based on the specified offset and limit
      */
     public List<FacetEntry> getFacetEntries(int offset, int limit) {
-      List<FacetEntry> entries = new LinkedList<FacetEntry>();
-      limit += offset;
+      List<FacetEntry> entries = new LinkedList<>();
 
-      int i = 0;
+      int skipped = 0;
+      int included = 0;
       for (FacetEntry facetEntry : facetEntries) {
-        if (i < offset) {
-          i++;
+        if (skipped < offset) {
+          skipped++;
           continue;
         }
-        if (i++ >= limit) {
+        if (included++ >= limit) {
           break;
         }
         entries.add(facetEntry);

Modified: lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/AbstractSecondPassGroupingCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/AbstractSecondPassGroupingCollector.java?rev=1487777&r1=1487776&r2=1487777&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/AbstractSecondPassGroupingCollector.java (original)
+++ lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/AbstractSecondPassGroupingCollector.java Thu May 30 07:53:18 2013
@@ -62,7 +62,7 @@ public abstract class AbstractSecondPass
     this.withinGroupSort = withinGroupSort;
     this.groups = groups;
     this.maxDocsPerGroup = maxDocsPerGroup;
-    groupMap = new HashMap<GROUP_VALUE_TYPE, SearchGroupDocs<GROUP_VALUE_TYPE>>(groups.size());
+    groupMap = new HashMap<>(groups.size());
 
     for (SearchGroup<GROUP_VALUE_TYPE> group : groups) {
       //System.out.println("  prep group=" + (group.groupValue == null ? "null" : group.groupValue.utf8ToString()));
@@ -75,7 +75,7 @@ public abstract class AbstractSecondPass
         collector = TopFieldCollector.create(withinGroupSort, maxDocsPerGroup, fillSortFields, getScores, getMaxScores, true);
       }
       groupMap.put(group.groupValue,
-          new SearchGroupDocs<GROUP_VALUE_TYPE>(group.groupValue,
+          new SearchGroupDocs<>(group.groupValue,
               collector));
     }
   }
@@ -128,7 +128,7 @@ public abstract class AbstractSecondPass
     for(SearchGroup<?> group : groups) {
       final SearchGroupDocs<GROUP_VALUE_TYPE> groupDocs = groupMap.get(group.groupValue);
       final TopDocs topDocs = groupDocs.collector.topDocs(withinGroupOffset, maxDocsPerGroup);
-      groupDocsResult[groupIDX++] = new GroupDocs<GROUP_VALUE_TYPE>(Float.NaN,
+      groupDocsResult[groupIDX++] = new GroupDocs<>(Float.NaN,
                                                                     topDocs.getMaxScore(),
                                                                     topDocs.totalHits,
                                                                     topDocs.scoreDocs,
@@ -137,7 +137,7 @@ public abstract class AbstractSecondPass
       maxScore = Math.max(maxScore, topDocs.getMaxScore());
     }
 
-    return new TopGroups<GROUP_VALUE_TYPE>(groupSort.getSort(),
+    return new TopGroups<>(groupSort.getSort(),
                                            withinGroupSort == null ? null : withinGroupSort.getSort(),
                                            totalHitCount, totalGroupedHitCount, groupDocsResult,
                                            maxScore);

Modified: lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/BlockGroupingCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/BlockGroupingCollector.java?rev=1487777&r1=1487776&r2=1487777&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/BlockGroupingCollector.java (original)
+++ lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/BlockGroupingCollector.java Thu May 30 07:53:18 2013
@@ -117,6 +117,11 @@ public class BlockGroupingCollector exte
     public int nextDoc() {
       throw new UnsupportedOperationException();
     }
+
+    @Override
+    public long cost() {
+      return 1;
+    }
   }
 
   private static final class OneGroup {
@@ -360,7 +365,7 @@ public class BlockGroupingCollector exte
 
       // TODO: we could aggregate scores across children
       // by Sum/Avg instead of passing NaN:
-      groups[downTo] = new GroupDocs<Object>(Float.NaN,
+      groups[downTo] = new GroupDocs<>(Float.NaN,
                                              topDocs.getMaxScore(),
                                              og.count,
                                              topDocs.scoreDocs,
@@ -377,7 +382,7 @@ public class BlockGroupingCollector exte
     }
     */
 
-    return new TopGroups<Object>(new TopGroups<Object>(groupSort.getSort(),
+    return new TopGroups<>(new TopGroups<>(groupSort.getSort(),
                                        withinGroupSort == null ? null : withinGroupSort.getSort(),
                                        totalHitCount, totalGroupedHitCount, groups, maxScore),
                          totalGroupCount);

Modified: lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/GroupingSearch.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/GroupingSearch.java?rev=1487777&r1=1487776&r2=1487777&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/GroupingSearch.java (original)
+++ lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/GroupingSearch.java Thu May 30 07:53:18 2013
@@ -17,11 +17,16 @@ package org.apache.lucene.search.groupin
  * limitations under the License.
  */
 
-import java.io.IOException;
-import java.util.*;
-
 import org.apache.lucene.queries.function.ValueSource;
-import org.apache.lucene.search.*;
+import org.apache.lucene.search.CachingCollector;
+import org.apache.lucene.search.Collector;
+import org.apache.lucene.search.FieldCache;
+import org.apache.lucene.search.Filter;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.MultiCollector;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.Sort;
+import org.apache.lucene.search.SortField;
 import org.apache.lucene.search.grouping.function.FunctionAllGroupHeadsCollector;
 import org.apache.lucene.search.grouping.function.FunctionAllGroupsCollector;
 import org.apache.lucene.search.grouping.function.FunctionFirstPassGroupingCollector;
@@ -34,6 +39,13 @@ import org.apache.lucene.util.Bits;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.mutable.MutableValue;
 
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
 /**
  * Convenience class to perform grouping in a non distributed environment.
  *
@@ -173,7 +185,7 @@ public class GroupingSearch {
 
     final Collector firstRound;
     if (allGroupHeads || allGroups) {
-      List<Collector> collectors = new ArrayList<Collector>();
+      List<Collector> collectors = new ArrayList<>();
       collectors.add(firstPassCollector);
       if (allGroups) {
         collectors.add(allGroupsCollector);

Modified: lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/SearchGroup.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/SearchGroup.java?rev=1487777&r1=1487776&r2=1487777&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/SearchGroup.java (original)
+++ lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/SearchGroup.java Thu May 30 07:53:18 2013
@@ -198,9 +198,9 @@ public class SearchGroup<GROUP_VALUE_TYP
     private final Map<T,MergedGroup<T>> groupsSeen;
 
     public GroupMerger(Sort groupSort) throws IOException {
-      groupComp = new GroupComparator<T>(groupSort);
-      queue = new TreeSet<MergedGroup<T>>(groupComp);
-      groupsSeen = new HashMap<T,MergedGroup<T>>();
+      groupComp = new GroupComparator<>(groupSort);
+      queue = new TreeSet<>(groupComp);
+      groupsSeen = new HashMap<>();
     }
 
     @SuppressWarnings({"unchecked","rawtypes"})

Modified: lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/TopGroups.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/TopGroups.java?rev=1487777&r1=1487776&r2=1487777&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/TopGroups.java (original)
+++ lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/TopGroups.java Thu May 30 07:53:18 2013
@@ -78,7 +78,7 @@ public class TopGroups<GROUP_VALUE_TYPE>
     Total,
     /* Avg score across all shards for this group. */
     Avg,
-  };
+  }
 
   /** Merges an array of TopGroups, for example obtained
    *  from the second-pass collector across multiple
@@ -202,7 +202,7 @@ public class TopGroups<GROUP_VALUE_TYPE>
       }
         
       //System.out.println("SHARDS=" + Arrays.toString(mergedTopDocs.shardIndex));
-      mergedGroupDocs[groupIDX] = new GroupDocs<T>(groupScore,
+      mergedGroupDocs[groupIDX] = new GroupDocs<>(groupScore,
                                                    maxScore,
                                                    totalHits,
                                                    mergedScoreDocs,
@@ -212,15 +212,15 @@ public class TopGroups<GROUP_VALUE_TYPE>
     }
 
     if (totalGroupCount != null) {
-      TopGroups<T> result = new TopGroups<T>(groupSort.getSort(),
+      TopGroups<T> result = new TopGroups<>(groupSort.getSort(),
                               docSort == null ? null : docSort.getSort(),
                               totalHitCount,
                               totalGroupedHitCount,
                               mergedGroupDocs,
                               totalMaxScore);
-      return new TopGroups<T>(result, totalGroupCount);
+      return new TopGroups<>(result, totalGroupCount);
     } else {
-      return new TopGroups<T>(groupSort.getSort(),
+      return new TopGroups<>(groupSort.getSort(),
                               docSort == null ? null : docSort.getSort(),
                               totalHitCount,
                               totalGroupedHitCount,

Modified: lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionAllGroupHeadsCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionAllGroupHeadsCollector.java?rev=1487777&r1=1487776&r2=1487777&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionAllGroupHeadsCollector.java (original)
+++ lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionAllGroupHeadsCollector.java Thu May 30 07:53:18 2013
@@ -59,7 +59,7 @@ public class FunctionAllGroupHeadsCollec
    */
   public FunctionAllGroupHeadsCollector(ValueSource groupBy, Map<?, ?> vsContext, Sort sortWithinGroup) {
     super(sortWithinGroup.getSort().length);
-    groups = new HashMap<MutableValue, GroupHead>();
+    groups = new HashMap<>();
     this.sortWithinGroup = sortWithinGroup;
     this.groupBy = groupBy;
     this.vsContext = vsContext;

Modified: lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionDistinctValuesCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionDistinctValuesCollector.java?rev=1487777&r1=1487776&r2=1487777&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionDistinctValuesCollector.java (original)
+++ lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionDistinctValuesCollector.java Thu May 30 07:53:18 2013
@@ -48,7 +48,7 @@ public class FunctionDistinctValuesColle
     this.vsContext = vsContext;
     this.groupSource = groupSource;
     this.countSource = countSource;
-    groupMap = new LinkedHashMap<MutableValue, GroupCount>();
+    groupMap = new LinkedHashMap<>();
     for (SearchGroup<MutableValue> group : groups) {
       groupMap.put(group.groupValue, new GroupCount(group.groupValue));
     }
@@ -56,7 +56,7 @@ public class FunctionDistinctValuesColle
 
   @Override
   public List<GroupCount> getGroups() {
-    return new ArrayList<GroupCount>(groupMap.values());
+    return new ArrayList<>(groupMap.values());
   }
 
   @Override

Modified: lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermAllGroupHeadsCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermAllGroupHeadsCollector.java?rev=1487777&r1=1487776&r2=1487777&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermAllGroupHeadsCollector.java (original)
+++ lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermAllGroupHeadsCollector.java Thu May 30 07:53:18 2013
@@ -17,16 +17,24 @@ package org.apache.lucene.search.groupin
  * limitations under the License.
  */
 
-import java.io.IOException;
-import java.util.*;
-
 import org.apache.lucene.index.AtomicReaderContext;
 import org.apache.lucene.index.SortedDocValues;
-import org.apache.lucene.search.*;
+import org.apache.lucene.search.FieldCache;
+import org.apache.lucene.search.FieldComparator;
+import org.apache.lucene.search.Scorer;
+import org.apache.lucene.search.Sort;
+import org.apache.lucene.search.SortField;
 import org.apache.lucene.search.grouping.AbstractAllGroupHeadsCollector;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.SentinelIntSet;
 
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 /**
  * A base implementation of {@link org.apache.lucene.search.grouping.AbstractAllGroupHeadsCollector} for retrieving the most relevant groups when grouping
  * on a string based group field. More specifically this all concrete implementations of this base implementation
@@ -115,7 +123,7 @@ public abstract class TermAllGroupHeadsC
     GeneralAllGroupHeadsCollector(String groupField, Sort sortWithinGroup) {
       super(groupField, sortWithinGroup.getSort().length);
       this.sortWithinGroup = sortWithinGroup;
-      groups = new HashMap<BytesRef, GroupHead>();
+      groups = new HashMap<>();
 
       final SortField[] sortFields = sortWithinGroup.getSort();
       for (int i = 0; i < sortFields.length; i++) {
@@ -219,7 +227,7 @@ public abstract class TermAllGroupHeadsC
     OrdScoreAllGroupHeadsCollector(String groupField, Sort sortWithinGroup, int initialSize) {
       super(groupField, sortWithinGroup.getSort().length);
       ordSet = new SentinelIntSet(initialSize, -2);
-      collectedGroups = new ArrayList<GroupHead>(initialSize);
+      collectedGroups = new ArrayList<>(initialSize);
 
       final SortField[] sortFields = sortWithinGroup.getSort();
       fields = new SortField[sortFields.length];
@@ -388,7 +396,7 @@ public abstract class TermAllGroupHeadsC
     OrdAllGroupHeadsCollector(String groupField, Sort sortWithinGroup, int initialSize) {
       super(groupField, sortWithinGroup.getSort().length);
       ordSet = new SentinelIntSet(initialSize, -2);
-      collectedGroups = new ArrayList<GroupHead>(initialSize);
+      collectedGroups = new ArrayList<>(initialSize);
 
       final SortField[] sortFields = sortWithinGroup.getSort();
       fields = new SortField[sortFields.length];
@@ -531,7 +539,7 @@ public abstract class TermAllGroupHeadsC
     ScoreAllGroupHeadsCollector(String groupField, Sort sortWithinGroup, int initialSize) {
       super(groupField, sortWithinGroup.getSort().length);
       ordSet = new SentinelIntSet(initialSize, -2);
-      collectedGroups = new ArrayList<GroupHead>(initialSize);
+      collectedGroups = new ArrayList<>(initialSize);
 
       final SortField[] sortFields = sortWithinGroup.getSort();
       fields = new SortField[sortFields.length];

Modified: lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermAllGroupsCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermAllGroupsCollector.java?rev=1487777&r1=1487776&r2=1487777&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermAllGroupsCollector.java (original)
+++ lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermAllGroupsCollector.java Thu May 30 07:53:18 2013
@@ -17,11 +17,6 @@ package org.apache.lucene.search.groupin
  * limitations under the License.
  */
 
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
 import org.apache.lucene.index.AtomicReaderContext;
 import org.apache.lucene.index.SortedDocValues;
 import org.apache.lucene.search.FieldCache;
@@ -29,6 +24,11 @@ import org.apache.lucene.search.grouping
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.SentinelIntSet;
 
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
 /**
  * A collector that collects all groups that match the
  * query. Only the group value is collected, and the order
@@ -66,7 +66,7 @@ public class TermAllGroupsCollector exte
    */
   public TermAllGroupsCollector(String groupField, int initialSize) {
     ordSet = new SentinelIntSet(initialSize, -2);
-    groups = new ArrayList<BytesRef>(initialSize);
+    groups = new ArrayList<>(initialSize);
     this.groupField = groupField;
   }
 

Modified: lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermDistinctValuesCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermDistinctValuesCollector.java?rev=1487777&r1=1487776&r2=1487777&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermDistinctValuesCollector.java (original)
+++ lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermDistinctValuesCollector.java Thu May 30 07:53:18 2013
@@ -17,9 +17,6 @@ package org.apache.lucene.search.groupin
  * limitations under the License.
  */
 
-import java.io.IOException;
-import java.util.*;
-
 import org.apache.lucene.index.AtomicReaderContext;
 import org.apache.lucene.index.SortedDocValues;
 import org.apache.lucene.search.FieldCache;
@@ -28,6 +25,12 @@ import org.apache.lucene.search.grouping
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.SentinelIntSet;
 
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
 /**
  * A term based implementation of {@link org.apache.lucene.search.grouping.AbstractDistinctValuesCollector} that relies
  * on {@link SortedDocValues} to count the distinct values per group.
@@ -55,7 +58,7 @@ public class TermDistinctValuesCollector
   public TermDistinctValuesCollector(String groupField, String countField, Collection<SearchGroup<BytesRef>> groups) {
     this.groupField = groupField;
     this.countField = countField;
-    this.groups = new ArrayList<GroupCount>(groups.size());
+    this.groups = new ArrayList<>(groups.size());
     for (SearchGroup<BytesRef> group : groups) {
       this.groups.add(new GroupCount(group.groupValue));
     }

Modified: lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermGroupFacetCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermGroupFacetCollector.java?rev=1487777&r1=1487776&r2=1487777&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermGroupFacetCollector.java (original)
+++ lucene/dev/branches/security/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermGroupFacetCollector.java Thu May 30 07:53:18 2013
@@ -17,20 +17,19 @@ package org.apache.lucene.search.groupin
  * limitations under the License.
  */
 
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
 import org.apache.lucene.index.AtomicReaderContext;
-import org.apache.lucene.index.DocTermOrds;
 import org.apache.lucene.index.SortedDocValues;
-import org.apache.lucene.index.SortedDocValuesTermsEnum;
 import org.apache.lucene.index.SortedSetDocValues;
-import org.apache.lucene.index.SortedSetDocValuesTermsEnum;
 import org.apache.lucene.index.TermsEnum;
 import org.apache.lucene.search.FieldCache;
 import org.apache.lucene.search.grouping.AbstractGroupFacetCollector;
-import org.apache.lucene.util.*;
+import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.SentinelIntSet;
+import org.apache.lucene.util.UnicodeUtil;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * An implementation of {@link AbstractGroupFacetCollector} that computes grouped facets based on the indexed terms
@@ -72,7 +71,7 @@ public abstract class TermGroupFacetColl
 
   TermGroupFacetCollector(String groupField, String facetField, BytesRef facetPrefix, int initialSize) {
     super(groupField, facetField, facetPrefix);
-    groupedFacetHits = new ArrayList<GroupedFacetHit>(initialSize);
+    groupedFacetHits = new ArrayList<>(initialSize);
     segmentGroupedFacetHits = new SentinelIntSet(initialSize, Integer.MIN_VALUE);
   }
 
@@ -170,7 +169,7 @@ public abstract class TermGroupFacetColl
 
     @Override
     protected SegmentResult createSegmentResult() throws IOException {
-      return new SegmentResult(segmentFacetCounts, segmentTotalCount, new SortedDocValuesTermsEnum(facetFieldTermsIndex), startFacetOrd, endFacetOrd);
+      return new SegmentResult(segmentFacetCounts, segmentTotalCount, facetFieldTermsIndex.termsEnum(), startFacetOrd, endFacetOrd);
     }
 
     private static class SegmentResult extends AbstractGroupFacetCollector.SegmentResult {
@@ -289,7 +288,7 @@ public abstract class TermGroupFacetColl
       if (facetFieldNumTerms == 0) {
         facetOrdTermsEnum = null;
       } else {
-        facetOrdTermsEnum = new SortedSetDocValuesTermsEnum(facetFieldDocTermOrds);
+        facetOrdTermsEnum = facetFieldDocTermOrds.termsEnum();
       }
       // [facetFieldNumTerms() + 1] for all possible facet values and docs not containing facet field
       segmentFacetCounts = new int[facetFieldNumTerms + 1];

Modified: lucene/dev/branches/security/lucene/grouping/src/test/org/apache/lucene/search/grouping/AllGroupHeadsCollectorTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/grouping/src/test/org/apache/lucene/search/grouping/AllGroupHeadsCollectorTest.java?rev=1487777&r1=1487776&r2=1487777&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/grouping/src/test/org/apache/lucene/search/grouping/AllGroupHeadsCollectorTest.java (original)
+++ lucene/dev/branches/security/lucene/grouping/src/test/org/apache/lucene/search/grouping/AllGroupHeadsCollectorTest.java Thu May 30 07:53:18 2013
@@ -17,11 +17,13 @@ package org.apache.lucene.search.groupin
  * limitations under the License.
  */
 
-import java.io.IOException;
-import java.util.*;
-
 import org.apache.lucene.analysis.MockAnalyzer;
-import org.apache.lucene.document.*;
+import org.apache.lucene.document.BinaryDocValuesField;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.document.IntField;
+import org.apache.lucene.document.SortedDocValuesField;
+import org.apache.lucene.document.TextField;
 import org.apache.lucene.index.DirectoryReader;
 import org.apache.lucene.index.FieldInfo.DocValuesType;
 import org.apache.lucene.index.IndexReader;
@@ -30,7 +32,14 @@ import org.apache.lucene.index.SlowCompo
 import org.apache.lucene.index.Term;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.queries.function.valuesource.BytesRefFieldSource;
-import org.apache.lucene.search.*;
+import org.apache.lucene.search.DocIdSetIterator;
+import org.apache.lucene.search.FieldCache;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.QueryUtils;
+import org.apache.lucene.search.ScoreDoc;
+import org.apache.lucene.search.Sort;
+import org.apache.lucene.search.SortField;
+import org.apache.lucene.search.TermQuery;
 import org.apache.lucene.search.grouping.function.FunctionAllGroupHeadsCollector;
 import org.apache.lucene.search.grouping.term.TermAllGroupHeadsCollector;
 import org.apache.lucene.store.Directory;
@@ -39,6 +48,16 @@ import org.apache.lucene.util.FixedBitSe
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.util._TestUtil;
 
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
 public class AllGroupHeadsCollectorTest extends LuceneTestCase {
 
   private static final DocValuesType[] vts = new DocValuesType[]{
@@ -53,98 +72,102 @@ public class AllGroupHeadsCollectorTest 
         dir,
         newIndexWriterConfig(TEST_VERSION_CURRENT,
             new MockAnalyzer(random())).setMergePolicy(newLogMergePolicy()));
-    boolean canUseIDV = true;
     DocValuesType valueType = vts[random().nextInt(vts.length)];
 
     // 0
     Document doc = new Document();
-    addGroupField(doc, groupField, "author1", canUseIDV, valueType);
-    doc.add(newTextField("content", "random text", Field.Store.YES));
-    doc.add(newStringField("id", "1", Field.Store.YES));
+    addGroupField(doc, groupField, "author1", valueType);
+    doc.add(newTextField("content", "random text", Field.Store.NO));
+    doc.add(newStringField("id_1", "1", Field.Store.NO));
+    doc.add(newStringField("id_2", "1", Field.Store.NO));
     w.addDocument(doc);
 
     // 1
     doc = new Document();
-    addGroupField(doc, groupField, "author1", canUseIDV, valueType);
-    doc.add(newTextField("content", "some more random text blob", Field.Store.YES));
-    doc.add(newStringField("id", "2", Field.Store.YES));
+    addGroupField(doc, groupField, "author1", valueType);
+    doc.add(newTextField("content", "some more random text blob", Field.Store.NO));
+    doc.add(newStringField("id_1", "2", Field.Store.NO));
+    doc.add(newStringField("id_2", "2", Field.Store.NO));
     w.addDocument(doc);
 
     // 2
     doc = new Document();
-    addGroupField(doc, groupField, "author1", canUseIDV, valueType);
-    doc.add(newTextField("content", "some more random textual data", Field.Store.YES));
-    doc.add(newStringField("id", "3", Field.Store.YES));
+    addGroupField(doc, groupField, "author1", valueType);
+    doc.add(newTextField("content", "some more random textual data", Field.Store.NO));
+    doc.add(newStringField("id_1", "3", Field.Store.NO));
+    doc.add(newStringField("id_2", "3", Field.Store.NO));
     w.addDocument(doc);
     w.commit(); // To ensure a second segment
 
     // 3
     doc = new Document();
-    addGroupField(doc, groupField, "author2", canUseIDV, valueType);
-    doc.add(newTextField("content", "some random text", Field.Store.YES));
-    doc.add(newStringField("id", "4", Field.Store.YES));
+    addGroupField(doc, groupField, "author2", valueType);
+    doc.add(newTextField("content", "some random text", Field.Store.NO));
+    doc.add(newStringField("id_1", "4", Field.Store.NO));
+    doc.add(newStringField("id_2", "4", Field.Store.NO));
     w.addDocument(doc);
 
     // 4
     doc = new Document();
-    addGroupField(doc, groupField, "author3", canUseIDV, valueType);
-    doc.add(newTextField("content", "some more random text", Field.Store.YES));
-    doc.add(newStringField("id", "5", Field.Store.YES));
+    addGroupField(doc, groupField, "author3", valueType);
+    doc.add(newTextField("content", "some more random text", Field.Store.NO));
+    doc.add(newStringField("id_1", "5", Field.Store.NO));
+    doc.add(newStringField("id_2", "5", Field.Store.NO));
     w.addDocument(doc);
 
     // 5
     doc = new Document();
-    addGroupField(doc, groupField, "author3", canUseIDV, valueType);
-    doc.add(newTextField("content", "random blob", Field.Store.YES));
-    doc.add(newStringField("id", "6", Field.Store.YES));
+    addGroupField(doc, groupField, "author3", valueType);
+    doc.add(newTextField("content", "random blob", Field.Store.NO));
+    doc.add(newStringField("id_1", "6", Field.Store.NO));
+    doc.add(newStringField("id_2", "6", Field.Store.NO));
     w.addDocument(doc);
 
     // 6 -- no author field
     doc = new Document();
-    doc.add(newTextField("content", "random word stuck in alot of other text", Field.Store.YES));
-    doc.add(newStringField("id", "6", Field.Store.YES));
+    doc.add(newTextField("content", "random word stuck in alot of other text", Field.Store.NO));
+    doc.add(newStringField("id_1", "6", Field.Store.NO));
+    doc.add(newStringField("id_2", "6", Field.Store.NO));
     w.addDocument(doc);
 
     // 7 -- no author field
     doc = new Document();
-    doc.add(newTextField("content", "random word stuck in alot of other text", Field.Store.YES));
-    doc.add(newStringField("id", "7", Field.Store.YES));
+    doc.add(newTextField("content", "random word stuck in alot of other text", Field.Store.NO));
+    doc.add(newStringField("id_1", "7", Field.Store.NO));
+    doc.add(newStringField("id_2", "7", Field.Store.NO));
     w.addDocument(doc);
 
     IndexReader reader = w.getReader();
-    IndexSearcher indexSearcher = new IndexSearcher(reader);
-    if (SlowCompositeReaderWrapper.class.isAssignableFrom(reader.getClass())) {
-      canUseIDV = false;
-    }
+    IndexSearcher indexSearcher = newSearcher(reader);
 
     w.close();
     int maxDoc = reader.maxDoc();
 
-    Sort sortWithinGroup = new Sort(new SortField("id", SortField.Type.INT, true));
-    AbstractAllGroupHeadsCollector<?> allGroupHeadsCollector = createRandomCollector(groupField, sortWithinGroup, canUseIDV, valueType);
+    Sort sortWithinGroup = new Sort(new SortField("id_1", SortField.Type.INT, true));
+    AbstractAllGroupHeadsCollector<?> allGroupHeadsCollector = createRandomCollector(groupField, sortWithinGroup);
     indexSearcher.search(new TermQuery(new Term("content", "random")), allGroupHeadsCollector);
     assertTrue(arrayContains(new int[]{2, 3, 5, 7}, allGroupHeadsCollector.retrieveGroupHeads()));
     assertTrue(openBitSetContains(new int[]{2, 3, 5, 7}, allGroupHeadsCollector.retrieveGroupHeads(maxDoc), maxDoc));
 
-    allGroupHeadsCollector = createRandomCollector(groupField, sortWithinGroup, canUseIDV, valueType);
+    allGroupHeadsCollector = createRandomCollector(groupField, sortWithinGroup);
     indexSearcher.search(new TermQuery(new Term("content", "some")), allGroupHeadsCollector);
     assertTrue(arrayContains(new int[]{2, 3, 4}, allGroupHeadsCollector.retrieveGroupHeads()));
     assertTrue(openBitSetContains(new int[]{2, 3, 4}, allGroupHeadsCollector.retrieveGroupHeads(maxDoc), maxDoc));
 
-    allGroupHeadsCollector = createRandomCollector(groupField, sortWithinGroup, canUseIDV, valueType);
+    allGroupHeadsCollector = createRandomCollector(groupField, sortWithinGroup);
     indexSearcher.search(new TermQuery(new Term("content", "blob")), allGroupHeadsCollector);
     assertTrue(arrayContains(new int[]{1, 5}, allGroupHeadsCollector.retrieveGroupHeads()));
     assertTrue(openBitSetContains(new int[]{1, 5}, allGroupHeadsCollector.retrieveGroupHeads(maxDoc), maxDoc));
 
     // STRING sort type triggers different implementation
-    Sort sortWithinGroup2 = new Sort(new SortField("id", SortField.Type.STRING, true));
-    allGroupHeadsCollector = createRandomCollector(groupField, sortWithinGroup2, canUseIDV, valueType);
+    Sort sortWithinGroup2 = new Sort(new SortField("id_2", SortField.Type.STRING, true));
+    allGroupHeadsCollector = createRandomCollector(groupField, sortWithinGroup2);
     indexSearcher.search(new TermQuery(new Term("content", "random")), allGroupHeadsCollector);
     assertTrue(arrayContains(new int[]{2, 3, 5, 7}, allGroupHeadsCollector.retrieveGroupHeads()));
     assertTrue(openBitSetContains(new int[]{2, 3, 5, 7}, allGroupHeadsCollector.retrieveGroupHeads(maxDoc), maxDoc));
 
-    Sort sortWithinGroup3 = new Sort(new SortField("id", SortField.Type.STRING, false));
-    allGroupHeadsCollector = createRandomCollector(groupField, sortWithinGroup3, canUseIDV, valueType);
+    Sort sortWithinGroup3 = new Sort(new SortField("id_2", SortField.Type.STRING, false));
+    allGroupHeadsCollector = createRandomCollector(groupField, sortWithinGroup3);
     indexSearcher.search(new TermQuery(new Term("content", "random")), allGroupHeadsCollector);
     // 7 b/c higher doc id wins, even if order of field is in not in reverse.
     assertTrue(arrayContains(new int[]{0, 3, 4, 6}, allGroupHeadsCollector.retrieveGroupHeads()));
@@ -168,7 +191,7 @@ public class AllGroupHeadsCollectorTest 
         System.out.println("TEST: numDocs=" + numDocs + " numGroups=" + numGroups);
       }
 
-      final List<BytesRef> groups = new ArrayList<BytesRef>();
+      final List<BytesRef> groups = new ArrayList<>();
       for (int i = 0; i < numGroups; i++) {
         String randomValue;
         do {
@@ -201,7 +224,6 @@ public class AllGroupHeadsCollectorTest 
           dir,
           newIndexWriterConfig(TEST_VERSION_CURRENT,
               new MockAnalyzer(random())));
-      boolean canUseIDV = true;
       DocValuesType valueType = vts[random().nextInt(vts.length)];
 
       Document doc = new Document();
@@ -209,8 +231,7 @@ public class AllGroupHeadsCollectorTest 
       Field group = newStringField("group", "", Field.Store.NO);
       doc.add(group);
       Field valuesField = null;
-      if (canUseIDV) {
-        switch(valueType) {
+      switch(valueType) {
         case BINARY:
           valuesField = new BinaryDocValuesField("group_dv", new BytesRef());
           break;
@@ -219,9 +240,8 @@ public class AllGroupHeadsCollectorTest 
           break;
         default:
           fail("unhandled type");
-        }
-        doc.add(valuesField);
       }
+      doc.add(valuesField);
       Field sort1 = newStringField("sort1", "", Field.Store.NO);
       doc.add(sort1);
       docNoGroup.add(sort1);
@@ -264,9 +284,7 @@ public class AllGroupHeadsCollectorTest 
         groupDocs[i] = groupDoc;
         if (groupDoc.group != null) {
           group.setStringValue(groupDoc.group.utf8ToString());
-          if (canUseIDV) {
-            valuesField.setBytesValue(new BytesRef(groupDoc.group.utf8ToString()));
-          }
+          valuesField.setBytesValue(new BytesRef(groupDoc.group.utf8ToString()));
         }
         sort1.setStringValue(groupDoc.sort1.utf8ToString());
         sort2.setStringValue(groupDoc.sort2.utf8ToString());
@@ -293,11 +311,6 @@ public class AllGroupHeadsCollectorTest 
 
       try {
         final IndexSearcher s = newSearcher(r);
-        if (SlowCompositeReaderWrapper.class.isAssignableFrom(s.getIndexReader().getClass())) {
-          canUseIDV = false;
-        } else {
-          canUseIDV = true;
-        }
 
         for (int contentID = 0; contentID < 3; contentID++) {
           final ScoreDoc[] hits = s.search(new TermQuery(new Term("content", "real" + contentID)), numDocs).scoreDocs;
@@ -323,7 +336,7 @@ public class AllGroupHeadsCollectorTest 
           final String searchTerm = "real" + random().nextInt(3);
           boolean sortByScoreOnly = random().nextBoolean();
           Sort sortWithinGroup = getRandomSort(sortByScoreOnly);
-          AbstractAllGroupHeadsCollector<?> allGroupHeadsCollector = createRandomCollector("group", sortWithinGroup, canUseIDV, valueType);
+          AbstractAllGroupHeadsCollector<?> allGroupHeadsCollector = createRandomCollector("group", sortWithinGroup);
           s.search(new TermQuery(new Term("content", searchTerm)), allGroupHeadsCollector);
           int[] expectedGroupHeads = createExpectedGroupHeads(searchTerm, groupDocs, sortWithinGroup, sortByScoreOnly, fieldIdToDocID);
           int[] actualGroupHeads = allGroupHeadsCollector.retrieveGroupHeads();
@@ -426,14 +439,14 @@ public class AllGroupHeadsCollectorTest 
   }
 
   private int[] createExpectedGroupHeads(String searchTerm, GroupDoc[] groupDocs, Sort docSort, boolean sortByScoreOnly, int[] fieldIdToDocID) {
-    Map<BytesRef, List<GroupDoc>> groupHeads = new HashMap<BytesRef, List<GroupDoc>>();
+    Map<BytesRef, List<GroupDoc>> groupHeads = new HashMap<>();
     for (GroupDoc groupDoc : groupDocs) {
       if (!groupDoc.content.startsWith(searchTerm)) {
         continue;
       }
 
       if (!groupHeads.containsKey(groupDoc.group)) {
-        List<GroupDoc> list = new ArrayList<GroupDoc>();
+        List<GroupDoc> list = new ArrayList<>();
         list.add(groupDoc);
         groupHeads.put(groupDoc.group, list);
         continue;
@@ -453,7 +466,7 @@ public class AllGroupHeadsCollectorTest 
   }
 
   private Sort getRandomSort(boolean scoreOnly) {
-    final List<SortField> sortFields = new ArrayList<SortField>();
+    final List<SortField> sortFields = new ArrayList<>();
     if (random().nextInt(7) == 2 || scoreOnly) {
       sortFields.add(SortField.FIELD_SCORE);
     } else {
@@ -514,11 +527,11 @@ public class AllGroupHeadsCollectorTest 
   }
 
   @SuppressWarnings({"unchecked","rawtypes"})
-  private AbstractAllGroupHeadsCollector<?> createRandomCollector(String groupField, Sort sortWithinGroup, boolean canUseIDV, DocValuesType valueType) {
+  private AbstractAllGroupHeadsCollector<?> createRandomCollector(String groupField, Sort sortWithinGroup) {
     AbstractAllGroupHeadsCollector<? extends AbstractAllGroupHeadsCollector.GroupHead> collector;
     if (random().nextBoolean()) {
       ValueSource vs = new BytesRefFieldSource(groupField);
-      collector =  new FunctionAllGroupHeadsCollector(vs, new HashMap<Object, Object>(), sortWithinGroup);
+      collector =  new FunctionAllGroupHeadsCollector(vs, new HashMap<>(), sortWithinGroup);
     } else {
       collector =  TermAllGroupHeadsCollector.create(groupField, sortWithinGroup);
     }
@@ -530,11 +543,10 @@ public class AllGroupHeadsCollectorTest 
     return collector;
   }
 
-  private void addGroupField(Document doc, String groupField, String value, boolean canUseIDV, DocValuesType valueType) {
-    doc.add(new TextField(groupField, value, Field.Store.YES));
-    if (canUseIDV) {
-      Field valuesField = null;
-      switch(valueType) {
+  private void addGroupField(Document doc, String groupField, String value, DocValuesType valueType) {
+    doc.add(new TextField(groupField, value, Field.Store.NO));
+    Field valuesField = null;
+    switch(valueType) {
       case BINARY:
         valuesField = new BinaryDocValuesField(groupField + "_dv", new BytesRef(value));
         break;
@@ -543,9 +555,8 @@ public class AllGroupHeadsCollectorTest 
         break;
       default:
         fail("unhandled type");
-      }
-      doc.add(valuesField);
     }
+    doc.add(valuesField);
   }
 
   private static class GroupDoc {

Modified: lucene/dev/branches/security/lucene/grouping/src/test/org/apache/lucene/search/grouping/AllGroupsCollectorTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/grouping/src/test/org/apache/lucene/search/grouping/AllGroupsCollectorTest.java?rev=1487777&r1=1487776&r2=1487777&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/grouping/src/test/org/apache/lucene/search/grouping/AllGroupsCollectorTest.java (original)
+++ lucene/dev/branches/security/lucene/grouping/src/test/org/apache/lucene/search/grouping/AllGroupsCollectorTest.java Thu May 30 07:53:18 2013
@@ -18,10 +18,13 @@ package org.apache.lucene.search.groupin
  */
 
 import org.apache.lucene.analysis.MockAnalyzer;
-import org.apache.lucene.document.*;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.document.FieldType;
+import org.apache.lucene.document.SortedDocValuesField;
+import org.apache.lucene.document.TextField;
 import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.index.Term;
-import org.apache.lucene.index.FieldInfo.DocValuesType;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.queries.function.valuesource.BytesRefFieldSource;
 import org.apache.lucene.search.IndexSearcher;
@@ -48,25 +51,24 @@ public class AllGroupsCollectorTest exte
         dir,
         newIndexWriterConfig(TEST_VERSION_CURRENT,
             new MockAnalyzer(random())).setMergePolicy(newLogMergePolicy()));
-    boolean canUseIDV = true;
 
     // 0
     Document doc = new Document();
-    addGroupField(doc, groupField, "author1", canUseIDV);
+    addGroupField(doc, groupField, "author1");
     doc.add(new TextField("content", "random text", Field.Store.YES));
     doc.add(new Field("id", "1", customType));
     w.addDocument(doc);
 
     // 1
     doc = new Document();
-    addGroupField(doc, groupField, "author1", canUseIDV);
+    addGroupField(doc, groupField, "author1");
     doc.add(new TextField("content", "some more random text blob", Field.Store.YES));
     doc.add(new Field("id", "2", customType));
     w.addDocument(doc);
 
     // 2
     doc = new Document();
-    addGroupField(doc, groupField, "author1", canUseIDV);
+    addGroupField(doc, groupField, "author1");
     doc.add(new TextField("content", "some more random textual data", Field.Store.YES));
     doc.add(new Field("id", "3", customType));
     w.addDocument(doc);
@@ -74,21 +76,21 @@ public class AllGroupsCollectorTest exte
 
     // 3
     doc = new Document();
-    addGroupField(doc, groupField, "author2", canUseIDV);
+    addGroupField(doc, groupField, "author2");
     doc.add(new TextField("content", "some random text", Field.Store.YES));
     doc.add(new Field("id", "4", customType));
     w.addDocument(doc);
 
     // 4
     doc = new Document();
-    addGroupField(doc, groupField, "author3", canUseIDV);
+    addGroupField(doc, groupField, "author3");
     doc.add(new TextField("content", "some more random text", Field.Store.YES));
     doc.add(new Field("id", "5", customType));
     w.addDocument(doc);
 
     // 5
     doc = new Document();
-    addGroupField(doc, groupField, "author3", canUseIDV);
+    addGroupField(doc, groupField, "author3");
     doc.add(new TextField("content", "random blob", Field.Store.YES));
     doc.add(new Field("id", "6", customType));
     w.addDocument(doc);
@@ -99,18 +101,18 @@ public class AllGroupsCollectorTest exte
     doc.add(new Field("id", "6", customType));
     w.addDocument(doc);
 
-    IndexSearcher indexSearcher = new IndexSearcher(w.getReader());
+    IndexSearcher indexSearcher = newSearcher(w.getReader());
     w.close();
 
-    AbstractAllGroupsCollector<?> allGroupsCollector = createRandomCollector(groupField, canUseIDV);
+    AbstractAllGroupsCollector<?> allGroupsCollector = createRandomCollector(groupField);
     indexSearcher.search(new TermQuery(new Term("content", "random")), allGroupsCollector);
     assertEquals(4, allGroupsCollector.getGroupCount());
 
-    allGroupsCollector = createRandomCollector(groupField, canUseIDV);
+    allGroupsCollector = createRandomCollector(groupField);
     indexSearcher.search(new TermQuery(new Term("content", "some")), allGroupsCollector);
     assertEquals(3, allGroupsCollector.getGroupCount());
 
-    allGroupsCollector = createRandomCollector(groupField, canUseIDV);
+    allGroupsCollector = createRandomCollector(groupField);
     indexSearcher.search(new TermQuery(new Term("content", "blob")), allGroupsCollector);
     assertEquals(2, allGroupsCollector.getGroupCount());
 
@@ -118,20 +120,18 @@ public class AllGroupsCollectorTest exte
     dir.close();
   }
 
-  private void addGroupField(Document doc, String groupField, String value, boolean canUseIDV) {
+  private void addGroupField(Document doc, String groupField, String value) {
     doc.add(new TextField(groupField, value, Field.Store.YES));
-    if (canUseIDV) {
-      doc.add(new SortedDocValuesField(groupField, new BytesRef(value)));
-    }
+    doc.add(new SortedDocValuesField(groupField, new BytesRef(value)));
   }
 
-  private AbstractAllGroupsCollector<?> createRandomCollector(String groupField, boolean canUseIDV) {
+  private AbstractAllGroupsCollector<?> createRandomCollector(String groupField) {
     AbstractAllGroupsCollector<?> selected;
     if (random().nextBoolean()) {
       selected = new TermAllGroupsCollector(groupField);
     } else {
       ValueSource vs = new BytesRefFieldSource(groupField);
-      selected = new FunctionAllGroupsCollector(vs, new HashMap<Object, Object>());
+      selected = new FunctionAllGroupsCollector(vs, new HashMap<>());
     }
 
     if (VERBOSE) {

Modified: lucene/dev/branches/security/lucene/grouping/src/test/org/apache/lucene/search/grouping/DistinctValuesCollectorTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/grouping/src/test/org/apache/lucene/search/grouping/DistinctValuesCollectorTest.java?rev=1487777&r1=1487776&r2=1487777&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/grouping/src/test/org/apache/lucene/search/grouping/DistinctValuesCollectorTest.java (original)
+++ lucene/dev/branches/security/lucene/grouping/src/test/org/apache/lucene/search/grouping/DistinctValuesCollectorTest.java Thu May 30 07:53:18 2013
@@ -17,13 +17,19 @@ package org.apache.lucene.search.groupin
  * limitations under the License.
  */
 
-import java.io.IOException;
-import java.util.*;
-
 import org.apache.lucene.analysis.MockAnalyzer;
-import org.apache.lucene.document.*;
-import org.apache.lucene.index.*;
+import org.apache.lucene.document.BinaryDocValuesField;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.document.NumericDocValuesField;
+import org.apache.lucene.document.SortedDocValuesField;
+import org.apache.lucene.document.StringField;
+import org.apache.lucene.document.TextField;
+import org.apache.lucene.index.DirectoryReader;
 import org.apache.lucene.index.FieldInfo.DocValuesType;
+import org.apache.lucene.index.RandomIndexWriter;
+import org.apache.lucene.index.StoredDocument;
+import org.apache.lucene.index.Term;
 import org.apache.lucene.queries.function.valuesource.BytesRefFieldSource;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.Sort;
@@ -39,6 +45,20 @@ import org.apache.lucene.util._TestUtil;
 import org.apache.lucene.util.mutable.MutableValue;
 import org.apache.lucene.util.mutable.MutableValueStr;
 
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Random;
+import java.util.Set;
+
 public class DistinctValuesCollectorTest extends AbstractGroupingTestCase {
 
   private final static NullComparator nullComparator = new NullComparator();
@@ -267,9 +287,9 @@ public class DistinctValuesCollectorTest
           AbstractDistinctValuesCollector.GroupCount<Comparable<?>> actual = actualResult.get(i);
           assertValues(expected.groupValue, actual.groupValue);
           assertEquals(expected.uniqueValues.size(), actual.uniqueValues.size());
-          List<Comparable<?>> expectedUniqueValues = new ArrayList<Comparable<?>>(expected.uniqueValues);
+          List<Comparable<?>> expectedUniqueValues = new ArrayList<>(expected.uniqueValues);
           Collections.sort(expectedUniqueValues, nullComparator);
-          List<Comparable<?>> actualUniqueValues = new ArrayList<Comparable<?>>(actual.uniqueValues);
+          List<Comparable<?>> actualUniqueValues = new ArrayList<>(actual.uniqueValues);
           Collections.sort(actualUniqueValues, nullComparator);
           for (int j = 0; j < expectedUniqueValues.size(); j++) {
             assertValues(expectedUniqueValues.get(j), actualUniqueValues.get(j));
@@ -373,7 +393,7 @@ public class DistinctValuesCollectorTest
     Random random = random();
     Collection<SearchGroup<T>> searchGroups = firstPassGroupingCollector.getTopGroups(0, false);
     if (FunctionFirstPassGroupingCollector.class.isAssignableFrom(firstPassGroupingCollector.getClass())) {
-      return (AbstractDistinctValuesCollector) new FunctionDistinctValuesCollector(new HashMap<Object, Object>(), new BytesRefFieldSource(groupField), new BytesRefFieldSource(countField), (Collection) searchGroups);
+      return (AbstractDistinctValuesCollector) new FunctionDistinctValuesCollector(new HashMap<>(), new BytesRefFieldSource(groupField), new BytesRefFieldSource(countField), (Collection) searchGroups);
     } else {
       return (AbstractDistinctValuesCollector) new TermDistinctValuesCollector(groupField, countField, (Collection) searchGroups);
     }
@@ -384,13 +404,13 @@ public class DistinctValuesCollectorTest
     Random random = random();
     if (dvType != null) {
       if (random.nextBoolean()) {
-        return (AbstractFirstPassGroupingCollector<T>) new FunctionFirstPassGroupingCollector(new BytesRefFieldSource(groupField), new HashMap<Object, Object>(), groupSort, topNGroups);
+        return (AbstractFirstPassGroupingCollector<T>) new FunctionFirstPassGroupingCollector(new BytesRefFieldSource(groupField), new HashMap<>(), groupSort, topNGroups);
       } else {
         return (AbstractFirstPassGroupingCollector<T>) new TermFirstPassGroupingCollector(groupField, groupSort, topNGroups);
       }
     } else {
       if (random.nextBoolean()) {
-        return (AbstractFirstPassGroupingCollector<T>) new FunctionFirstPassGroupingCollector(new BytesRefFieldSource(groupField), new HashMap<Object, Object>(), groupSort, topNGroups);
+        return (AbstractFirstPassGroupingCollector<T>) new FunctionFirstPassGroupingCollector(new BytesRefFieldSource(groupField), new HashMap<>(), groupSort, topNGroups);
       } else {
         return (AbstractFirstPassGroupingCollector<T>) new TermFirstPassGroupingCollector(groupField, groupSort, topNGroups);
       }
@@ -413,7 +433,7 @@ public class DistinctValuesCollectorTest
       if (topN <= i++) {
         break;
       }
-      Set<BytesRef> uniqueValues = new HashSet<BytesRef>();
+      Set<BytesRef> uniqueValues = new HashSet<>();
       for (String val : groupCounts.get(group)) {
         uniqueValues.add(val != null ? new BytesRef(val) : null);
       }
@@ -450,8 +470,8 @@ public class DistinctValuesCollectorTest
       countValues[i] = generateRandomNonEmptyString();
     }
     
-    List<String> contentStrings = new ArrayList<String>();
-    Map<String, Map<String, Set<String>>> searchTermToGroupCounts = new HashMap<String, Map<String, Set<String>>>();
+    List<String> contentStrings = new ArrayList<>();
+    Map<String, Map<String, Set<String>>> searchTermToGroupCounts = new HashMap<>();
     for (int i = 1; i <= numDocs; i++) {
       String groupValue = random.nextInt(23) == 14 ? null : groupValues[random.nextInt(groupValues.length)];
       String countValue = random.nextInt(21) == 13 ? null : countValues[random.nextInt(countValues.length)];
@@ -459,13 +479,13 @@ public class DistinctValuesCollectorTest
       Map<String, Set<String>> groupToCounts = searchTermToGroupCounts.get(content);
       if (groupToCounts == null) {
         // Groups sort always DOCID asc...
-        searchTermToGroupCounts.put(content, groupToCounts = new LinkedHashMap<String, Set<String>>());
+        searchTermToGroupCounts.put(content, groupToCounts = new LinkedHashMap<>());
         contentStrings.add(content);
       }
 
       Set<String> countsVals = groupToCounts.get(groupValue);
       if (countsVals == null) {
-        groupToCounts.put(groupValue, countsVals = new HashSet<String>());
+        groupToCounts.put(groupValue, countsVals = new HashSet<>());
       }
       countsVals.add(countValue);
 

Modified: lucene/dev/branches/security/lucene/grouping/src/test/org/apache/lucene/search/grouping/GroupFacetCollectorTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/grouping/src/test/org/apache/lucene/search/grouping/GroupFacetCollectorTest.java?rev=1487777&r1=1487776&r2=1487777&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/grouping/src/test/org/apache/lucene/search/grouping/GroupFacetCollectorTest.java (original)
+++ lucene/dev/branches/security/lucene/grouping/src/test/org/apache/lucene/search/grouping/GroupFacetCollectorTest.java Thu May 30 07:53:18 2013
@@ -18,7 +18,11 @@ package org.apache.lucene.search.groupin
  */
 
 import org.apache.lucene.analysis.MockAnalyzer;
-import org.apache.lucene.document.*;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.document.FieldType;
+import org.apache.lucene.document.SortedDocValuesField;
+import org.apache.lucene.document.StringField;
 import org.apache.lucene.index.DirectoryReader;
 import org.apache.lucene.index.NoMergePolicy;
 import org.apache.lucene.index.RandomIndexWriter;
@@ -28,12 +32,22 @@ import org.apache.lucene.search.MatchAll
 import org.apache.lucene.search.TermQuery;
 import org.apache.lucene.search.grouping.term.TermGroupFacetCollector;
 import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.FSDirectory;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util._TestUtil;
 
 import java.io.IOException;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.NavigableSet;
+import java.util.Random;
+import java.util.Set;
+import java.util.TreeSet;
 
 public class GroupFacetCollectorTest extends AbstractGroupingTestCase {
 
@@ -48,8 +62,7 @@ public class GroupFacetCollectorTest ext
         dir,
         newIndexWriterConfig(TEST_VERSION_CURRENT,
             new MockAnalyzer(random())).setMergePolicy(newLogMergePolicy()));
-    boolean canUseDV = true;
-    boolean useDv = canUseDV && random().nextBoolean();
+    boolean useDv = random().nextBoolean();
 
     // 0
     Document doc = new Document();
@@ -87,20 +100,41 @@ public class GroupFacetCollectorTest ext
     addField(doc, "duration", "5", useDv);
     w.addDocument(doc);
 
-    IndexSearcher indexSearcher = new IndexSearcher(w.getReader());
-    AbstractGroupFacetCollector groupedAirportFacetCollector = createRandomCollector(useDv ? "hotel_dv" : "hotel", useDv ? "airport_dv" : "airport", null, false);
-    indexSearcher.search(new MatchAllDocsQuery(), groupedAirportFacetCollector);
-    TermGroupFacetCollector.GroupedFacetResult airportResult = groupedAirportFacetCollector.mergeSegmentResults(10, 0, false);
-    assertEquals(3, airportResult.getTotalCount());
-    assertEquals(0, airportResult.getTotalMissingCount());
+    IndexSearcher indexSearcher = newSearcher(w.getReader());
 
-    List<TermGroupFacetCollector.FacetEntry> entries = airportResult.getFacetEntries(0, 10);
-    assertEquals(2, entries.size());
-    assertEquals("ams", entries.get(0).getValue().utf8ToString());
-    assertEquals(2, entries.get(0).getCount());
-    assertEquals("dus", entries.get(1).getValue().utf8ToString());
-    assertEquals(1, entries.get(1).getCount());
+    List<TermGroupFacetCollector.FacetEntry> entries;
+    AbstractGroupFacetCollector groupedAirportFacetCollector;
+    TermGroupFacetCollector.GroupedFacetResult airportResult;
+    
+    for (int limit : new int[] { 2, 10, 100, Integer.MAX_VALUE }) {
+      // any of these limits is plenty for the data we have
+
+      groupedAirportFacetCollector = createRandomCollector
+        (useDv ? "hotel_dv" : "hotel", 
+         useDv ? "airport_dv" : "airport", null, false);
+      indexSearcher.search(new MatchAllDocsQuery(), groupedAirportFacetCollector);
+      int maxOffset = 5;
+      airportResult = groupedAirportFacetCollector.mergeSegmentResults
+        (Integer.MAX_VALUE == limit ? limit : maxOffset + limit, 0, false);
+      
+      assertEquals(3, airportResult.getTotalCount());
+      assertEquals(0, airportResult.getTotalMissingCount());
+
+      entries = airportResult.getFacetEntries(maxOffset, limit);
+      assertEquals(0, entries.size());
 
+      entries = airportResult.getFacetEntries(0, limit);
+      assertEquals(2, entries.size());
+      assertEquals("ams", entries.get(0).getValue().utf8ToString());
+      assertEquals(2, entries.get(0).getCount());
+      assertEquals("dus", entries.get(1).getValue().utf8ToString());
+      assertEquals(1, entries.get(1).getCount());
+
+      entries = airportResult.getFacetEntries(1, limit);
+      assertEquals(1, entries.size());
+      assertEquals("dus", entries.get(0).getValue().utf8ToString());
+      assertEquals(1, entries.get(0).getCount());
+    }
 
     AbstractGroupFacetCollector groupedDurationFacetCollector = createRandomCollector(useDv ? "hotel_dv" : "hotel", useDv ? "duration_dv" : "duration", null, false);
     indexSearcher.search(new MatchAllDocsQuery(), groupedDurationFacetCollector);
@@ -147,7 +181,7 @@ public class GroupFacetCollectorTest ext
     w.addDocument(doc);
 
     indexSearcher.getIndexReader().close();
-    indexSearcher = new IndexSearcher(w.getReader());
+    indexSearcher = newSearcher(w.getReader());
     groupedAirportFacetCollector = createRandomCollector(useDv ? "hotel_dv" : "hotel", useDv ? "airport_dv" : "airport", null, !useDv);
     indexSearcher.search(new MatchAllDocsQuery(), groupedAirportFacetCollector);
     airportResult = groupedAirportFacetCollector.mergeSegmentResults(3, 0, true);
@@ -195,7 +229,7 @@ public class GroupFacetCollectorTest ext
     w.addDocument(doc);
 
     indexSearcher.getIndexReader().close();
-    indexSearcher = new IndexSearcher(w.getReader());
+    indexSearcher = newSearcher(w.getReader());
     groupedAirportFacetCollector = createRandomCollector(useDv ? "hotel_dv" : "hotel", useDv ? "airport_dv" : "airport", null, false);
     indexSearcher.search(new MatchAllDocsQuery(), groupedAirportFacetCollector);
     airportResult = groupedAirportFacetCollector.mergeSegmentResults(10, 0, false);
@@ -311,7 +345,7 @@ public class GroupFacetCollectorTest ext
     w.commit();
 
     w.close();
-    IndexSearcher indexSearcher = new IndexSearcher(DirectoryReader.open(dir));
+    IndexSearcher indexSearcher = newSearcher(DirectoryReader.open(dir));
     AbstractGroupFacetCollector groupedAirportFacetCollector = createRandomCollector(groupField, "airport", null, true);
     indexSearcher.search(new MatchAllDocsQuery(), groupedAirportFacetCollector);
     TermGroupFacetCollector.GroupedFacetResult airportResult = groupedAirportFacetCollector.mergeSegmentResults(10, 0, false);
@@ -452,11 +486,11 @@ public class GroupFacetCollectorTest ext
       System.out.println("TEST: numDocs=" + numDocs + " numGroups=" + numGroups);
     }
 
-    final List<String> groups = new ArrayList<String>();
+    final List<String> groups = new ArrayList<>();
     for (int i = 0; i < numGroups; i++) {
       groups.add(generateRandomNonEmptyString());
     }
-    final List<String> facetValues = new ArrayList<String>();
+    final List<String> facetValues = new ArrayList<>();
     for (int i = 0; i < numFacets; i++) {
       facetValues.add(generateRandomNonEmptyString());
     }
@@ -519,7 +553,7 @@ public class GroupFacetCollectorTest ext
     docNoFacet.add(content);
     docNoGroupNoFacet.add(content);
 
-    NavigableSet<String> uniqueFacetValues = new TreeSet<String>(new Comparator<String>() {
+    NavigableSet<String> uniqueFacetValues = new TreeSet<>(new Comparator<String>() {
 
       @Override
       public int compare(String a, String b) {
@@ -535,7 +569,7 @@ public class GroupFacetCollectorTest ext
       }
 
     });
-    Map<String, Map<String, Set<String>>> searchTermToFacetToGroups = new HashMap<String, Map<String, Set<String>>>();
+    Map<String, Map<String, Set<String>>> searchTermToFacetToGroups = new HashMap<>();
     int facetWithMostGroups = 0;
     for (int i = 0; i < numDocs; i++) {
       final String groupValue;
@@ -557,7 +591,7 @@ public class GroupFacetCollectorTest ext
       }
       Map<String, Set<String>> facetToGroups = searchTermToFacetToGroups.get(contentStr);
 
-      List<String> facetVals = new ArrayList<String>();
+      List<String> facetVals = new ArrayList<>();
       if (useDv || random.nextInt(24) != 18) {
         if (useDv) {
           String facetValue = facetValues.get(random.nextInt(facetValues.size()));
@@ -635,14 +669,14 @@ public class GroupFacetCollectorTest ext
   private GroupedFacetResult createExpectedFacetResult(String searchTerm, IndexContext context, int offset, int limit, int minCount, final boolean orderByCount, String facetPrefix) {
     Map<String, Set<String>> facetGroups = context.searchTermToFacetGroups.get(searchTerm);
     if (facetGroups == null) {
-      facetGroups = new HashMap<String, Set<String>>();
+      facetGroups = new HashMap<>();
     }
 
     int totalCount = 0;
     int totalMissCount = 0;
     Set<String> facetValues;
     if (facetPrefix != null) {
-      facetValues = new HashSet<String>();
+      facetValues = new HashSet<>();
       for (String facetValue : context.facetValues) {
         if (facetValue != null && facetValue.startsWith(facetPrefix)) {
           facetValues.add(facetValue);
@@ -652,7 +686,7 @@ public class GroupFacetCollectorTest ext
       facetValues = context.facetValues;
     }
 
-    List<TermGroupFacetCollector.FacetEntry> entries = new ArrayList<TermGroupFacetCollector.FacetEntry>(facetGroups.size());
+    List<TermGroupFacetCollector.FacetEntry> entries = new ArrayList<>(facetGroups.size());
     // also includes facets with count 0
     for (String facetValue : facetValues) {
       if (facetValue == null) {

Modified: lucene/dev/branches/security/lucene/grouping/src/test/org/apache/lucene/search/grouping/GroupingSearchTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/security/lucene/grouping/src/test/org/apache/lucene/search/grouping/GroupingSearchTest.java?rev=1487777&r1=1487776&r2=1487777&view=diff
==============================================================================
--- lucene/dev/branches/security/lucene/grouping/src/test/org/apache/lucene/search/grouping/GroupingSearchTest.java (original)
+++ lucene/dev/branches/security/lucene/grouping/src/test/org/apache/lucene/search/grouping/GroupingSearchTest.java Thu May 30 07:53:18 2013
@@ -60,7 +60,7 @@ public class GroupingSearchTest extends 
         newIndexWriterConfig(TEST_VERSION_CURRENT,
             new MockAnalyzer(random())).setMergePolicy(newLogMergePolicy()));
     boolean canUseIDV = true;
-    List<Document> documents = new ArrayList<Document>();
+    List<Document> documents = new ArrayList<>();
     // 0
     Document doc = new Document();
     addGroupField(doc, groupField, "author1", canUseIDV);
@@ -118,7 +118,7 @@ public class GroupingSearchTest extends 
 
     w.addDocument(doc);
 
-    IndexSearcher indexSearcher = new IndexSearcher(w.getReader());
+    IndexSearcher indexSearcher = newSearcher(w.getReader());
     w.close();
 
     Sort groupSort = Sort.RELEVANCE;
@@ -207,7 +207,7 @@ public class GroupingSearchTest extends 
     GroupingSearch groupingSearch;
     if (random().nextBoolean()) {
       ValueSource vs = new BytesRefFieldSource(groupField);
-      groupingSearch = new GroupingSearch(vs, new HashMap<Object, Object>());
+      groupingSearch = new GroupingSearch(vs, new HashMap<>());
     } else {
       groupingSearch = new GroupingSearch(groupField);
     }
@@ -233,7 +233,7 @@ public class GroupingSearchTest extends 
     doc.add(newField("group", "foo", StringField.TYPE_NOT_STORED));
     w.addDocument(doc);
 
-    IndexSearcher indexSearcher = new IndexSearcher(w.getReader());
+    IndexSearcher indexSearcher = newSearcher(w.getReader());
     w.close();
 
     GroupingSearch gs = new GroupingSearch("group");



Mime
View raw message