if (_predefinedRangeIndexes != null) {
int minCount = _ospec.getMinHitCount();
int maxNumOfFacets = _ospec.getMaxCount();
if (maxNumOfFacets <= 0 || maxNumOfFacets > _predefinedRangeIndexes.length) maxNumOfFacets = _predefinedRangeIndexes.length;
BigSegmentedArray rangeCount = new LazyBigIntArray(_predefinedRangeIndexes.length);
for (int k = 0; k < _predefinedRangeIndexes.length; ++k) {
int count = 0;
int idx = _predefinedRangeIndexes[k][0];
int end = _predefinedRangeIndexes[k][1];
while (idx <= end) {
count += _count.get(idx++);
}
rangeCount.add(k, count);
}
List<BrowseFacet> facetColl;
FacetSortSpec sortspec = _ospec.getOrderBy();
if (sortspec == FacetSortSpec.OrderValueAsc) {
facetColl = new ArrayList<BrowseFacet>(maxNumOfFacets);
for (int k = 0; k < _predefinedRangeIndexes.length; ++k) {
if (rangeCount.get(k) >= minCount) {
BrowseFacet choice = new BrowseFacet(_predefinedRanges.get(k), rangeCount.get(k));
facetColl.add(choice);
}
if (facetColl.size() >= maxNumOfFacets) break;
}
} else // if (sortspec == FacetSortSpec.OrderHitsDesc)
{
ComparatorFactory comparatorFactory;
if (sortspec == FacetSortSpec.OrderHitsDesc) {
comparatorFactory = new FacetHitcountComparatorFactory();
} else {
comparatorFactory = _ospec.getCustomComparatorFactory();
}
if (comparatorFactory == null) {
throw new IllegalArgumentException("facet comparator factory not specified");
}
final IntComparator comparator = comparatorFactory.newComparator(
new FieldValueAccessor() {
@Override
public String getFormatedValue(int index) {
return _predefinedRanges.get(index);
}
@Override
public Object getRawValue(int index) {
return _predefinedRanges.getRawValue(index);
}
}, rangeCount);
final int forbidden = -1;
IntBoundedPriorityQueue pq = new IntBoundedPriorityQueue(comparator, maxNumOfFacets,
forbidden);
for (int i = 0; i < _predefinedRangeIndexes.length; ++i) {
if (rangeCount.get(i) >= minCount) pq.offer(i);
}
int val;
facetColl = new LinkedList<BrowseFacet>();
while ((val = pq.pollInt()) != forbidden) {
BrowseFacet facet = new BrowseFacet(_predefinedRanges.get(val), rangeCount.get(val));
((LinkedList<BrowseFacet>) facetColl).addFirst(facet);
}
}
return facetColl;
} else {