}
};
if (maxCnt != Integer.MAX_VALUE) {
// we will maintain a min heap of size maxCnt
// Order by hits in descending order and max count is supplied
PriorityQueue queue = createPQ(maxCnt, comparator);
int qsize = 0;
while ((qsize < maxCnt) && ((facet = iter.next(minHits)) != null)) {
queue.add(new BrowseFacet(String.valueOf(facet), iter.count));
qsize++;
}
if (facet != null) {
BrowseFacet rootFacet = (BrowseFacet) queue.top();
minHits = rootFacet.getFacetValueHitCount() + 1;
// facet count less than top of min heap, it will never be added
while (((facet = iter.next(minHits)) != null)) {
rootFacet.setValue(String.valueOf(facet));
rootFacet.setFacetValueHitCount(iter.count);
rootFacet = (BrowseFacet) queue.updateTop();
minHits = rootFacet.getFacetValueHitCount() + 1;
}
}
// at this point, queue contains top maxCnt facets that have hitcount >= minHits
while (qsize-- > 0) {
// append each entry to the beginning of the facet list to order facets by hits descending
list.addFirst((BrowseFacet) queue.pop());
}
} else {
// no maxCnt specified. So fetch all facets according to minHits and sort them later
while ((facet = iter.next(minHits)) != null)
list.add(new BrowseFacet(String.valueOf(facet), iter.count));
Collections.sort(list, comparator);
}
} else // FacetSortSpec.OrderByCustom.equals(_fspec.getOrderBy()
{
comparator = _fspec.getCustomComparatorFactory().newComparator();
if (maxCnt != Integer.MAX_VALUE) {
PriorityQueue queue = createPQ(maxCnt, comparator);
BrowseFacet browseFacet = new BrowseFacet();
int qsize = 0;
while ((qsize < maxCnt) && ((facet = iter.next(minHits)) != null)) {
queue.add(new BrowseFacet(String.valueOf(facet), iter.count));
qsize++;
}
if (facet != null) {
while ((facet = iter.next(minHits)) != null) {
// check with the top of min heap
browseFacet.setFacetValueHitCount(iter.count);
browseFacet.setValue(String.valueOf(facet));
browseFacet = (BrowseFacet) queue.insertWithOverflow(browseFacet);
}
}
// remove from queue and add to the list
while (qsize-- > 0)
list.addFirst((BrowseFacet) queue.pop());
} else {
// order by custom but no max count supplied
while ((facet = iter.next(minHits)) != null)
list.add(new BrowseFacet(String.valueOf(facet), iter.count));
Collections.sort(list, comparator);