for (int i = 1; i < countlength;++i) // exclude zero
{
int hits=count.get(i);
if (hits>=minCount)
{
BrowseFacet facet=new BrowseFacet(valList.get(i),hits);
facetColl.add(facet);
}
if (facetColl.size()>=max) 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(){
public String getFormatedValue(int index) {
return valList.get(index);
}
public Object getRawValue(int index) {
return valList.getRawValue(index);
}
}, count);
facetColl=new LinkedList<BrowseFacet>();
final int forbidden = -1;
IntBoundedPriorityQueue pq=new IntBoundedPriorityQueue(comparator,max, forbidden);
for (int i=1;i<countlength;++i)
{
int hits=count.get(i);
if (hits>=minCount)
{
pq.offer(i);
}
}
int val;
while((val = pq.pollInt()) != forbidden)
{
BrowseFacet facet=new BrowseFacet(valList.get(val),count.get(val));
((LinkedList<BrowseFacet>)facetColl).addFirst(facet);
}
}
return facetColl;
}