}
@Override
public SenseiResult handlePartitionedRequest(final SenseiRequest request,
List<BoboIndexReader> readerList,SenseiQueryBuilderFactory queryBuilderFactory) throws Exception {
MultiBoboBrowser browser = null;
try
{
final List<BoboIndexReader> segmentReaders = BoboBrowser.gatherSubReaders(readerList);
if (segmentReaders!=null && segmentReaders.size() > 0) {
final AtomicInteger skipDocs = new AtomicInteger(0);
final SenseiIndexPruner pruner = _core.getIndexPruner();
List<BoboIndexReader> validatedSegmentReaders = _timerMetric.time(new Callable<List<BoboIndexReader>>(){
@Override
public List<BoboIndexReader> call() throws Exception {
IndexReaderSelector readerSelector = pruner.getReaderSelector(request);
List<BoboIndexReader> validatedReaders = new ArrayList<BoboIndexReader>(segmentReaders.size());
for (BoboIndexReader segmentReader : segmentReaders){
if (readerSelector.isSelected(segmentReader)){
validatedReaders.add(segmentReader);
}
else{
skipDocs.addAndGet(segmentReader.numDocs());
}
}
return validatedReaders;
}
});
pruner.sort(validatedSegmentReaders);
browser = new MultiBoboBrowser(BoboBrowser.createBrowsables(validatedSegmentReaders));
request.setSearchable(browser);
request.setQueryBuilderFactory(queryBuilderFactory);
BrowseRequest breq = RequestConverter.convert(request, queryBuilderFactory);
if (request.getMapReduceFunction() != null) {
SenseiMapFunctionWrapper mapWrapper = new SenseiMapFunctionWrapper(request.getMapReduceFunction(), _core.getSystemInfo().getFacetInfos());
breq.setMapReduceWrapper(mapWrapper);
}
SubReaderAccessor<BoboIndexReader> subReaderAccessor =
ZoieIndexReader.getSubReaderAccessor(validatedSegmentReaders);
SenseiResult res = browse(request, browser, breq, subReaderAccessor);
int totalDocs = res.getTotalDocs()+skipDocs.get();
res.setTotalDocs(totalDocs);
// For debugging serialization issues:
// byte[] responseBytes = getSerializer().responseToBytes(res);
// SenseiResult response2 = getSerializer().responseFromBytes(responseBytes);
// if(!res.equals(response2)) {
// throw new IllegalArgumentException("Cant serialize response");
// }
return res;
}
else{
return new SenseiResult();
}
} catch (Exception e)
{
logger.error(e.getMessage(), e);
throw e;
} finally
{
if (browser != null)
{
try
{
browser.close();
} catch (IOException ioe)
{
logger.error(ioe.getMessage(), ioe);
}
}