Example usage for org.apache.lucene.index FieldInfo checkConsistency

List of usage examples for org.apache.lucene.index FieldInfo checkConsistency

Introduction

In this page you can find the example usage for org.apache.lucene.index FieldInfo checkConsistency.

Prototype

public boolean checkConsistency() 

Source Link

Document

Performs internal consistency checks.

Usage

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

License:Open Source License

@Override
public void write(Directory directory, SegmentInfo segmentInfo, String segmentSuffix, FieldInfos infos,
        IOContext context) throws IOException {
    final String fileName = IndexFileNames.segmentFileName(segmentInfo.name, segmentSuffix, EXTENSION);
    try (IndexOutput output = directory.createOutput(fileName, context)) {
        CodecUtil.writeIndexHeader(output, Lucene60FieldInfosFormatWithCache.CODEC_NAME,
                Lucene60FieldInfosFormatWithCache.FORMAT_CURRENT, segmentInfo.getId(), segmentSuffix);
        output.writeVInt(infos.size());//from  www  . j a v  a  2s  . c om
        for (FieldInfo fi : infos) {
            fi.checkConsistency();

            output.writeString(fi.name);
            output.writeVInt(fi.number);

            byte bits = 0x0;
            if (fi.hasVectors()) {
                bits |= STORE_TERMVECTOR;
            }
            if (fi.omitsNorms()) {
                bits |= OMIT_NORMS;
            }
            if (fi.hasPayloads()) {
                bits |= STORE_PAYLOADS;
            }
            output.writeByte(bits);

            output.writeByte(indexOptionsByte(fi.getIndexOptions()));

            // pack the DV type and hasNorms in one byte
            output.writeByte(docValuesByte(fi.getDocValuesType()));
            output.writeLong(fi.getDocValuesGen());
            output.writeMapOfStrings(fi.attributes());
            int pointDimensionCount = fi.getPointDimensionCount();
            output.writeVInt(pointDimensionCount);
            if (pointDimensionCount != 0) {
                output.writeVInt(fi.getPointNumBytes());
            }
        }
        CodecUtil.writeFooter(output);
    }
}

From source file:org.elasticsearch.index.merge.policy.VersionFieldUpgrader.java

License:Apache License

VersionFieldUpgrader(CodecReader in) {
    super(in);// w  ww  . j  a  v  a2 s  .  c o  m

    // Find a free field number
    int fieldNumber = 0;
    for (FieldInfo fi : in.getFieldInfos()) {
        fieldNumber = Math.max(fieldNumber, fi.number + 1);
    }

    // TODO: lots of things can wrong here...
    FieldInfo newInfo = new FieldInfo(VersionFieldMapper.NAME, // field name
            fieldNumber, // field number
            false, // store term vectors
            false, // omit norms
            false, // store payloads
            IndexOptions.NONE, // index options
            DocValuesType.NUMERIC, // docvalues
            -1, // docvalues generation
            Collections.<String, String>emptyMap() // attributes
    );
    newInfo.checkConsistency(); // fail merge immediately if above code is wrong

    final ArrayList<FieldInfo> fieldInfoList = new ArrayList<>();
    for (FieldInfo info : in.getFieldInfos()) {
        if (!info.name.equals(VersionFieldMapper.NAME)) {
            fieldInfoList.add(info);
        }
    }
    fieldInfoList.add(newInfo);
    infos = new FieldInfos(fieldInfoList.toArray(new FieldInfo[fieldInfoList.size()]));
}