Example usage for org.apache.lucene.codecs.lucene70 Lucene70DocValuesFormat Lucene70DocValuesFormat

List of usage examples for org.apache.lucene.codecs.lucene70 Lucene70DocValuesFormat Lucene70DocValuesFormat

Introduction

In this page you can find the example usage for org.apache.lucene.codecs.lucene70 Lucene70DocValuesFormat Lucene70DocValuesFormat.

Prototype

public Lucene70DocValuesFormat() 

Source Link

Document

Sole Constructor

Usage

From source file:perf.DiskUsage.java

License:Apache License

public static void main(String args[]) throws Exception {
    if (args.length != 1) {
        System.err.println(//from  ww w  . j a v  a2s .  c o  m
                "java [-Djava.io.tmpdir=/scratch] [-Dmode=BEST_COMPRESSION] -cp lucene-core.jar:./build DiskUsage <path to lucene index>");
        System.exit(1);
    }

    IndexWriterConfig conf = new IndexWriterConfig(null);
    conf.setOpenMode(OpenMode.CREATE);
    // force codec to write per-field filenames.
    conf.setCodec(new Lucene70Codec(Mode.valueOf(System.getProperty("mode", "BEST_SPEED"))) {
        @Override
        public PostingsFormat getPostingsFormatForField(String field) {
            return new Lucene50PostingsFormat();
        }

        @Override
        public DocValuesFormat getDocValuesFormatForField(String field) {
            return new Lucene70DocValuesFormat();
        }
    });

    Path tmp = Files.createTempDirectory(null);
    System.err.println("analyzing... (using " + tmp + " for temporary storage)");

    try (Directory dir = FSDirectory.open(Paths.get(args[0]));
            DirectoryReader reader = DirectoryReader.open(dir);
            Directory scratch = FSDirectory.open(tmp);
            IndexWriter writer = new IndexWriter(scratch, conf)) {

        CodecReader inputs[] = new CodecReader[reader.leaves().size()];
        for (int i = 0; i < inputs.length; i++) {
            inputs[i] = (CodecReader) reader.leaves().get(i).reader();
        }
        writer.addIndexes(inputs);

        try (DirectoryReader newReader = DirectoryReader.open(writer)) {
            assert newReader.leaves().size() == 1;
            SegmentReader sr = (SegmentReader) newReader.leaves().get(0).reader();
            report(sr, analyzeFields(sr));
        }
    } finally {
        IOUtils.rm(tmp);
    }
}