Apache Lucene open-source search software
SOLR-8043: add DocSetCollector constructor that calculates small-set-size, add DocSetUtil.smallSetSize
Yonik Seeley68d942eee149
diff --git a/solr/core/src/java/org/apache/solr/search/DocSetCollector.java b/solr/core/src/java/org/apache/solr/search/DocSetCollector.javaindex c26581db991..921339a18cf 100644--- a/solr/core/src/java/org/apache/solr/search/DocSetCollector.java+++ b/solr/core/src/java/org/apache/solr/search/DocSetCollector.java@@ -40,6 +40,10 @@ public class DocSetCollector extends SimpleCollector {// in case there are only a few.final int[] scratch;+ public DocSetCollector(int maxDoc) {+ this(DocSetUtil.smallSetSize(maxDoc), maxDoc);+ }+public DocSetCollector(int smallSetSize, int maxDoc) {this.smallSetSize = smallSetSize;this.maxDoc = maxDoc;diff --git a/solr/core/src/java/org/apache/solr/search/DocSetUtil.java b/solr/core/src/java/org/apache/solr/search/DocSetUtil.javaindex 590f1bec285..f9047ee51e3 100644--- a/solr/core/src/java/org/apache/solr/search/DocSetUtil.java+++ b/solr/core/src/java/org/apache/solr/search/DocSetUtil.java@@ -46,6 +46,11 @@ import org.apache.lucene.util.FixedBitSet;/** @lucene.experimental */public class DocSetUtil {+ /** The cut-off point for small sets (SortedIntDocSet) vs large sets (BitDocSet) */+ public static int smallSetSize(int maxDoc) {+ return (maxDoc>>6)+5; // The +5 is for better test coverage for small sets+ }+/*** Iterates DocSets to test for equality - slow and for testing purposes only.* @lucene.internal@@ -97,7 +102,7 @@ public class DocSetUtil {public static DocSet createDocSetGeneric(SolrIndexSearcher searcher, Query query) throws IOException {int maxDoc = searcher.getIndexReader().maxDoc();- DocSetCollector collector = new DocSetCollector((maxDoc >> 6) + 5, maxDoc);+ DocSetCollector collector = new DocSetCollector(maxDoc);// This may throw an ExitableDirectoryReader.ExitingReaderException// but we should not catch it here, as we don't know how this DocSet will be used (it could be negated before use) or cached.@@ -109,7 +114,7 @@ public class DocSetUtil {public static DocSet createDocSet(SolrIndexSearcher searcher, Term term) throws IOException {DirectoryReader reader = searcher.getRawReader(); // raw reader to avoid extra wrapping overheadint maxDoc = searcher.getIndexReader().maxDoc();- int smallSetSize = (maxDoc >> 6) + 5;+ int smallSetSize = smallSetSize(maxDoc);String field = term.field();@@ -187,7 +192,7 @@ public class DocSetUtil {BitDocSet docSet = new BitDocSet( new FixedBitSet(bits, maxDoc), sz );- int smallSetSize = (maxDoc >> 6) + 5;+ int smallSetSize = smallSetSize(maxDoc);if (sz < smallSetSize) {// make this optional?DocSet smallSet = toSmallSet( docSet );diff --git a/solr/core/src/java/org/apache/solr/search/Grouping.java b/solr/core/src/java/org/apache/solr/search/Grouping.javaindex 3cce5981107..f7c91378717 100644--- a/solr/core/src/java/org/apache/solr/search/Grouping.java+++ b/solr/core/src/java/org/apache/solr/search/Grouping.java@@ -347,7 +347,7 @@ public class Grouping {DocSetCollector setCollector = null;if (getDocSet && allGroupHeadsCollector == null) {- setCollector = new DocSetCollector(maxDoc >> 6, maxDoc);+ setCollector = new DocSetCollector(maxDoc);collectors.add(setCollector);}Collector allCollectors = MultiCollector.wrap(collectors);diff --git a/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java b/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.javaindex ef186d53891..654c1a68001 100644--- a/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java+++ b/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java@@ -967,7 +967,7 @@ public class SolrIndexSearcher extends IndexSearcher implements Closeable,SolrInprivate DocSet getDocSetScore(List<Query> queries) throws IOException {Query main = queries.remove(0);ProcessedFilter pf = getProcessedFilter(null, queries);- DocSetCollector setCollector = new DocSetCollector(maxDoc()>>6, maxDoc());+ DocSetCollector setCollector = new DocSetCollector(maxDoc());Collector collector = setCollector;if (pf.postFilter != null) {pf.postFilter.setLastDelegate(collector);@@ -1014,7 +1014,7 @@ public class SolrIndexSearcher extends IndexSearcher implements Closeable,SolrInif (pf.answer != null) return pf.answer;- DocSetCollector setCollector = new DocSetCollector(maxDoc()>>6, maxDoc());+ DocSetCollector setCollector = new DocSetCollector(maxDoc());Collector collector = setCollector;if (pf.postFilter != null) {pf.postFilter.setLastDelegate(collector);@@ -1187,7 +1187,7 @@ public class SolrIndexSearcher extends IndexSearcher implements Closeable,SolrInif (result != null) return result;}- int smallSetSize = maxDoc()>>6;+ int smallSetSize = DocSetUtil.smallSetSize(maxDoc());int scratchSize = Math.min(smallSetSize, largestPossible);if (deState.scratch == null || deState.scratch.length < scratchSize)deState.scratch = new int[scratchSize];@@ -1715,7 +1715,6 @@ public class SolrIndexSearcher extends IndexSearcher implements Closeable,SolrInboolean needScores = (cmd.getFlags() & GET_SCORES) != 0;int maxDoc = maxDoc();- int smallSetSize = maxDoc>>6;ProcessedFilter pf = getProcessedFilter(cmd.getFilter(), cmd.getFilterList());Query query = QueryUtils.makeQueryable(cmd.getQuery());@@ -1731,7 +1730,7 @@ public class SolrIndexSearcher extends IndexSearcher implements Closeable,SolrInfinal float[] topscore = new float[] { Float.NEGATIVE_INFINITY };Collector collector;- final DocSetCollector setCollector = new DocSetCollector(smallSetSize, maxDoc);+ final DocSetCollector setCollector = new DocSetCollector(maxDoc);if (!needScores) {collector = setCollector;@@ -1774,7 +1773,7 @@ public class SolrIndexSearcher extends IndexSearcher implements Closeable,SolrIn} else {final TopDocsCollector topCollector = buildTopDocsCollector(len, cmd);- DocSetCollector setCollector = new DocSetCollector(maxDoc>>6, maxDoc);+ DocSetCollector setCollector = new DocSetCollector(maxDoc);Collector collector = MultiCollector.wrap(topCollector, setCollector);buildAndRunCollectorChain(qr, query, collector, cmd, pf.postFilter);diff --git a/solr/core/src/java/org/apache/solr/search/facet/BlockJoin.java b/solr/core/src/java/org/apache/solr/search/facet/BlockJoin.javaindex e4f75f4e554..6af62dec46e 100644--- a/solr/core/src/java/org/apache/solr/search/facet/BlockJoin.java+++ b/solr/core/src/java/org/apache/solr/search/facet/BlockJoin.java@@ -26,6 +26,7 @@ import org.apache.solr.search.BitDocSet;import org.apache.solr.search.DocIterator;import org.apache.solr.search.DocSet;import org.apache.solr.search.DocSetCollector;+import org.apache.solr.search.DocSetUtil;import org.apache.solr.search.QueryContext;/** @lucene.experimental */@@ -36,7 +37,7 @@ public class BlockJoin {*/public static DocSet toChildren(DocSet parentInput, BitDocSet parentList, DocSet acceptDocs, QueryContext qcontext) throws IOException {FixedBitSet parentBits = parentList.getBits();- DocSetCollector collector = new DocSetCollector(qcontext.searcher().maxDoc()>>6, qcontext.searcher().maxDoc());+ DocSetCollector collector = new DocSetCollector(qcontext.searcher().maxDoc());DocIterator iter = parentInput.iterator();while (iter.hasNext()) {int parentDoc = iter.nextDoc();@@ -56,7 +57,7 @@ public class BlockJoin {/** childInput may also contain parents (i.e. a parent or below will all roll up to that parent) */public static DocSet toParents(DocSet childInput, BitDocSet parentList, QueryContext qcontext) throws IOException {FixedBitSet parentBits = parentList.getBits();- DocSetCollector collector = new DocSetCollector(qcontext.searcher().maxDoc()>>6, qcontext.searcher().maxDoc());+ DocSetCollector collector = new DocSetCollector(qcontext.searcher().maxDoc());DocIterator iter = childInput.iterator();int currentParent = -1;while (iter.hasNext()) {diff --git a/solr/core/src/java/org/apache/solr/search/grouping/CommandHandler.java b/solr/core/src/java/org/apache/solr/search/grouping/CommandHandler.javaindex aaa3a29d2bc..1b03ef26694 100644--- a/solr/core/src/java/org/apache/solr/search/grouping/CommandHandler.java+++ b/solr/core/src/java/org/apache/solr/search/grouping/CommandHandler.java@@ -190,7 +190,7 @@ public class CommandHandler {private DocSet computeDocSet(Query query, ProcessedFilter filter, List<Collector> collectors) throws IOException {int maxDoc = searcher.maxDoc();final Collector collector;- final DocSetCollector docSetCollector = new DocSetCollector(maxDoc >> 6, maxDoc);+ final DocSetCollector docSetCollector = new DocSetCollector(maxDoc);List<Collector> allCollectors = new ArrayList<>(collectors);allCollectors.add(docSetCollector);searchWithTimeLimiter(query, filter, MultiCollector.wrap(allCollectors));