From 6b49457d9db6bdff0bd61fd79d65345fc2187f7c Mon Sep 17 00:00:00 2001 From: Igor Motov Date: Wed, 13 Feb 2013 21:04:54 -0500 Subject: [PATCH] Optimize conversion to a cacheable DocIdSet --- .../common/lucene/docset/DocIdSets.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/elasticsearch/common/lucene/docset/DocIdSets.java b/src/main/java/org/elasticsearch/common/lucene/docset/DocIdSets.java index d404965dbba..6d857d1e1c1 100644 --- a/src/main/java/org/elasticsearch/common/lucene/docset/DocIdSets.java +++ b/src/main/java/org/elasticsearch/common/lucene/docset/DocIdSets.java @@ -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;