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

The following examples show how to use org.apache.lucene.index.DirectoryReader#directory() . 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 File: AlfrescoLukeRequestHandler.java    From SearchServices with GNU Lesser General Public License v3.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", reader.isCurrent());
	indexInfo.add("hasDeletions", reader.hasDeletions());
	indexInfo.add("directory", dir);
	indexInfo.add("userData", reader.getIndexCommit().getUserData());
	String s = reader.getIndexCommit().getUserData()
			.get(SolrIndexWriter.COMMIT_TIME_MSEC_KEY);
	if (s != null) {
		indexInfo.add("lastModified", new Date(Long.parseLong(s)));
	}
	return indexInfo;
}
 
Example 2
Source File: LukeModel.java    From lucene-solr with 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 3
Source File: LukeRequestHandler.java    From lucene-solr with 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 4
Source File: DirectUpdateHandlerTest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Test
public void testPrepareCommit() throws Exception {
  assertU(adoc("id", "999"));
  assertU(optimize("maxSegments", "1"));     // make sure there's just one segment
  assertU(commit());       // commit a second time to make sure index files aren't still referenced by the old searcher

  SolrQueryRequest sr = req();
  DirectoryReader r = sr.getSearcher().getIndexReader();
  Directory d = r.directory();

  if (log.isInfoEnabled()) {
    log.info("FILES before addDoc={}", Arrays.asList(d.listAll()));
  }
  assertU(adoc("id", "1"));

  int nFiles = d.listAll().length;
  if (log.isInfoEnabled()) {
    log.info("FILES before prepareCommit={}", Arrays.asList(d.listAll()));
  }

  updateJ("", params("prepareCommit", "true"));

  if (log.isInfoEnabled()) {
    log.info("FILES after prepareCommit={}", Arrays.asList(d.listAll()));
  }
  assertTrue( d.listAll().length > nFiles);  // make sure new index files were actually written
  
  assertJQ(req("q", "id:1")
      , "/response/numFound==0"
  );

  updateJ("", params("rollback","true"));
  assertU(commit());

  assertJQ(req("q", "id:1")
      , "/response/numFound==0"
  );

  assertU(adoc("id","1"));
  updateJ("", params("prepareCommit","true"));

  assertJQ(req("q", "id:1")
      , "/response/numFound==0"
  );

  assertU(commit());

  assertJQ(req("q", "id:1")
      , "/response/numFound==1"
  );

  sr.close();
}
 
Example 5
Source File: BlurInputFormatSplitCommand.java    From incubator-retired-blur with Apache License 2.0 4 votes vote down vote up
private Directory getDirectory(IndexReader indexReader) {
  DirectoryReader directoryReader = (DirectoryReader) indexReader;
  return directoryReader.directory();
}
 
Example 6
Source File: CommitsImpl.java    From lucene-solr with Apache License 2.0 2 votes vote down vote up
/**
 * Constructs a CommitsImpl that holds the {@link Directory} wrapped in the given {@link DirectoryReader}.
 *
 * @param reader - the index reader
 * @param indexPath - the path to index directory
 */
public CommitsImpl(DirectoryReader reader, String indexPath) {
  super(reader.directory());
  this.indexPath = indexPath;
  this.commitMap = initCommitMap();
}