BrowseHit[] hits = new BrowseHit[scoreDocs.length];
Collection<FacetHandler<?>> facetHandlers = facetHandlerMap.values();
for (int i = scoreDocs.length - 1; i >= 0; i--) {
MyScoreDoc fdoc = scoreDocs[i];
BoboSegmentReader reader = fdoc.reader;
BrowseHit hit = new BrowseHit();
if (fetchStoredFields) {
hit.setStoredFields(reader.document(fdoc.doc));
}
if (termVectorsToFetch != null && termVectorsToFetch.size() > 0) {
Map<String, List<BoboTerm>> tvMap = new HashMap<String, List<BoboTerm>>();
hit.setTermVectorMap(tvMap);
Fields fds = reader.getTermVectors(fdoc.doc);
for (String field : termVectorsToFetch) {
Terms terms = fds.terms(field);
if (terms == null) {
continue;
}
TermsEnum termsEnum = terms.iterator(null);
BytesRef text;
DocsAndPositionsEnum docsAndPositions = null;
List<BoboTerm> boboTermList = new ArrayList<BoboTerm>();
while ((text = termsEnum.next()) != null) {
BoboTerm boboTerm = new BoboTerm();
boboTerm.term = text.utf8ToString();
boboTerm.freq = (int) termsEnum.totalTermFreq();
docsAndPositions = termsEnum.docsAndPositions(null, docsAndPositions);
if (docsAndPositions != null) {
docsAndPositions.nextDoc();
boboTerm.positions = new ArrayList<Integer>();
boboTerm.startOffsets = new ArrayList<Integer>();
boboTerm.endOffsets = new ArrayList<Integer>();
for (int t = 0; t < boboTerm.freq; ++t) {
boboTerm.positions.add(docsAndPositions.nextPosition());
boboTerm.startOffsets.add(docsAndPositions.startOffset());
boboTerm.endOffsets.add(docsAndPositions.endOffset());
}
}
boboTermList.add(boboTerm);
}
tvMap.put(field, boboTermList);
}
}
Map<String, String[]> map = new HashMap<String, String[]>();
Map<String, Object[]> rawMap = new HashMap<String, Object[]>();
for (FacetHandler<?> facetHandler : facetHandlers) {
map.put(facetHandler.getName(), facetHandler.getFieldValues(reader, fdoc.doc));
rawMap.put(facetHandler.getName(), facetHandler.getRawFieldValues(reader, fdoc.doc));
}
hit.setFieldValues(map);
hit.setRawFieldValues(rawMap);
hit.setDocid(fdoc.doc + fdoc.queue.base);
hit.setScore(fdoc.score);
hit.setComparable(fdoc.getValue());
if (groupBy != null) {
hit.setGroupField(groupBy.getName());
hit.setGroupValue(hit.getField(groupBy.getName()));
hit.setRawGroupValue(hit.getRawField(groupBy.getName()));
if (groupAccessibles != null && hit.getGroupValue() != null && groupAccessibles != null
&& groupAccessibles.length > 0) {
BrowseFacet facet = groupAccessibles[0].getFacet(hit.getGroupValue());
hit.setGroupHitsCount(facet.getFacetValueHitCount());
}
}
hits[i] = hit;
}
return hits;