diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 79d18b72f84..85b95218168 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -167,6 +167,9 @@ Optimizations the "threads" local param on the facet.field param. This algorithm will only be faster in the presence of rapid index changes. (yonik) +* SOLR-1904: When facet.enum.cache.minDf > 0 and the base doc set is a + SortedIntSet, convert to HashDocSet for better performance. (yonik) + Bug Fixes ---------------------- diff --git a/solr/src/java/org/apache/solr/request/SimpleFacets.java b/solr/src/java/org/apache/solr/request/SimpleFacets.java index 853a9fa3bfa..235e481c42b 100644 --- a/solr/src/java/org/apache/solr/request/SimpleFacets.java +++ b/solr/src/java/org/apache/solr/request/SimpleFacets.java @@ -493,6 +493,14 @@ public class SimpleFacets { // Minimum term docFreq in order to use the filterCache for that term. int minDfFilterCache = params.getFieldInt(field, FacetParams.FACET_ENUM_CACHE_MINDF, 0); + // make sure we have a set that is fast for random access, if we will use it for that + DocSet fastForRandomSet = docs; + if (minDfFilterCache>0 && docs instanceof SortedIntDocSet) { + SortedIntDocSet sset = (SortedIntDocSet)docs; + fastForRandomSet = new HashDocSet(sset.getDocs(), 0, sset.size()); + } + + IndexSchema schema = searcher.getSchema(); IndexReader r = searcher.getReader(); FieldType ft = schema.getFieldType(field); @@ -576,7 +584,7 @@ public class SimpleFacets { int[] docArr = bulk.docs.ints; // this might be movable outside the loop, but perhaps not worth the risk. int end = bulk.docs.offset + nDocs; for (int i=bulk.docs.offset; i