Example usage for org.apache.lucene.util BitSet length

List of usage examples for org.apache.lucene.util BitSet length

Introduction

In this page you can find the example usage for org.apache.lucene.util BitSet length.

Prototype

int length();

Source Link

Document

Returns the number of bits in this set

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/* ww  w  .j a  v  a 2 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:org.elasticsearch.index.search.child.AbstractChildTestCase.java

License:Apache License

static boolean equals(BitDocIdSet expected, BitDocIdSet actual) {
    if (actual == null && expected == null) {
        return true;
    } else if (actual == null || expected == null) {
        return false;
    }/*from w  w  w.  ja va2  s  . c om*/
    BitSet actualBits = actual.bits();
    BitSet expectedBits = expected.bits();
    if (actualBits.length() != expectedBits.length()) {
        return false;
    }
    for (int i = 0; i < expectedBits.length(); i++) {
        if (expectedBits.get(i) != actualBits.get(i)) {
            return false;
        }
    }
    return true;
}

From source file:org.elasticsearch.index.shard.ShardSplittingQuery.java

License:Apache License

private void markChildDocs(BitSet parentDocs, BitSet matchingDocs) {
    int currentDeleted = 0;
    while (currentDeleted < matchingDocs.length()
            && (currentDeleted = matchingDocs.nextSetBit(currentDeleted)) != DocIdSetIterator.NO_MORE_DOCS) {
        int previousParent = parentDocs.prevSetBit(Math.max(0, currentDeleted - 1));
        for (int i = previousParent + 1; i < currentDeleted; i++) {
            matchingDocs.set(i);/*from   w  w  w.j a v a 2  s . c o  m*/
        }
        currentDeleted++;
    }
}