List<Integer> docIds = new ArrayList<Integer>(list.size());
while (it.hasNext())
docIds.add(it.next());
IndexReader reader = (IndexReader) ((SolrIndexReader) rb.req.getSearcher().getIndexReader())
.getWrappedReader();
SolrQueryRequest req = rb.req;
SolrParams params = req.getParams();
String ids = params.get(ShardParams.IDS);
// only set firstPhase threadLocal in case of sharding.
// this is to optimize our querying time by not fetching actually doc obj in first phase of sharding
// first phase of sharding only tries to fetch docids and scores which are already in tv
if(SolbaseShardUtil.getNumShard() != 0){
if (ids != null) {
IndexReader.firstPhase.set(false);
} else {
IndexReader.firstPhase.set(true);
}
} else {
// it's always false in case of stand alone
IndexReader.firstPhase.set(false);
}
logger.debug(reader.getIndexName() + " : Fetching " + docIds.size() + " Docs");
if (docIds.size() > 0) {
List<byte[]> fieldFilter = null;
Set<String> returnFields = rb.rsp.getReturnFields();
if (returnFields != null) {
// copy return fields list
fieldFilter = new ArrayList<byte[]>(returnFields.size());
for (String field : returnFields) {
fieldFilter.add(Bytes.toBytes(field));
}
// add highlight fields
SolrHighlighter highligher = rb.req.getCore().getHighlighter();
if (highligher.isHighlightingEnabled(rb.req.getParams())) {
for (String field : highligher.getHighlightFields(rb.getQuery(), rb.req, null))
if (!returnFields.contains(field))
fieldFilter.add(Bytes.toBytes(field));
}
// fetch unique key if one exists.
SchemaField keyField = rb.req.getSearcher().getSchema().getUniqueKeyField();
if (null != keyField)
if (!returnFields.contains(keyField))
fieldFilter.add(Bytes.toBytes(keyField.getName()));
}
FieldSelector selector = new SolbaseFieldSelector(docIds, fieldFilter);
// This will bulk load these docs
rb.req.getSearcher().getReader().document(docIds.get(0), selector);
}
ReaderCache.flushThreadLocalCaches(reader.getIndexName());
}