filters.add(fqp.getQuery());
}
}
}
} catch (ParseException e) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
}
Query query = rb.getQuery();
SortSpec sortspec = rb.getSortSpec();
Sort sort = null;
if (sortspec!=null){
sort = sortspec.getSort();
}
SolrParams solrParams = rb.req.getParams();
String shardsVal = solrParams.get(ShardParams.SHARDS, null);
BrowseRequest br = null;
try{
br=BoboRequestBuilder.buildRequest(solrParams,query,sort);
}
catch(Exception e){
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
}
BrowseResult res = null;
if (shardsVal == null && !solrParams.getBool(ShardParams.IS_SHARD, false))
{
SolrIndexSearcher searcher=rb.req.getSearcher();
SolrIndexReader solrReader = searcher.getReader();
BoboIndexReader reader = (BoboIndexReader)solrReader.getWrappedReader();
if (reader instanceof BoboIndexReader){
try {
List<Query> filters = rb.getFilters();
if (filters!=null){
final ArrayList<DocIdSet> docsets = new ArrayList<DocIdSet>(filters.size());
for (Query filter : filters){
Weight weight = filter.createWeight(rb.req.getSearcher());
final Scorer scorer = weight.scorer(reader, false, true);
docsets.add(new DocIdSet(){
@Override
public DocIdSetIterator iterator() throws IOException {
return scorer;
}
});
}
if (docsets.size()>0){
br.setFilter(
new Filter(){
@Override
public DocIdSet getDocIdSet(IndexReader reader)
throws IOException {
return new AndDocIdSet(docsets);
}
});
}
}
Set<String> facetNames = reader.getFacetNames();
Set<String> returnFields = rb.rsp.getReturnFields();
Set<String> storedFields = new HashSet<String>();
if (returnFields!=null){
for (String fld : returnFields){
if (!facetNames.contains(fld)){
storedFields.add(fld);
}
}
br.setFetchStoredFields(!storedFields.isEmpty());
}
BoboBrowser browser = new BoboBrowser(reader);
res=browser.browse(br);
} catch (Exception e) {
logger.error(e.getMessage(),e);
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,e.getMessage(),e);
}
}
else{
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,"invalid reader, please make sure BoboIndexReaderFactory is set.");
}
}
else{
// multi sharded request
String[] shards = shardsVal.split(",");