Example usage for org.apache.lucene.codecs Codec forName

List of usage examples for org.apache.lucene.codecs Codec forName

Introduction

In this page you can find the example usage for org.apache.lucene.codecs Codec forName.

Prototype

public static Codec forName(String name) 

Source Link

Document

looks up a codec by name

Usage

From source file:com.rocana.lucene.codec.v1.TestRocanaSearchCodecV1.java

License:Apache License

/**
 * This test ensures we registered our codec properly in the SPI file:
 * META-INF/services/org.apache.lucene.codecs.Codec
 *//*from  www .ja  va 2s .  c  om*/
@Test
public void validateJavaServiceProviderConfigFile() throws Exception {
    Codec codec = Codec.forName(RocanaSearchCodecV1.SHORT_NAME);

    Assert.assertEquals("Expected the Rocana codec", RocanaSearchCodecV1.class, codec.getClass());
}

From source file:net.semanticmetadata.lire.imageanalysis.OpponentHistogramTest.java

License:Open Source License

public void testFastSearch() throws IOException {
    Codec.forName("LireCustomCodec");
    //        ParallelIndexer pin = new ParallelIndexer(7, "./index-fast-3", "testdata/wang-1000") {
    ParallelIndexer pin = new ParallelIndexer(7, "./index-fast-3", "D:\\DataSets\\Flickrphotos\\01", true) {
        @Override/*from  w w  w.j  a v a  2  s  .c  o m*/
        public void addBuilders(ChainedDocumentBuilder builder) {
            builder.addBuilder(DocumentBuilderFactory.getOpponentHistogramDocumentBuilder());
        }
    };
    pin.run();
    IndexReader ir = DirectoryReader.open(MMapDirectory.open(new File("./index-fast-3")));
    System.out.println("ir.maxDoc() = " + ir.maxDoc());

    long ms = System.currentTimeMillis();
    ImageSearcher is = new FastOpponentImageSearcher(50);
    ms = System.currentTimeMillis() - ms;
    System.out.println("init ms = " + ms);

    ms = System.currentTimeMillis();
    for (int i = 0; i < 100; i++)
        is.search(ir.document(i), ir);
    ms = System.currentTimeMillis() - ms;
    System.out.println("cached ms = " + ms);

    is = ImageSearcherFactory.createOpponentHistogramSearcher(50);
    ms = System.currentTimeMillis();
    for (int i = 0; i < 100; i++)
        is.search(ir.document(i), ir);
    ms = System.currentTimeMillis() - ms;
    System.out.println("read from Lucene ms = " + ms);
}

From source file:org.apache.blur.mapreduce.lib.GenericRecordReader.java

License:Apache License

private SegmentInfoPerCommit segmentInfosRead(Directory directory, String segmentFileName,
        String segmentInfoName) throws IOException {
    boolean success = false;

    ChecksumIndexInput input = new ChecksumIndexInput(directory.openInput(segmentFileName, IOContext.READ));
    try {// w ww .  j av a  2 s .  c o  m
        final int format = input.readInt();
        if (format == CodecUtil.CODEC_MAGIC) {
            // 4.0+
            CodecUtil.checkHeaderNoMagic(input, "segments", SegmentInfos.VERSION_40, SegmentInfos.VERSION_40);
            input.readLong();// read version
            input.readInt(); // read counter
            int numSegments = input.readInt();
            if (numSegments < 0) {
                throw new CorruptIndexException(
                        "invalid segment count: " + numSegments + " (resource: " + input + ")");
            }
            for (int seg = 0; seg < numSegments; seg++) {
                String segName = input.readString();
                Codec codec = Codec.forName(input.readString());
                SegmentInfo info = codec.segmentInfoFormat().getSegmentInfoReader().read(directory, segName,
                        IOContext.READ);
                info.setCodec(codec);
                long delGen = input.readLong();
                int delCount = input.readInt();
                if (delCount < 0 || delCount > info.getDocCount()) {
                    throw new CorruptIndexException(
                            "invalid deletion count: " + delCount + " (resource: " + input + ")");
                }
                if (segName.equals(segmentInfoName)) {
                    success = true;
                    return new SegmentInfoPerCommit(info, delCount, delGen);
                }
            }
        } else {
            throw new IOException("Legacy Infos not supported for dir [" + directory + "].");
        }
        throw new IOException("Segment [" + segmentInfoName + "] nout found in dir [" + directory + "]");
    } finally {
        if (!success) {
            IOUtils.closeWhileHandlingException(input);
        } else {
            input.close();
        }
    }
}

From source file:org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition.java

License:Apache License

private Codec createCodec() {
    String codecName = getOptionalValue(definition, LuceneIndexConstants.CODEC_NAME, null);
    Codec codec = null;//w w w.  ja v  a  2s  . c o m
    if (codecName != null) {
        // prevent LUCENE-6482
        // (also done in LuceneIndexProviderService, just to be save)
        OakCodec ensureLucene46CodecLoaded = new OakCodec();
        // to ensure the JVM doesn't optimize away object creation
        // (probably not really needed; just to be save)
        log.debug("Lucene46Codec is loaded: {}", ensureLucene46CodecLoaded);
        codec = Codec.forName(codecName);
        log.debug("Codec is loaded: {}", codecName);
    } else if (fullTextEnabled) {
        codec = new OakCodec();
    }
    return codec;
}

From source file:org.elasticsearch.index.codec.CodecService.java

License:Apache License

@Inject
public CodecService(Index index, @IndexSettings Settings indexSettings,
        PostingsFormatService postingsFormatService, DocValuesFormatService docValuesFormatService,
        MapperService mapperService) {//from w  w  w .  j  a  va 2  s . c o m
    super(index, indexSettings);
    this.postingsFormatService = postingsFormatService;
    this.docValuesFormatService = docValuesFormatService;
    this.mapperService = mapperService;
    MapBuilder<String, Codec> codecs = MapBuilder.<String, Codec>newMapBuilder();
    if (mapperService == null) {
        codecs.put(DEFAULT_CODEC, Codec.getDefault());
    } else {
        codecs.put(DEFAULT_CODEC,
                new PerFieldMappingPostingFormatCodec(mapperService,
                        postingsFormatService.get(PostingsFormatService.DEFAULT_FORMAT).get(),
                        docValuesFormatService.get(DocValuesFormatService.DEFAULT_FORMAT).get(), logger));
    }
    for (String codec : Codec.availableCodecs()) {
        codecs.put(codec, Codec.forName(codec));
    }
    this.codecs = codecs.immutableMap();
    this.loadBloomFilter = indexSettings.getAsBoolean(INDEX_CODEC_BLOOM_LOAD, INDEX_CODEC_BLOOM_LOAD_DEFAULT);
}

From source file:org.modeshape.jcr.index.lucene.LuceneConfig.java

License:Apache License

private Codec codec(String name) {
    return StringUtil.isBlank(name) ? Codec.getDefault() : Codec.forName(name);
}

From source file:perf.IndexAndSearchOpenStreetMaps.java

License:Apache License

private static Codec getCodec(boolean fast) {
    if (fast) {/*from w  w w.  ja v  a 2  s  . c  o  m*/
        return new FilterCodec("Lucene62", Codec.getDefault()) {
            @Override
            public PointsFormat pointsFormat() {
                return new PointsFormat() {
                    @Override
                    public PointsWriter fieldsWriter(SegmentWriteState writeState) throws IOException {
                        int maxPointsInLeafNode = 1024;
                        return new Lucene60PointsWriter(writeState, maxPointsInLeafNode,
                                BKDWriter.DEFAULT_MAX_MB_SORT_IN_HEAP);
                    }

                    @Override
                    public PointsReader fieldsReader(SegmentReadState readState) throws IOException {
                        return new Lucene60PointsReader(readState);
                    }
                };
            }
        };
    } else {
        return Codec.forName("Lucene62");
    }
}