}
else
{
int[] rawGroupValueType = new int[req.getGroupBy().length]; // 0: unknown, 1: normal, 2: long[]
PrimitiveLongArrayWrapper primitiveLongArrayWrapperTmp = new PrimitiveLongArrayWrapper(null);
Iterator<SenseiHit> mergedIter = ListMerger.mergeLists(hitLists, comparator);
List<SenseiHit> hitsList = null;
if (!hasSortCollector)
{
hitsList = buildHitsListNoSortCollector(req, topHits, rawGroupValueType, mergedIter, req.getOffset());
//numGroups = (int)(numGroups*(groupHitMap.size()/(float)preGroups));
}
else
{
int offsetLeft = req.getOffset();
MyScoreDoc pre = null;
if (topHits > 0 && groupAccessibles != null && groupAccessibles.length != 0)
{
hitsList = buildHitsList(req, results, topHits, groupAccessibles, rawGroupValueType, primitiveLongArrayWrapperTmp);
}
else
{
hitsList = buildHitsListNoGroupAccessibles(req, topHits, rawGroupValueType, primitiveLongArrayWrapperTmp, mergedIter, offsetLeft);
}
//for (int i=0; i<combinedFacetAccessibles.length; ++i) combinedFacetAccessibles[i].close();
}
hits = hitsList.toArray(new SenseiHit[hitsList.size()]);
primitiveLongArrayWrapperTmp = new PrimitiveLongArrayWrapper(null);
PrepareGroupMappings prepareGroupMappings = new PrepareGroupMappings(req, results, hasSortCollector, hits, rawGroupValueType, primitiveLongArrayWrapperTmp).invoke();
Map<Object, HitWithGroupQueue>[] groupMaps = prepareGroupMappings.getGroupMaps();
totalDocs = prepareGroupMappings.getTotalDocs();
if (hasSortCollector)
{
// Fix group position
for (SenseiHit hit : hits)
{
if (hit.getGroupHitsCount() <= 1)
{
hit.setGroupPosition(0);
hit.setGroupField(req.getGroupBy()[0]);
hit.setGroupValue(hit.getField(req.getGroupBy()[0]));
hit.setRawGroupValue(hit.getRawField(req.getGroupBy()[0]));
}
}
for (Map<Object, HitWithGroupQueue> map : groupMaps)
{
for (HitWithGroupQueue hwg : map.values())
{
if (hwg.queue == null) continue;
int index = hwg.queue.size - 1;
if (index >= 0)
{
SenseiHit[] groupHits = new SenseiHit[index+1];
while (index >=0)
{
groupHits[index] = ((MyScoreDoc)hwg.queue.pop()).getSenseiHit(req);
--index;
}
hwg.hit.setGroupHits(groupHits);
}
}
}
}
else
{
Set<Object>[] distinctSets = null;
Object[] distinctValues = null;
int[] distinctValueType = null;
if (req.getDistinct() != null && req.getDistinct().length != 0)
{
distinctSets = new Set[req.getDistinct().length];
for (int i = 0; i < distinctSets.length; ++i)
{
distinctSets[i] = new HashSet<Object>(req.getMaxPerGroup());
}
distinctValues = new Object[distinctSets.length];
distinctValueType = new int[distinctSets.length];
primitiveLongArrayWrapperTmp = new PrimitiveLongArrayWrapper(null);
}
for (Map<Object, HitWithGroupQueue> map : groupMaps)
{
for (HitWithGroupQueue hwg : map.values())
{