Apache Solr open-source search software
LUCENE-7356: SearchGroup tweaks (initialCapacity, size==0 vs. isEmpty)
Christine Poerschkee0c45f400f83
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 9eea9e27abc..e0f11c32484 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -70,6 +70,8 @@ Optimizations* LUCENE-7330, LUCENE-7339: Speed up conjunction queries. (Adrien Grand)+* LUCENE-7356: SearchGroup tweaks. (Christine Poerschke)+Other* LUCENE-4787: Fixed some highlighting javadocs. (Michael Dodsworth via Adriendiff --git a/lucene/grouping/src/java/org/apache/lucene/search/grouping/SearchGroup.java b/lucene/grouping/src/java/org/apache/lucene/search/grouping/SearchGroup.javaindex c9d7fa0863a..b3a43cb6c32 100644--- a/lucene/grouping/src/java/org/apache/lucene/search/grouping/SearchGroup.java+++ b/lucene/grouping/src/java/org/apache/lucene/search/grouping/SearchGroup.java@@ -288,11 +288,11 @@ public class SearchGroup<GROUP_VALUE_TYPE> {}// Pull merged topN groups:- final List<SearchGroup<T>> newTopGroups = new ArrayList<>();+ final List<SearchGroup<T>> newTopGroups = new ArrayList<>(topN);int count = 0;- while(queue.size() != 0) {+ while(!queue.isEmpty()) {final MergedGroup<T> group = queue.pollFirst();group.processed = true;//System.out.println(" pop: shards=" + group.shards + " group=" + (group.groupValue == null ? "null" : (((BytesRef) group.groupValue).utf8ToString())) + " sortValues=" + Arrays.toString(group.topValues));@@ -314,7 +314,7 @@ public class SearchGroup<GROUP_VALUE_TYPE> {}}- if (newTopGroups.size() == 0) {+ if (newTopGroups.isEmpty()) {return null;} else {return newTopGroups;@@ -333,7 +333,7 @@ public class SearchGroup<GROUP_VALUE_TYPE> {*/public static <T> Collection<SearchGroup<T>> merge(List<Collection<SearchGroup<T>>> topGroups, int offset, int topN, Sort groupSort)throws IOException {- if (topGroups.size() == 0) {+ if (topGroups.isEmpty()) {return null;} else {return new GroupMerger<T>(groupSort).merge(topGroups, offset, topN);