if (offset < 0 || count < 0) {
throw new IllegalArgumentException("both offset and count must be > 0: " + offset + "/"
+ count);
}
SortCollector collector = getSortCollector(req.getSort(), req.getQuery(), offset, count,
req.isFetchStoredFields(), req.getTermVectorsToFetch(), req.getGroupBy(),
req.getMaxPerGroup(), req.getCollectDocIdCache());
Map<String, FacetAccessible> facetCollectors = new HashMap<String, FacetAccessible>();
browse(req, collector, facetCollectors);
if (req.getMapReduceWrapper() != null) {
result.setMapReduceResult(req.getMapReduceWrapper().getResult());
}
BrowseHit[] hits = null;
try {
hits = collector.topDocs();
} catch (IOException e) {
logger.error(e.getMessage(), e);
result.addError(e.getMessage());
hits = new BrowseHit[0];
}
Query q = req.getQuery();
if (req.isShowExplanation()) {
for (BrowseHit hit : hits) {
try {
int doc = hit.getDocid();
Explanation expl = _indexSearcher.explain(q, doc);
hit.setExplanation(expl);
} catch (IOException e) {
logger.error(e.getMessage(), e);
result.addError(e.getMessage());
}
}
}
result.setHits(hits);
result.setNumHits(collector.getTotalHits());
result.setNumGroups(collector.getTotalGroups());
result.setGroupAccessibles(collector.getGroupAccessibles());
result.setSortCollector(collector);
result.setTotalDocs(numDocs());
result.addAll(facetCollectors);
long end = System.currentTimeMillis();
result.setTime(end - start);