Example usage for org.apache.lucene.index IndexCommit getDirectory

List of usage examples for org.apache.lucene.index IndexCommit getDirectory

Introduction

In this page you can find the example usage for org.apache.lucene.index IndexCommit getDirectory.

Prototype

public abstract Directory getDirectory();

Source Link

Document

Returns the Directory for the index.

Usage

From source file:com.liferay.portal.search.lucene.dump.IndexCommitMetaInfo.java

License:Open Source License

public IndexCommitMetaInfo(IndexCommit indexCommit) throws IOException {
    if (indexCommit == null) {
        _empty = true;// w  w  w. j  a va  2  s .  co m

        return;
    }

    List<String> fileNames = new ArrayList<String>(indexCommit.getFileNames());

    _segments = new ArrayList<Segment>(fileNames.size());

    Directory directory = indexCommit.getDirectory();

    for (String fileName : fileNames) {
        Segment segment = new Segment(fileName, directory.fileLength(fileName));

        _segments.add(segment);
    }

    _generation = indexCommit.getGeneration();
}

From source file:com.liferay.portal.search.lucene.dump.IndexCommitSerializationUtil.java

License:Open Source License

public static void serializeIndex(IndexCommit indexCommit, OutputStream outputStream) throws IOException {

    if (PropsValues.INDEX_DUMP_COMPRESSION_ENABLED) {
        outputStream = new GZIPOutputStream(outputStream);
    }//from   w w w . j  a v a2  s .c o  m

    ObjectOutputStream objectOputStream = new ObjectOutputStream(outputStream);

    IndexCommitMetaInfo indexCommitMetaInfo = new IndexCommitMetaInfo(indexCommit);

    if (_log.isDebugEnabled()) {
        _log.debug("Serializing " + indexCommitMetaInfo);
    }

    objectOputStream.writeObject(indexCommitMetaInfo);

    List<Segment> segments = indexCommitMetaInfo.getSegments();

    Directory directory = indexCommit.getDirectory();

    for (Segment segment : segments) {
        if (_log.isDebugEnabled()) {
            _log.debug("Serializing segment " + segment);
        }

        serializeSegment(directory.openInput(segment.getFileName()), segment.getFileSize(), objectOputStream);
    }

    objectOputStream.flush();

    if (PropsValues.INDEX_DUMP_COMPRESSION_ENABLED) {
        GZIPOutputStream gZipOutputStream = (GZIPOutputStream) outputStream;

        gZipOutputStream.finish();
    }
}

From source file:com.vmware.xenon.services.common.LuceneDocumentIndexBackupService.java

License:Open Source License

private void copyInMemoryLuceneIndexToDirectory(IndexCommit commit, Path directoryPath) throws IOException {
    Directory from = commit.getDirectory();
    try (Directory to = new NIOFSDirectory(directoryPath)) {
        for (String filename : commit.getFileNames()) {
            to.copyFrom(from, filename, filename, IOContext.DEFAULT);
        }//from w  w w  .ja va  2 s  .  c  o m
    }
}

From source file:org.apache.solr.core.SolrDeletionPolicy.java

License:Apache License

private String getId(IndexCommit commit) {
    StringBuilder sb = new StringBuilder();
    Directory dir = commit.getDirectory();

    // For anything persistent, make something that will
    // be the same, regardless of the Directory instance.
    if (dir instanceof FSDirectory) {
        FSDirectory fsd = (FSDirectory) dir;
        File fdir = fsd.getDirectory();
        sb.append(fdir.getPath());/*w w  w  .  ja  v  a  2  s  . c o  m*/
    } else {
        sb.append(dir);
    }

    sb.append('/');
    sb.append(commit.getGeneration());
    return sb.toString();
}

From source file:org.codelibs.elasticsearch.common.lucene.Lucene.java

License:Apache License

/**
 * Reads the segments infos from the given commit, failing if it fails to load
 *///from   w ww  .j  a v  a  2 s .  c om
public static SegmentInfos readSegmentInfos(IndexCommit commit) throws IOException {
    // Using commit.getSegmentsFileName() does NOT work here, have to
    // manually create the segment filename
    String filename = IndexFileNames.fileNameFromGeneration(IndexFileNames.SEGMENTS, "",
            commit.getGeneration());
    return SegmentInfos.readCommit(commit.getDirectory(), filename);
}