Java Code Examples for org.apache.lucene.codecs.Codec#forName()
The following examples show how to use
org.apache.lucene.codecs.Codec#forName() .
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: SegmentInfos.java From lucene-solr with Apache License 2.0 | 5 votes |
private static Codec readCodec(DataInput input) throws IOException { final String name = input.readString(); try { return Codec.forName(name); } catch (IllegalArgumentException e) { // maybe it's an old default codec that moved if (name.startsWith("Lucene")) { throw new IllegalArgumentException("Could not load codec '" + name + "'. Did you forget to add lucene-backward-codecs.jar?", e); } throw e; } }
Example 2
Source File: TestLucene70SegmentInfoFormat.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override protected Codec getCodec() { return new FilterCodec("Lucene84", Codec.forName("Lucene84")) { @Override public SegmentInfoFormat segmentInfoFormat() { return new Lucene70RWSegmentInfoFormat(); } }; }
Example 3
Source File: Test2BPoints.java From lucene-solr with Apache License 2.0 | 4 votes |
private static Codec getCodec() { return Codec.forName("Lucene84"); }
Example 4
Source File: TestDuelingCodecs.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override public void setUp() throws Exception { super.setUp(); // for now it's SimpleText vs Default(random postings format) // as this gives the best overall coverage. when we have more // codecs we should probably pick 2 from Codec.availableCodecs() leftCodec = Codec.forName("SimpleText"); rightCodec = new RandomCodec(random()); leftDir = newFSDirectory(createTempDir("leftDir")); rightDir = newFSDirectory(createTempDir("rightDir")); seed = random().nextLong(); // must use same seed because of random payloads, etc int maxTermLength = TestUtil.nextInt(random(), 1, IndexWriter.MAX_TERM_LENGTH); MockAnalyzer leftAnalyzer = new MockAnalyzer(new Random(seed)); leftAnalyzer.setMaxTokenLength(maxTermLength); MockAnalyzer rightAnalyzer = new MockAnalyzer(new Random(seed)); rightAnalyzer.setMaxTokenLength(maxTermLength); // but these can be different // TODO: this turns this into a really big test of Multi*, is that what we want? IndexWriterConfig leftConfig = newIndexWriterConfig(leftAnalyzer); leftConfig.setCodec(leftCodec); // preserve docids leftConfig.setMergePolicy(newLogMergePolicy()); IndexWriterConfig rightConfig = newIndexWriterConfig(rightAnalyzer); rightConfig.setCodec(rightCodec); // preserve docids rightConfig.setMergePolicy(newLogMergePolicy()); // must use same seed because of random docvalues fields, etc leftWriter = new RandomIndexWriter(new Random(seed), leftDir, leftConfig); rightWriter = new RandomIndexWriter(new Random(seed), rightDir, rightConfig); info = "left: " + leftCodec.toString() + " / right: " + rightCodec.toString(); }
Example 5
Source File: TestNamedSPILoader.java From lucene-solr with Apache License 2.0 | 4 votes |
public void testLookup() { String currentName = TestUtil.getDefaultCodec().getName(); Codec codec = Codec.forName(currentName); assertEquals(currentName, codec.getName()); }
Example 6
Source File: GenericRecordReader.java From incubator-retired-blur with Apache License 2.0 | 4 votes |
private SegmentInfoPerCommit segmentInfosRead(Directory directory, String segmentFileName, String segmentInfoName) throws IOException { boolean success = false; ChecksumIndexInput input = new ChecksumIndexInput(directory.openInput(segmentFileName, IOContext.READ)); try { 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(); } } }