public RandomAccessDocIdSet getRandomAccessDocIdSet(BoboSegmentReader reader) throws IOException {
@SuppressWarnings("unchecked")
final MultiValueFacetDataCache<String> dataCache = (MultiValueFacetDataCache<String>) _facetHandler
.getFacetData(reader);
final int[] index = _valueConverter.convert(dataCache, _vals);
final BigNestedIntArray nestedArray = dataCache._nestedArray;
final OpenBitSet bitset = new OpenBitSet(dataCache.valArray.size());
for (int i : index) {
bitset.fastSet(i);
}
if (_takeCompliment) {
// flip the bits
int size = dataCache.valArray.size();
for (int i = 0; i < size; ++i) {
bitset.fastFlip(i);
}
}
long count = bitset.cardinality();
if (count == 0) {
final DocIdSet empty = EmptyDocIdSet.getInstance();
return new RandomAccessDocIdSet() {
@Override
public boolean get(int docId) {
return false;
}
@Override
public DocIdSetIterator iterator() throws IOException {
return empty.iterator();
}
};
} else {
return new RandomAccessDocIdSet() {
@Override
public DocIdSetIterator iterator() {
return new MultiValueOrFacetDocIdSetIterator(dataCache, bitset);
}
@Override
final public boolean get(int docId) {
return nestedArray.contains(docId, bitset);
}
};
}
}