public MdrillDetailFdt( SolrIndexSearcher _searcher, SegmentReader reader, SolrParams _params, SolrQueryRequest req) { try { this.hostId = java.net.InetAddress.getLocalHost().getHostAddress() + "," + String.valueOf(java.net.InetAddress.getLocalHost().getHostName()); } catch (UnknownHostException e) { hostId = java.util.UUID.randomUUID().toString(); } this.segKey = reader.getSigmentUniqKey(); this.reader = reader; this.req = req; this.searcher = _searcher; this.parse = new MdrillParseDetailFdt(_params); this.crcget = _params.get("mdrill.crc.key.get", null); this.recordCount = new RecordCountDetail(); this.params = _params; }
@Override public synchronized IndexReader reopen() throws CorruptIndexException, IOException { IndexReader newInner = null; SegmentInfos sinfos = new SegmentInfos(); sinfos.read(_dir); int size = sinfos.size(); if (in instanceof MultiReader) { // setup current reader list 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 IndexReader reader = in.reopen(true); if (in != reader) { return BoboIndexReader.getInstance( newInner, _facetHandlers, _runtimeFacetHandlerFactories, _workArea); } else { return this; } } }