use of org.apache.geode.cache.lucene.internal.distributed.TopEntries.EntryScoreComparator in project geode by apache.
the class TopEntriesCollectorManager method reduce.
@Override
public TopEntriesCollector reduce(Collection<TopEntriesCollector> collectors) {
TopEntriesCollector mergedResult = new TopEntriesCollector(id, limit);
if (collectors.isEmpty()) {
return mergedResult;
}
final EntryScoreComparator scoreComparator = new TopEntries().new EntryScoreComparator();
// orders a entry with higher score above a doc with lower score
Comparator<ListScanner> entryListComparator = new Comparator<ListScanner>() {
@Override
public int compare(ListScanner l1, ListScanner l2) {
EntryScore o1 = l1.peek();
EntryScore o2 = l2.peek();
return scoreComparator.compare(o1, o2);
}
};
// The queue contains iterators for all bucket results. The queue puts the entry with the
// highest score at the head
// using score comparator.
PriorityQueue<ListScanner> entryListsPriorityQueue;
entryListsPriorityQueue = new PriorityQueue<ListScanner>(collectors.size(), Collections.reverseOrder(entryListComparator));
for (IndexResultCollector collector : collectors) {
logger.debug("Number of entries found in collector {} is {}", collector.getName(), collector.size());
if (collector.size() > 0) {
entryListsPriorityQueue.add(new ListScanner(((TopEntriesCollector) collector).getEntries().getHits()));
}
}
logger.debug("Only {} count of entries will be reduced. Other entries will be ignored", limit);
while (entryListsPriorityQueue.size() > 0 && limit > mergedResult.size()) {
ListScanner scanner = entryListsPriorityQueue.remove();
EntryScore entry = scanner.next();
mergedResult.collect(entry);
if (scanner.hasNext()) {
entryListsPriorityQueue.add(scanner);
}
}
logger.debug("Reduced size of {} is {}", mergedResult.getName(), mergedResult.size());
return mergedResult;
}
Aggregations