Example usage for org.apache.lucene.util.fst BytesRefFSTEnum next

List of usage examples for org.apache.lucene.util.fst BytesRefFSTEnum next

Introduction

In this page you can find the example usage for org.apache.lucene.util.fst BytesRefFSTEnum next.

Prototype

public InputOutput<T> next() throws IOException 

Source Link

Usage

From source file:org.elasticsearch.index.fielddata.plain.FSTBytesAtomicFieldData.java

License:Apache License

@Override
public BytesValues.WithOrdinals getBytesValues(boolean needsHashes) {
    assert fst != null;
    if (needsHashes) {
        if (hashes == null) {
            BytesRefFSTEnum<Long> fstEnum = new BytesRefFSTEnum<Long>(fst);
            IntArray hashes = BigArrays.newIntArray(ordinals.getMaxOrd());
            // we don't store an ord 0 in the FST since we could have an empty string in there and FST don't support
            // empty strings twice. ie. them merge fails for long output.
            hashes.set(0, new BytesRef().hashCode());
            try {
                for (long i = 1, maxOrd = ordinals.getMaxOrd(); i < maxOrd; ++i) {
                    hashes.set(i, fstEnum.next().input.hashCode());
                }//from ww w . j  a va  2s.  c  o m
                assert fstEnum.next() == null;
            } catch (IOException e) {
                // Don't use new "AssertionError("Cannot happen", e)" directly as this is a Java 1.7-only API
                final AssertionError error = new AssertionError("Cannot happen");
                error.initCause(e);
                throw error;
            }
            this.hashes = hashes;
        }
        return new HashedBytesValues(fst, ordinals.ordinals(), hashes);
    } else {
        return new BytesValues(fst, ordinals.ordinals());
    }
}