Apache Lucene open-source search software
merge trunk
Robert Muir533249e67d24
diff --cc lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50FieldInfosFormat.javaindex d7dc30fc8c2,77295b6168a..555ce32ecd1--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50FieldInfosFormat.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50FieldInfosFormat.java@@@ -46,10 -46,10 +46,10 @@@ import org.apache.lucene.store.IndexOut* FieldBits,DocValuesBits,DocValuesGen,Attributes> <sup>FieldsCount</sup>,Footer</p>* <p>Data types:* <ul>- * <li>Header --> {@link CodecUtil#checkSegmentHeader SegmentHeader}</li>+ * <li>Header --> {@link CodecUtil#checkIndexHeader IndexHeader}</li>* <li>FieldsCount --> {@link DataOutput#writeVInt VInt}</li>* <li>FieldName --> {@link DataOutput#writeString String}</li>- * <li>FieldBits, DocValuesBits --> {@link DataOutput#writeByte Byte}</li>+ * <li>FieldBits, IndexOptions, DocValuesBits --> {@link DataOutput#writeByte Byte}</li>* <li>FieldNumber --> {@link DataOutput#writeInt VInt}</li>* <li>Attributes --> {@link DataOutput#writeStringStringMap Map<String,String>}</li>* <li>DocValuesGen --> {@link DataOutput#writeLong(long) Int64}</li>@@@ -186,11 -203,55 +203,55 @@@ public final class Lucene50FieldInfosFo}}+ static {+ // We "mirror" IndexOptions enum values with the constants below; let's try to ensure if we add a new IndexOption while this format is+ // still used for writing, we remember to fix this encoding:+ assert IndexOptions.values().length == 4;+ }++ private static byte indexOptionsByte(IndexOptions indexOptions) {+ if (indexOptions == null) {+ return 0;+ } else {+ switch (indexOptions) {+ case DOCS_ONLY:+ return 1;+ case DOCS_AND_FREQS:+ return 2;+ case DOCS_AND_FREQS_AND_POSITIONS:+ return 3;+ case DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS:+ return 4;+ default:+ // BUG:+ throw new AssertionError("unhandled IndexOptions: " + indexOptions);+ }+ }+ }++ private static IndexOptions getIndexOptions(IndexInput input, byte b) throws IOException {+ switch (b) {+ case 0:+ return null;+ case 1:+ return IndexOptions.DOCS_ONLY;+ case 2:+ return IndexOptions.DOCS_AND_FREQS;+ case 3:+ return IndexOptions.DOCS_AND_FREQS_AND_POSITIONS;+ case 4:+ return IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS;+ default:+ // BUG+ throw new CorruptIndexException("invalid IndexOptions byte: " + b, input);+ }+ }+@Overridepublic void write(Directory directory, SegmentInfo segmentInfo, String segmentSuffix, FieldInfos infos, IOContext context) throws IOException {- final String fileName = IndexFileNames.segmentFileName(segmentInfo.name, segmentSuffix, Lucene50FieldInfosFormat.EXTENSION);+ final String fileName = IndexFileNames.segmentFileName(segmentInfo.name, segmentSuffix, EXTENSION);try (IndexOutput output = directory.createOutput(fileName, context)) {- CodecUtil.writeSegmentHeader(output, CODEC_NAME, FORMAT_CURRENT, segmentInfo.getId(), segmentSuffix);+ CodecUtil.writeIndexHeader(output, Lucene50FieldInfosFormat.CODEC_NAME, Lucene50FieldInfosFormat.FORMAT_CURRENT, segmentInfo.getId(), segmentSuffix);output.writeVInt(infos.size());for (FieldInfo fi : infos) {fi.checkConsistency();