List<IndexReader> boboReaderList = new LinkedList<IndexReader>();
ReaderUtil.gatherSubReaders((List<IndexReader>)boboReaderList, in);
Map<String,BoboIndexReader> readerMap = new HashMap<String,BoboIndexReader>();
for (IndexReader reader : boboReaderList){
BoboIndexReader boboReader = (BoboIndexReader)reader;
SegmentReader sreader = (SegmentReader)(boboReader.in);
readerMap.put(sreader.getSegmentName(),boboReader);
}
ArrayList<BoboIndexReader> currentReaders = new ArrayList<BoboIndexReader>(size);
boolean isNewReader = false;
for (int i=0;i<size;++i){
SegmentInfo sinfo = (SegmentInfo)sinfos.info(i);
BoboIndexReader breader = readerMap.remove(sinfo.name);
if (breader!=null){
// should use SegmentReader.reopen
// TODO: see LUCENE-2559
BoboIndexReader newReader = (BoboIndexReader)breader.reopen(true);
if (newReader!=breader){
isNewReader = true;
}
if (newReader!=null){
currentReaders.add(newReader);
}
}
else{
isNewReader = true;
SegmentReader newSreader = SegmentReader.get(true, sinfo, 1);
breader = BoboIndexReader.getInstanceAsSubReader(newSreader,this._facetHandlers,this._runtimeFacetHandlerFactories);
breader._dir = _dir;
currentReaders.add(breader);
}
}
isNewReader = isNewReader || (readerMap.size() != 0);
if (!isNewReader){
return this;
}
else{
MultiReader newMreader = new MultiReader(currentReaders.toArray(new BoboIndexReader[currentReaders.size()]),false);
BoboIndexReader newReader = BoboIndexReader.getInstanceAsSubReader(newMreader,this._facetHandlers,this._runtimeFacetHandlerFactories);
newReader._dir = _dir;
return newReader;
}
}
else if (in instanceof SegmentReader){
// should use SegmentReader.reopen
// TODO: see LUCENE-2559
SegmentReader sreader = (SegmentReader)in;
int numDels = sreader.numDeletedDocs();
SegmentInfo sinfo = null;
boolean sameSeg = false;
//get SegmentInfo instance
for (int i=0;i<size;++i){
SegmentInfo sinfoTmp = (SegmentInfo)sinfos.info(i);
if (sinfoTmp.name.equals(sreader.getSegmentName())){
int numDels2 = sinfoTmp.getDelCount();
sameSeg = numDels==numDels2;
sinfo = sinfoTmp;
break;
}
}
if (sinfo == null){
// segment no longer exists
return null;
}
if (sameSeg){
return this;
}
else{
SegmentReader newSreader = SegmentReader.get(true, sinfo, 1);
return BoboIndexReader.getInstanceAsSubReader(newSreader,this._facetHandlers,this._runtimeFacetHandlerFactories);
}
}
else{
// should not reach here, a catch-all default case