Package org.apache.lucene.index

Examples of org.apache.lucene.index.SegmentInfo


    }
   
    ArrayList<BoboIndexReader> currentReaders = new ArrayList<BoboIndexReader>(size);
    boolean isNewReader = false;
    for (int i=0;i<size;++i){
      SegmentInfo sinfo = (SegmentInfo)sinfos.get(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.get(i);
    if (sinfoTmp.name.equals(sreader.getSegmentName())){
      int numDels2 = sinfoTmp.getDelCount();
      sameSeg = numDels==numDels2;
      sinfo = sinfoTmp;
      break;
    }
    }
View Full Code Here


     
      if (input.getFilePointer() != input.length()) {
        throw new CorruptIndexException("did not read all bytes from file \"" + fileName + "\": read " + input.getFilePointer() + " vs size " + input.length() + " (resource: " + input + ")");
      }

      final SegmentInfo si = new SegmentInfo(dir, version, segment, docCount, isCompoundFile, null, diagnostics);
      si.setFiles(files);

      success = true;

      return si;
View Full Code Here

    infos.version = input.readLong(); // read version
    infos.counter = input.readInt(); // read counter
    Lucene3xSegmentInfoReader reader = new Lucene3xSegmentInfoReader();
    for (int i = input.readInt(); i > 0; i--) { // read segmentInfos
      SegmentCommitInfo siPerCommit = reader.readLegacySegmentInfo(directory, format, input);
      SegmentInfo si = siPerCommit.info;

      if (si.getVersion() == null) {
        // Could be a 3.0 - try to open the doc stores - if it fails, it's a
        // 2.x segment, and an IndexFormatTooOldException will be thrown,
        // which is what we want.
        Directory dir = directory;
        if (Lucene3xSegmentInfoFormat.getDocStoreOffset(si) != -1) {
          if (Lucene3xSegmentInfoFormat.getDocStoreIsCompoundFile(si)) {
            dir = new CompoundFileDirectory(dir, IndexFileNames.segmentFileName(
                Lucene3xSegmentInfoFormat.getDocStoreSegment(si), "",
                Lucene3xCodec.COMPOUND_FILE_STORE_EXTENSION), IOContext.READONCE, false);
          }
        } else if (si.getUseCompoundFile()) {
          dir = new CompoundFileDirectory(dir, IndexFileNames.segmentFileName(
              si.name, "", IndexFileNames.COMPOUND_FILE_EXTENSION), IOContext.READONCE, false);
        }

        try {
          Lucene3xStoredFieldsReader.checkCodeVersion(dir, Lucene3xSegmentInfoFormat.getDocStoreSegment(si));
        } finally {
          // If we opened the directory, close it
          if (dir != directory) dir.close();
        }
         
        // Above call succeeded, so it's a 3.0 segment. Upgrade it so the next
        // time the segment is read, its version won't be null and we won't
        // need to open FieldsReader every time for each such segment.
        si.setVersion("3.0");
      } else if (si.getVersion().equals("2.x")) {
        // If it's a 3x index touched by 3.1+ code, then segments record their
        // version, whether they are 2.x ones or not. We detect that and throw
        // appropriate exception.
        throw new IndexFormatTooOldException("segment " + si.name + " in resource " + input, si.getVersion());
      }
      infos.add(siPerCommit);
    }
     
    infos.userData = input.readStringStringMap();
View Full Code Here

    boolean success = false;

    IndexInput input = directory.openInput(fileName, context);

    try {
      SegmentInfo si = readUpgradedSegmentInfo(segmentName, directory, input);
      success = true;
      return si;
    } finally {
      if (!success) {
        IOUtils.closeWhileHandlingException(input);
View Full Code Here

          assert false;
        }
      }
    }

    SegmentInfo info = new SegmentInfo(dir, version, name, docCount, isCompoundFile,
                                       null, diagnostics, Collections.unmodifiableMap(attributes));
    info.setFiles(files);

    SegmentCommitInfo infoPerCommit = new SegmentCommitInfo(info, delCount, delGen, -1);
    return infoPerCommit;
  }
View Full Code Here

    final Map<String,String> diagnostics = input.readStringStringMap();

    final Set<String> files = input.readStringSet();

    SegmentInfo info = new SegmentInfo(dir, version, name, docCount, isCompoundFile,
                                       null, diagnostics, Collections.unmodifiableMap(attributes));
    info.setFiles(files);
    return info;
  }
View Full Code Here

     
      if (input.getFilePointer() != input.length()) {
        throw new CorruptIndexException("did not read all bytes from file \"" + fileName + "\": read " + input.getFilePointer() + " vs size " + input.length() + " (resource: " + input + ")");
      }

      final SegmentInfo si = new SegmentInfo(dir, version, segment, docCount, isCompoundFile, null, diagnostics);
      si.setFiles(files);

      success = true;

      return si;
View Full Code Here

        assert StringHelper.startsWith(scratch, SI_FILE);
        String fileName = readString(SI_FILE.length, scratch);
        files.add(fileName);
      }

      SegmentInfo info = new SegmentInfo(directory, version, segmentName, docCount,
                                         isCompoundFile, null, diagnostics);
      info.setFiles(files);
      success = true;
      return info;
    } finally {
      if (!success) {
        IOUtils.closeWhileHandlingException(input);
View Full Code Here

            Searcher searcher = searcher();
            try {
                IndexReader[] readers = searcher.reader().getSequentialSubReaders();
                for (IndexReader reader : readers) {
                    assert reader instanceof SegmentReader;
                    SegmentInfo info = Lucene.getSegmentInfo((SegmentReader) reader);
                    assert !segments.containsKey(info.name);
                    Segment segment = new Segment(info.name);
                    segment.search = true;
                    segment.docCount = reader.numDocs();
                    segment.delDocCount = reader.numDeletedDocs();
                    try {
                        segment.sizeInBytes = info.sizeInBytes(true);
                    } catch (IOException e) {
                        logger.trace("failed to get size for [{}]", e, info.name);
                    }
                    segments.put(info.name, segment);
                }
            } finally {
                searcher.release();
            }

            // now, correlate or add the committed ones...
            if (lastCommittedSegmentInfos != null) {
                SegmentInfos infos = lastCommittedSegmentInfos;
                for (SegmentInfo info : infos) {
                    Segment segment = segments.get(info.name);
                    if (segment == null) {
                        segment = new Segment(info.name);
                        segment.search = false;
                        segment.committed = true;
                        segment.docCount = info.docCount;
                        try {
                            segment.delDocCount = indexWriter.numDeletedDocs(info);
                        } catch (IOException e) {
                            logger.trace("failed to get deleted docs for committed segment", e);
                        }
                        try {
                            segment.sizeInBytes = info.sizeInBytes(true);
                        } catch (IOException e) {
                            logger.trace("failed to get size for [{}]", e, info.name);
                        }
                        segments.put(info.name, segment);
                    } else {
View Full Code Here

  }

  private boolean isOptimized(SegmentInfos infos, IndexWriter writer, int maxNumSegments, Set<?> segmentsToOptimize) throws IOException {
    final int numSegments = infos.size();
    int numToOptimize = 0;
    SegmentInfo optimizeInfo = null;
    for(int i=0;i<numSegments && numToOptimize <= maxNumSegments;i++) {
      final SegmentInfo info = infos.info(i);
      if (segmentsToOptimize.contains(info)) {
        numToOptimize++;
        optimizeInfo = info;
      }
    }
View Full Code Here

TOP

Related Classes of org.apache.lucene.index.SegmentInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.