Example usage for org.apache.lucene.util BitSetIterator getSparseFixedBitSetOrNull

List of usage examples for org.apache.lucene.util BitSetIterator getSparseFixedBitSetOrNull

Introduction

In this page you can find the example usage for org.apache.lucene.util BitSetIterator getSparseFixedBitSetOrNull.

Prototype

public static SparseFixedBitSet getSparseFixedBitSetOrNull(DocIdSetIterator iterator) 

Source Link

Document

If the provided iterator wraps a SparseFixedBitSet , returns it, otherwise returns null.

Usage

From source file:de.unihildesheim.iw.lucene.util.DocIdSetUtils.java

License:Open Source License

/**
 * Get the highest document id stored in the {@link DocIdSet}.
 *
 * @param dis DocIdSet//from ww  w .  j a  v a2 s. c  o  m
 * @return Highest document number or {@code -1}, if there's no document
 * @throws IOException Thrown on low-level i/o-errors
 */
public static int maxDoc(@NotNull final DocIdSet dis) throws IOException {
    final int maxDoc;

    @Nullable
    final DocIdSetIterator disi = dis.iterator();
    if (disi == null) {
        maxDoc = 0;
    } else {
        @Nullable
        BitSet bitSet;
        bitSet = BitSetIterator.getFixedBitSetOrNull(disi);
        if (bitSet == null) {
            bitSet = BitSetIterator.getSparseFixedBitSetOrNull(disi);
        }
        if (bitSet == null) {
            bitSet = BitsUtils.bits2BitSet(dis.bits());
        }

        if (bitSet == null) {
            maxDoc = StreamUtils.stream(dis).sorted().max().getAsInt();
        } else {
            if (bitSet.length() == 0) {
                maxDoc = -1;
            } else if (bitSet.length() == 1) {
                maxDoc = bitSet.get(0) ? 0 : -1;
            } else {
                maxDoc = bitSet.prevSetBit(bitSet.length() - 1);
            }
        }
    }
    return maxDoc;
}

From source file:de.unihildesheim.iw.lucene.util.DocIdSetUtils.java

License:Open Source License

/**
 * Get a bits instance from a DocIdSet./*from w  w w. ja va 2s.  com*/
 *
 * @param dis Set whose bits to get
 * @return Bits or null, if no bits are set
 * @throws IOException Thrown on low-level I/O-errors
 */
@Nullable
public static BitSet bits(@NotNull final DocIdSet dis) throws IOException {
    @Nullable
    final DocIdSetIterator disi = dis.iterator();

    if (disi == null) {
        return null;
    } else {
        @Nullable
        BitSet bitSet;

        bitSet = BitSetIterator.getFixedBitSetOrNull(disi);
        if (bitSet == null) {
            bitSet = BitSetIterator.getSparseFixedBitSetOrNull(disi);
        }
        if (bitSet == null) {
            bitSet = BitsUtils.bits2BitSet(dis.bits());
        }

        if (bitSet == null) {
            bitSet = new SparseFixedBitSet(maxDoc(dis) + 1);
            StreamUtils.stream(disi).forEach(bitSet::set);
        }
        return bitSet;
    }
}