Optimize conversion to a cacheable DocIdSet

This commit is contained in:
Igor Motov 2013-02-13 21:04:54 -05:00
parent 883c593d7e
commit 6b49457d9d
1 changed files with 9 additions and 4 deletions

View File

@ -82,7 +82,12 @@ public class DocIdSets {
if (set instanceof FixedBitSet) {
return set;
}
return toFixedBitSet(set.iterator(), reader.maxDoc());
FixedBitSet fixedBitSet = new FixedBitSet(reader.maxDoc());
do {
fixedBitSet.set(doc);
doc = it.nextDoc();
} while (doc != DocIdSetIterator.NO_MORE_DOCS);
return fixedBitSet;
}
/**
@ -100,16 +105,16 @@ public class DocIdSets {
if (iterator == null) {
return new Bits.MatchNoBits(reader.maxDoc());
}
return new FixedBitSet(toFixedBitSet(iterator, reader.maxDoc()));
return toFixedBitSet(iterator, reader.maxDoc());
}
/**
* Creates a {@link FixedBitSet} from an iterator.
*/
public static FixedBitSet toFixedBitSet(DocIdSetIterator iteartor, int numBits) throws IOException {
public static FixedBitSet toFixedBitSet(DocIdSetIterator iterator, int numBits) throws IOException {
FixedBitSet set = new FixedBitSet(numBits);
int doc;
while ((doc = iteartor.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
while ((doc = iterator.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
set.set(doc);
}
return set;