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

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

Introduction

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

Prototype

public long getDocValuesGen() 

Source Link

Document

Returns the docValues generation of this field, or -1 if no docValues updates exist for it.

Usage

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

License:Open Source License

public static boolean equals(FieldInfo a, FieldInfo b) {
    return a.number == b.number && a.name.equals(b.name)
            && a.getPointDimensionCount() == b.getPointDimensionCount()
            && a.getPointNumBytes() == b.getPointNumBytes() && a.getDocValuesGen() == b.getDocValuesGen()
            && a.getIndexOptions() == b.getIndexOptions() && a.hasPayloads() == b.hasPayloads()
            && a.hasVectors() == b.hasVectors() && a.omitsNorms() == b.omitsNorms()
            && a.hasNorms() == b.hasNorms();
}

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  w  w w .java 2  s.c o  m*/
        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.apache.solr.uninverting.UninvertingReader.java

License:Apache License

/** 
 * Create a new UninvertingReader with the specified mapping 
 * <p>//from w  w w.jav  a  2  s .c o  m
 * Expert: This should almost never be used. Use {@link #wrap(DirectoryReader, Map)}
 * instead.
 *  
 * @lucene.internal
 */
public UninvertingReader(LeafReader in, Map<String, Type> mapping) {
    super(in);
    this.mapping = mapping;
    ArrayList<FieldInfo> filteredInfos = new ArrayList<>();
    for (FieldInfo fi : in.getFieldInfos()) {
        DocValuesType type = fi.getDocValuesType();
        if (type == DocValuesType.NONE) {
            Type t = mapping.get(fi.name);
            if (t != null) {
                if (t == Type.INTEGER_POINT || t == Type.LONG_POINT || t == Type.FLOAT_POINT
                        || t == Type.DOUBLE_POINT) {
                    // type uses points
                    if (fi.getPointDimensionCount() == 0) {
                        continue;
                    }
                } else {
                    // type uses inverted index
                    if (fi.getIndexOptions() == IndexOptions.NONE) {
                        continue;
                    }
                }
                switch (t) {
                case INTEGER_POINT:
                case LONG_POINT:
                case FLOAT_POINT:
                case DOUBLE_POINT:
                case LEGACY_INTEGER:
                case LEGACY_LONG:
                case LEGACY_FLOAT:
                case LEGACY_DOUBLE:
                    type = DocValuesType.NUMERIC;
                    break;
                case BINARY:
                    type = DocValuesType.BINARY;
                    break;
                case SORTED:
                    type = DocValuesType.SORTED;
                    break;
                case SORTED_SET_BINARY:
                case SORTED_SET_INTEGER:
                case SORTED_SET_FLOAT:
                case SORTED_SET_LONG:
                case SORTED_SET_DOUBLE:
                    type = DocValuesType.SORTED_SET;
                    break;
                default:
                    throw new AssertionError();
                }
            }
        }
        filteredInfos.add(new FieldInfo(fi.name, fi.number, fi.hasVectors(), fi.omitsNorms(), fi.hasPayloads(),
                fi.getIndexOptions(), type, fi.getDocValuesGen(), fi.attributes(), fi.getPointDimensionCount(),
                fi.getPointNumBytes()));
    }
    fieldInfos = new FieldInfos(filteredInfos.toArray(new FieldInfo[filteredInfos.size()]));
}

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

License:Apache License

/** Return an "upgraded" view of the reader. */
static AtomicReader filter(AtomicReader reader) throws IOException {
    final FieldInfos fieldInfos = reader.getFieldInfos();
    final FieldInfo versionInfo = fieldInfos.fieldInfo(VersionFieldMapper.NAME);
    if (versionInfo != null && versionInfo.hasDocValues()) {
        // the reader is a recent one, it has versions and they are stored
        // in a numeric doc values field
        return reader;
    }//from  www .j  av  a2s  .c  om
    // The segment is an old one, load all versions in memory and hide
    // them behind a numeric doc values field
    final Terms terms = reader.terms(UidFieldMapper.NAME);
    if (terms == null || !terms.hasPayloads()) {
        // The segment doesn't have an _uid field or doesn't have paylods
        // don't try to do anything clever. If any other segment has versions
        // all versions of this segment will be initialized to 0
        return reader;
    }
    final TermsEnum uids = terms.iterator(null);
    final GrowableWriter versions = new GrowableWriter(2, reader.maxDoc(), PackedInts.DEFAULT);
    DocsAndPositionsEnum dpe = null;
    for (BytesRef uid = uids.next(); uid != null; uid = uids.next()) {
        dpe = uids.docsAndPositions(reader.getLiveDocs(), dpe, DocsAndPositionsEnum.FLAG_PAYLOADS);
        assert dpe != null : "field has payloads";
        for (int doc = dpe.nextDoc(); doc != DocsEnum.NO_MORE_DOCS; doc = dpe.nextDoc()) {
            dpe.nextPosition();
            final BytesRef payload = dpe.getPayload();
            if (payload != null && payload.length == 8) {
                final long version = Numbers.bytesToLong(payload);
                versions.set(doc, version);
                break;
            }
        }
    }
    // Build new field infos, doc values, and return a filter reader
    final FieldInfo newVersionInfo;
    if (versionInfo == null) {
        // Find a free field number
        int fieldNumber = 0;
        for (FieldInfo fi : fieldInfos) {
            fieldNumber = Math.max(fieldNumber, fi.number + 1);
        }
        newVersionInfo = new FieldInfo(VersionFieldMapper.NAME, false, fieldNumber, false, true, false,
                IndexOptions.DOCS_ONLY, DocValuesType.NUMERIC, DocValuesType.NUMERIC, -1,
                Collections.<String, String>emptyMap());
    } else {
        newVersionInfo = new FieldInfo(VersionFieldMapper.NAME, versionInfo.isIndexed(), versionInfo.number,
                versionInfo.hasVectors(), versionInfo.omitsNorms(), versionInfo.hasPayloads(),
                versionInfo.getIndexOptions(), versionInfo.getDocValuesType(), versionInfo.getNormType(),
                versionInfo.getDocValuesGen(), versionInfo.attributes());
    }
    final ArrayList<FieldInfo> fieldInfoList = new ArrayList<>();
    for (FieldInfo info : fieldInfos) {
        if (info != versionInfo) {
            fieldInfoList.add(info);
        }
    }
    fieldInfoList.add(newVersionInfo);
    final FieldInfos newFieldInfos = new FieldInfos(fieldInfoList.toArray(new FieldInfo[fieldInfoList.size()]));
    final NumericDocValues versionValues = new NumericDocValues() {
        @Override
        public long get(int index) {
            return versions.get(index);
        }
    };
    return new FilterAtomicReader(reader) {
        @Override
        public FieldInfos getFieldInfos() {
            return newFieldInfos;
        }

        @Override
        public NumericDocValues getNumericDocValues(String field) throws IOException {
            if (VersionFieldMapper.NAME.equals(field)) {
                return versionValues;
            }
            return super.getNumericDocValues(field);
        }

        @Override
        public Bits getDocsWithField(String field) throws IOException {
            return new Bits.MatchAllBits(in.maxDoc());
        }
    };
}