|
@@ -19,17 +19,11 @@
|
|
|
|
|
|
package org.elasticsearch.common.lucene.docset;
|
|
|
|
|
|
-import org.apache.lucene.index.LeafReader;
|
|
|
import org.apache.lucene.search.DocIdSet;
|
|
|
import org.apache.lucene.search.DocIdSetIterator;
|
|
|
import org.apache.lucene.search.Scorer;
|
|
|
import org.apache.lucene.search.TwoPhaseIterator;
|
|
|
-import org.apache.lucene.util.BitDocIdSet;
|
|
|
-import org.apache.lucene.util.BitSet;
|
|
|
import org.apache.lucene.util.Bits;
|
|
|
-import org.apache.lucene.util.RamUsageEstimator;
|
|
|
-import org.apache.lucene.util.RoaringDocIdSet;
|
|
|
-import org.apache.lucene.util.SparseFixedBitSet;
|
|
|
import org.elasticsearch.common.Nullable;
|
|
|
|
|
|
import java.io.IOException;
|
|
@@ -38,13 +32,6 @@ import java.io.IOException;
|
|
|
*/
|
|
|
public class DocIdSets {
|
|
|
|
|
|
- /**
|
|
|
- * Return the size of the doc id set, plus a reference to it.
|
|
|
- */
|
|
|
- public static long sizeInBytes(DocIdSet docIdSet) {
|
|
|
- return RamUsageEstimator.NUM_BYTES_OBJECT_REF + docIdSet.ramBytesUsed();
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Is it an empty {@link DocIdSet}?
|
|
|
*/
|
|
@@ -52,59 +39,6 @@ public class DocIdSets {
|
|
|
return set == null || set == DocIdSet.EMPTY;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Converts to a cacheable {@link DocIdSet}
|
|
|
- * <p/>
|
|
|
- * This never returns <code>null</code>.
|
|
|
- */
|
|
|
- public static DocIdSet toCacheable(LeafReader reader, @Nullable DocIdSet set) throws IOException {
|
|
|
- if (set == null || set == DocIdSet.EMPTY) {
|
|
|
- return DocIdSet.EMPTY;
|
|
|
- }
|
|
|
- final DocIdSetIterator it = set.iterator();
|
|
|
- if (it == null) {
|
|
|
- return DocIdSet.EMPTY;
|
|
|
- }
|
|
|
- final int firstDoc = it.nextDoc();
|
|
|
- if (firstDoc == DocIdSetIterator.NO_MORE_DOCS) {
|
|
|
- return DocIdSet.EMPTY;
|
|
|
- }
|
|
|
- if (set instanceof BitDocIdSet) {
|
|
|
- return set;
|
|
|
- }
|
|
|
-
|
|
|
- final RoaringDocIdSet.Builder builder = new RoaringDocIdSet.Builder(reader.maxDoc());
|
|
|
- builder.add(firstDoc);
|
|
|
- for (int doc = it.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = it.nextDoc()) {
|
|
|
- builder.add(doc);
|
|
|
- }
|
|
|
-
|
|
|
- return builder.build();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Get a build a {@link Bits} instance that will match all documents
|
|
|
- * contained in {@code set}. Note that this is a potentially heavy
|
|
|
- * operation as this might require to consume an iterator of this set
|
|
|
- * entirely and to load it into a {@link BitSet}. Prefer using
|
|
|
- * {@link #asSequentialAccessBits} if you only need to consume the
|
|
|
- * {@link Bits} once and in order.
|
|
|
- */
|
|
|
- public static Bits toSafeBits(int maxDoc, @Nullable DocIdSet set) throws IOException {
|
|
|
- if (set == null) {
|
|
|
- return new Bits.MatchNoBits(maxDoc);
|
|
|
- }
|
|
|
- Bits bits = set.bits();
|
|
|
- if (bits != null) {
|
|
|
- return bits;
|
|
|
- }
|
|
|
- DocIdSetIterator iterator = set.iterator();
|
|
|
- if (iterator == null) {
|
|
|
- return new Bits.MatchNoBits(maxDoc);
|
|
|
- }
|
|
|
- return toBitSet(iterator, maxDoc);
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Given a {@link Scorer}, return a {@link Bits} instance that will match
|
|
|
* all documents contained in the set. Note that the returned {@link Bits}
|
|
@@ -168,18 +102,4 @@ public class DocIdSets {
|
|
|
};
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Creates a {@link BitSet} from an iterator.
|
|
|
- */
|
|
|
- public static BitSet toBitSet(DocIdSetIterator iterator, int numBits) throws IOException {
|
|
|
- BitDocIdSet.Builder builder = new BitDocIdSet.Builder(numBits);
|
|
|
- builder.or(iterator);
|
|
|
- BitDocIdSet result = builder.build();
|
|
|
- if (result != null) {
|
|
|
- return result.bits();
|
|
|
- } else {
|
|
|
- return new SparseFixedBitSet(numBits);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
}
|