Java Code Examples for org.apache.lucene.index.DirectoryReader#getIndexCommit()

The following examples show how to use org.apache.lucene.index.DirectoryReader#getIndexCommit() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: lucene-solr   File: LukeModel.java    License: Apache License 2.0 6 votes vote down vote up
protected LukeModel(IndexReader reader) {
  this.reader = Objects.requireNonNull(reader);

  if (reader instanceof DirectoryReader) {
    DirectoryReader dr = (DirectoryReader) reader;
    this.dir = dr.directory();
    try {
      this.commit = dr.getIndexCommit();
    } catch (IOException e) {
      throw new LukeException(e.getMessage(), e);
    }
  } else {
    this.dir = null;
    this.commit = null;
  }

  this.liveDocs = IndexUtils.getLiveDocs(reader);
}
 
Example 2
Source Project: lucene-solr   File: LukeRequestHandler.java    License: Apache License 2.0 6 votes vote down vote up
public static SimpleOrderedMap<Object> getIndexInfo(DirectoryReader reader) throws IOException {
  Directory dir = reader.directory();
  SimpleOrderedMap<Object> indexInfo = new SimpleOrderedMap<>();

  indexInfo.add("numDocs", reader.numDocs());
  indexInfo.add("maxDoc", reader.maxDoc());
  indexInfo.add("deletedDocs", reader.maxDoc() - reader.numDocs());
  indexInfo.add("indexHeapUsageBytes", getIndexHeapUsed(reader));

  indexInfo.add("version", reader.getVersion());  // TODO? Is this different then: IndexReader.getCurrentVersion( dir )?
  indexInfo.add("segmentCount", reader.leaves().size());
  indexInfo.add("current", closeSafe( reader::isCurrent));
  indexInfo.add("hasDeletions", reader.hasDeletions() );
  indexInfo.add("directory", dir );
  IndexCommit indexCommit = reader.getIndexCommit();
  String segmentsFileName = indexCommit.getSegmentsFileName();
  indexInfo.add("segmentsFile", segmentsFileName);
  indexInfo.add("segmentsFileSizeInBytes", getSegmentsFileLength(indexCommit));
  Map<String,String> userData = indexCommit.getUserData();
  indexInfo.add("userData", userData);
  String s = userData.get(SolrIndexWriter.COMMIT_TIME_MSEC_KEY);
  if (s != null) {
    indexInfo.add("lastModified", new Date(Long.parseLong(s)));
  }
  return indexInfo;
}
 
Example 3
public void createSnapshot(String name, DirectoryReader reader, String context) throws IOException {
  _writeLock.lock();
  try {
    if (_namesToGenerations.containsKey(name)) {
      throw new IOException("Snapshot [" + name + "] already exists.");
    }
    LOG.info("Creating snapshot [{0}] in [{1}].", name, context);
    IndexCommit indexCommit = reader.getIndexCommit();
    long generation = indexCommit.getGeneration();
    _namesToGenerations.put(name, generation);
    Set<String> names = _generationsToNames.get(generation);
    if (names == null) {
      names = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());
      _generationsToNames.put(generation, names);
    }
    names.add(name);
    storeGenerations();
  } finally {
    _writeLock.unlock();
  }
}