diff --git a/lucene/core/src/java/org/apache/lucene/search/DocValuesDocIdSet.java b/lucene/core/src/java/org/apache/lucene/search/DocValuesDocIdSet.java index 21489e260aa..591bdfc6786 100644 --- a/lucene/core/src/java/org/apache/lucene/search/DocValuesDocIdSet.java +++ b/lucene/core/src/java/org/apache/lucene/search/DocValuesDocIdSet.java @@ -19,6 +19,7 @@ package org.apache.lucene.search; import java.io.IOException; import org.apache.lucene.util.Bits; +import org.apache.lucene.util.FixedBitDocIdSet; import org.apache.lucene.util.FixedBitSet; /** @@ -116,7 +117,7 @@ public abstract class DocValuesDocIdSet extends DocIdSet { } else if (acceptDocs instanceof FixedBitSet) { // special case for FixedBitSet: use the iterator and filter it // (used e.g. when Filters are chained by FilteredQuery) - return new FilteredDocIdSetIterator(((DocIdSet) acceptDocs).iterator()) { + return new FilteredDocIdSetIterator(new FixedBitDocIdSet((FixedBitSet) acceptDocs).iterator()) { @Override protected boolean match(int doc) { return DocValuesDocIdSet.this.matchDoc(doc); diff --git a/lucene/core/src/java/org/apache/lucene/search/SloppyPhraseScorer.java b/lucene/core/src/java/org/apache/lucene/search/SloppyPhraseScorer.java index 986ab066ccb..c5a4f70dfe1 100644 --- a/lucene/core/src/java/org/apache/lucene/search/SloppyPhraseScorer.java +++ b/lucene/core/src/java/org/apache/lucene/search/SloppyPhraseScorer.java @@ -510,9 +510,8 @@ final class SloppyPhraseScorer extends Scorer { HashMap tg = new HashMap<>(); Term[] t = tord.keySet().toArray(new Term[0]); for (int i=0; i= bits.length() ? -1 : bits.nextSetBit(ord + 1)) { tg.put(t[ord],i); } } diff --git a/lucene/core/src/java/org/apache/lucene/util/DocIdSetBuilder.java b/lucene/core/src/java/org/apache/lucene/util/DocIdSetBuilder.java index 45a881e783a..f181a24ffdf 100644 --- a/lucene/core/src/java/org/apache/lucene/util/DocIdSetBuilder.java +++ b/lucene/core/src/java/org/apache/lucene/util/DocIdSetBuilder.java @@ -21,6 +21,7 @@ import java.io.IOException; import org.apache.lucene.search.DocIdSet; import org.apache.lucene.search.DocIdSetIterator; +import org.apache.lucene.util.SparseFixedBitSet.SparseFixedBitSetIterator; /** * A builder of {@link DocIdSet}s that supports random access. @@ -63,7 +64,7 @@ public final class DocIdSetBuilder { denseSet = new FixedBitSet(maxDoc); denseSet.or(it); if (sparseSet != null) { - denseSet.or(sparseSet.iterator()); + denseSet.or(new SparseFixedBitSetIterator(sparseSet, 0L)); } return; } @@ -84,7 +85,14 @@ public final class DocIdSetBuilder { * anymore after this method has been called. */ public DocIdSet build() { - final DocIdSet result = denseSet != null ? denseSet : sparseSet; + final DocIdSet result; + if (denseSet != null) { + result = new FixedBitDocIdSet(denseSet, denseSet.cardinality()); + } else if (sparseSet != null) { + result = new SparseFixedBitDocIdSet(sparseSet, sparseSet.approximateCardinality()); + } else { + result = null; + } denseSet = null; sparseSet = null; costUpperBound = 0; diff --git a/lucene/core/src/java/org/apache/lucene/util/FixedBitDocIdSet.java b/lucene/core/src/java/org/apache/lucene/util/FixedBitDocIdSet.java new file mode 100644 index 00000000000..6dbddc7c350 --- /dev/null +++ b/lucene/core/src/java/org/apache/lucene/util/FixedBitDocIdSet.java @@ -0,0 +1,79 @@ +package org.apache.lucene.util; + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.apache.lucene.search.DocIdSet; +import org.apache.lucene.search.DocIdSetIterator; +import org.apache.lucene.util.FixedBitSet.FixedBitSetIterator; + +/** + * Implementation of the {@link DocIdSet} interface on top of a {@link FixedBitSet}. + * @lucene.internal + */ +public class FixedBitDocIdSet extends DocIdSet { + + private static final long BASE_RAM_BYTES_USED = RamUsageEstimator.shallowSizeOfInstance(SparseFixedBitDocIdSet.class); + + private final FixedBitSet set; + private final long cost; + + /** + * Wrap the given {@link FixedBitSet} as a {@link DocIdSet}. The provided + * {@link FixedBitSet} should not be modified after having wrapped as a + * {@link DocIdSet}. + */ + public FixedBitDocIdSet(FixedBitSet set, long cost) { + this.set = set; + this.cost = cost; + } + + /** + * Same as {@link #FixedBitDocIdSet(FixedBitSet, long)} but uses the set + * {@link FixedBitSet#cardinality() cardinality} as a cost. + */ + public FixedBitDocIdSet(FixedBitSet set) { + this(set, set.cardinality()); + } + + @Override + public DocIdSetIterator iterator() { + return new FixedBitSetIterator(set, cost); + } + + @Override + public FixedBitSet bits() { + return set; + } + + /** This DocIdSet implementation is cacheable. */ + @Override + public boolean isCacheable() { + return true; + } + + @Override + public long ramBytesUsed() { + return BASE_RAM_BYTES_USED + set.ramBytesUsed(); + } + + @Override + public String toString() { + return getClass().getSimpleName() + "(set=" + set + ",cost=" + cost + ")"; + } + +} diff --git a/lucene/core/src/java/org/apache/lucene/util/FixedBitSet.java b/lucene/core/src/java/org/apache/lucene/util/FixedBitSet.java index d97f121a18b..6c40fc8600e 100644 --- a/lucene/core/src/java/org/apache/lucene/util/FixedBitSet.java +++ b/lucene/core/src/java/org/apache/lucene/util/FixedBitSet.java @@ -19,6 +19,7 @@ package org.apache.lucene.util; import java.io.IOException; import java.util.Arrays; +import java.util.Collections; import org.apache.lucene.search.DocIdSet; import org.apache.lucene.search.DocIdSetIterator; @@ -31,7 +32,7 @@ import org.apache.lucene.search.DocIdSetIterator; * * @lucene.internal */ -public final class FixedBitSet extends DocIdSet implements MutableBits { +public final class FixedBitSet implements MutableBits, Accountable { private static final long BASE_RAM_BYTES_USED = RamUsageEstimator.shallowSizeOfInstance(FixedBitSet.class); @@ -43,18 +44,20 @@ public final class FixedBitSet extends DocIdSet implements MutableBits { final int numBits, numWords; final long[] bits; + final long cost; int doc = -1; /** Creates an iterator over the given {@link FixedBitSet}. */ - public FixedBitSetIterator(FixedBitSet bits) { - this(bits.bits, bits.numBits, bits.numWords); + public FixedBitSetIterator(FixedBitSet bits, long cost) { + this(bits.bits, bits.numBits, bits.numWords, cost); } /** Creates an iterator over the given array of bits. */ - public FixedBitSetIterator(long[] bits, int numBits, int wordLength) { + public FixedBitSetIterator(long[] bits, int numBits, int wordLength, long cost) { this.bits = bits; this.numBits = numBits; this.numWords = wordLength; + this.cost = cost; } @Override @@ -69,7 +72,7 @@ public final class FixedBitSet extends DocIdSet implements MutableBits { @Override public long cost() { - return numBits; + return cost; } @Override @@ -179,33 +182,22 @@ public final class FixedBitSet extends DocIdSet implements MutableBits { this.numBits = numBits; this.bits = storedBits; } - - @Override - public DocIdSetIterator iterator() { - return new FixedBitSetIterator(bits, numBits, numWords); - } - - @Override - public Bits bits() { - return this; - } @Override public int length() { return numBits; } - /** This DocIdSet implementation is cacheable. */ - @Override - public boolean isCacheable() { - return true; - } - @Override public long ramBytesUsed() { return BASE_RAM_BYTES_USED + RamUsageEstimator.sizeOf(bits); } + @Override + public Iterable getChildResources() { + return Collections.emptyList(); + } + /** Expert. */ public long[] getBits() { return bits; diff --git a/lucene/core/src/java/org/apache/lucene/util/RoaringDocIdSet.java b/lucene/core/src/java/org/apache/lucene/util/RoaringDocIdSet.java index 93d4ab85bfa..9a7e13115da 100644 --- a/lucene/core/src/java/org/apache/lucene/util/RoaringDocIdSet.java +++ b/lucene/core/src/java/org/apache/lucene/util/RoaringDocIdSet.java @@ -92,7 +92,7 @@ public class RoaringDocIdSet extends DocIdSet { sets[currentBlock] = new NotDocIdSet(BLOCK_SIZE, new ShortArrayDocIdSet(excludedDocs)); } else { // Neither sparse nor super dense, use a fixed bit set - sets[currentBlock] = denseBuffer; + sets[currentBlock] = new FixedBitDocIdSet(denseBuffer, currentBlockCardinality); } denseBuffer = null; } diff --git a/lucene/core/src/java/org/apache/lucene/util/SparseFixedBitDocIdSet.java b/lucene/core/src/java/org/apache/lucene/util/SparseFixedBitDocIdSet.java new file mode 100644 index 00000000000..7bf564b603a --- /dev/null +++ b/lucene/core/src/java/org/apache/lucene/util/SparseFixedBitDocIdSet.java @@ -0,0 +1,71 @@ +package org.apache.lucene.util; + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.io.IOException; + +import org.apache.lucene.search.DocIdSet; +import org.apache.lucene.search.DocIdSetIterator; +import org.apache.lucene.util.SparseFixedBitSet.SparseFixedBitSetIterator; + +/** + * Implementation of the {@link DocIdSet} interface on top of a {@link SparseFixedBitSet}. + * @lucene.internal + */ +public class SparseFixedBitDocIdSet extends DocIdSet { + + private static final long BASE_RAM_BYTES_USED = RamUsageEstimator.shallowSizeOfInstance(SparseFixedBitDocIdSet.class); + + private final SparseFixedBitSet set; + private final long cost; + + /** + * Wrap the given {@link FixedBitSet} as a {@link DocIdSet}. The provided + * {@link FixedBitSet} should not be modified after having wrapped as a + * {@link DocIdSet}. + */ + public SparseFixedBitDocIdSet(SparseFixedBitSet set, long cost) { + this.set = set; + this.cost = cost; + } + + @Override + public SparseFixedBitSet bits() { + return set; + } + + @Override + public boolean isCacheable() { + return true; + } + + @Override + public DocIdSetIterator iterator() throws IOException { + return new SparseFixedBitSetIterator(set, cost); + } + + @Override + public long ramBytesUsed() { + return BASE_RAM_BYTES_USED + set.ramBytesUsed(); + } + + @Override + public String toString() { + return getClass().getSimpleName() + "(set=" + set + ",cost=" + cost + ")"; + } +} diff --git a/lucene/core/src/java/org/apache/lucene/util/SparseFixedBitSet.java b/lucene/core/src/java/org/apache/lucene/util/SparseFixedBitSet.java index 7a971956342..b264d924505 100644 --- a/lucene/core/src/java/org/apache/lucene/util/SparseFixedBitSet.java +++ b/lucene/core/src/java/org/apache/lucene/util/SparseFixedBitSet.java @@ -18,8 +18,8 @@ package org.apache.lucene.util; */ import java.io.IOException; +import java.util.Collections; -import org.apache.lucene.search.DocIdSet; import org.apache.lucene.search.DocIdSetIterator; /** @@ -33,7 +33,7 @@ import org.apache.lucene.search.DocIdSetIterator; * * @lucene.internal */ -public class SparseFixedBitSet extends DocIdSet implements Bits { +public class SparseFixedBitSet implements Bits, Accountable { private static final long BASE_RAM_BYTES_USED = RamUsageEstimator.shallowSizeOfInstance(SparseFixedBitSet.class); private static final long SINGLE_ELEMENT_ARRAY_BYTES_USED = RamUsageEstimator.sizeOf(new long[1]); @@ -68,21 +68,11 @@ public class SparseFixedBitSet extends DocIdSet implements Bits { + RamUsageEstimator.shallowSizeOf(bits); } - @Override - public boolean isCacheable() { - return true; - } - @Override public int length() { return length; } - @Override - public Bits bits() throws IOException { - return this; - } - private boolean consistent(int index) { assert index >= 0 && index < length : "index=" + index + ",length=" + length; return true; @@ -218,14 +208,27 @@ public class SparseFixedBitSet extends DocIdSet implements Bits { } @Override - public DocIdSetIterator iterator() throws IOException { - return new Iterator(); + public Iterable getChildResources() { + return Collections.emptyList(); } - class Iterator extends DocIdSetIterator { + /** + * A {@link DocIdSetIterator} which iterates over set bits in a + * {@link SparseFixedBitSet}. + */ + public static class SparseFixedBitSetIterator extends DocIdSetIterator { + private final long[] indices; + private final long[][] bits; + private final long cost; private int doc = -1; - private int cost = -1; + + /** Sole constructor. */ + public SparseFixedBitSetIterator(SparseFixedBitSet set, long cost) { + indices = set.indices; + bits = set.bits; + this.cost = cost; + } @Override public int docID() { @@ -315,13 +318,6 @@ public class SparseFixedBitSet extends DocIdSet implements Bits { @Override public long cost() { - // although constant-time, approximateCardinality is a bit expensive so - // we cache it to avoid performance traps eg. when sorting iterators by - // cost - if (cost < 0) { - cost = approximateCardinality(); - } - assert cost >= 0; return cost; } diff --git a/lucene/core/src/test/org/apache/lucene/search/MockFilter.java b/lucene/core/src/test/org/apache/lucene/search/MockFilter.java index a6e2f35af20..1bd9bb4f46c 100644 --- a/lucene/core/src/test/org/apache/lucene/search/MockFilter.java +++ b/lucene/core/src/test/org/apache/lucene/search/MockFilter.java @@ -18,6 +18,7 @@ package org.apache.lucene.search; */ import org.apache.lucene.index.LeafReaderContext; +import org.apache.lucene.util.FixedBitDocIdSet; import org.apache.lucene.util.FixedBitSet; import org.apache.lucene.util.Bits; @@ -27,7 +28,8 @@ public class MockFilter extends Filter { @Override public DocIdSet getDocIdSet(LeafReaderContext context, Bits acceptDocs) { wasCalled = true; - return new FixedBitSet(context.reader().maxDoc()); + FixedBitSet bits = new FixedBitSet(context.reader().maxDoc()); + return new FixedBitDocIdSet(bits); } public void clear() { diff --git a/lucene/core/src/test/org/apache/lucene/search/SingleDocTestFilter.java b/lucene/core/src/test/org/apache/lucene/search/SingleDocTestFilter.java index 90bc6ff2d61..d0cd8fe62dd 100644 --- a/lucene/core/src/test/org/apache/lucene/search/SingleDocTestFilter.java +++ b/lucene/core/src/test/org/apache/lucene/search/SingleDocTestFilter.java @@ -17,12 +17,13 @@ package org.apache.lucene.search; * limitations under the License. */ +import java.io.IOException; + import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.util.Bits; +import org.apache.lucene.util.FixedBitDocIdSet; import org.apache.lucene.util.FixedBitSet; -import java.io.IOException; - public class SingleDocTestFilter extends Filter { private int doc; @@ -35,6 +36,6 @@ public class SingleDocTestFilter extends Filter { FixedBitSet bits = new FixedBitSet(context.reader().maxDoc()); bits.set(doc); if (acceptDocs != null && !acceptDocs.get(doc)) bits.clear(doc); - return bits; + return new FixedBitDocIdSet(bits); } } diff --git a/lucene/core/src/test/org/apache/lucene/search/TestCachingWrapperFilter.java b/lucene/core/src/test/org/apache/lucene/search/TestCachingWrapperFilter.java index 945edbdeced..34318f5e253 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestCachingWrapperFilter.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestCachingWrapperFilter.java @@ -32,6 +32,7 @@ import org.apache.lucene.index.SlowCompositeReaderWrapper; import org.apache.lucene.index.Term; import org.apache.lucene.store.Directory; import org.apache.lucene.util.Bits; +import org.apache.lucene.util.FixedBitDocIdSet; import org.apache.lucene.util.FixedBitSet; import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.LuceneTestCase; @@ -264,7 +265,7 @@ public class TestCachingWrapperFilter extends LuceneTestCase { assertDocIdSetCacheable(reader, new Filter() { @Override public DocIdSet getDocIdSet(LeafReaderContext context, Bits acceptDocs) { - return new FixedBitSet(context.reader().maxDoc()); + return new FixedBitDocIdSet(new FixedBitSet(context.reader().maxDoc())); } }, true); diff --git a/lucene/core/src/test/org/apache/lucene/search/TestFilteredQuery.java b/lucene/core/src/test/org/apache/lucene/search/TestFilteredQuery.java index 323ffb6d5fd..6238e77c467 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestFilteredQuery.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestFilteredQuery.java @@ -34,6 +34,7 @@ import org.apache.lucene.search.BooleanClause.Occur; import org.apache.lucene.search.FilteredQuery.FilterStrategy; import org.apache.lucene.store.Directory; import org.apache.lucene.util.Bits; +import org.apache.lucene.util.FixedBitDocIdSet; import org.apache.lucene.util.FixedBitSet; import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.LuceneTestCase; @@ -104,7 +105,7 @@ public class TestFilteredQuery extends LuceneTestCase { FixedBitSet bitset = new FixedBitSet(context.reader().maxDoc()); if (acceptDocs.get(1)) bitset.set(1); if (acceptDocs.get(3)) bitset.set(3); - return bitset; + return new FixedBitDocIdSet(bitset); } }; } @@ -185,7 +186,7 @@ public class TestFilteredQuery extends LuceneTestCase { assertNull("acceptDocs should be null, as we have an index without deletions", acceptDocs); FixedBitSet bitset = new FixedBitSet(context.reader().maxDoc()); bitset.set(0, Math.min(5, bitset.length())); - return bitset; + return new FixedBitDocIdSet(bitset); } }; } diff --git a/lucene/core/src/test/org/apache/lucene/search/TestFilteredSearch.java b/lucene/core/src/test/org/apache/lucene/search/TestFilteredSearch.java index ae21d75fb5b..b1e7b78ae77 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestFilteredSearch.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestFilteredSearch.java @@ -31,6 +31,7 @@ import org.apache.lucene.index.Term; import org.apache.lucene.index.IndexWriterConfig.OpenMode; import org.apache.lucene.store.Directory; import org.apache.lucene.util.Bits; +import org.apache.lucene.util.FixedBitDocIdSet; import org.apache.lucene.util.FixedBitSet; @@ -98,7 +99,7 @@ public class TestFilteredSearch extends LuceneTestCase { set.set(docId-docBase); } } - return set.cardinality() == 0 ? null:set; + return set.cardinality() == 0 ? null : new FixedBitDocIdSet(set); } } diff --git a/lucene/core/src/test/org/apache/lucene/search/TestScorerPerf.java b/lucene/core/src/test/org/apache/lucene/search/TestScorerPerf.java index 6405173e6fe..b13f144bae5 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestScorerPerf.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestScorerPerf.java @@ -14,6 +14,7 @@ import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.Term; import org.apache.lucene.store.Directory; import org.apache.lucene.util.Bits; +import org.apache.lucene.util.FixedBitDocIdSet; import org.apache.lucene.util.FixedBitSet; import org.apache.lucene.util.LuceneTestCase; @@ -145,7 +146,7 @@ public class TestScorerPerf extends LuceneTestCase { @Override public DocIdSet getDocIdSet (LeafReaderContext context, Bits acceptDocs) { assertNull("acceptDocs should be null, as we have an index without deletions", acceptDocs); - return rnd; + return new FixedBitDocIdSet(rnd); } }); bq.add(q, BooleanClause.Occur.MUST); diff --git a/lucene/core/src/test/org/apache/lucene/search/TestSortRandom.java b/lucene/core/src/test/org/apache/lucene/search/TestSortRandom.java index 9df13d6ea35..a2c73f86219 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestSortRandom.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestSortRandom.java @@ -39,6 +39,7 @@ import org.apache.lucene.search.BooleanClause.Occur; import org.apache.lucene.store.Directory; import org.apache.lucene.util.Bits; import org.apache.lucene.util.BytesRef; +import org.apache.lucene.util.FixedBitDocIdSet; import org.apache.lucene.util.FixedBitSet; import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.TestUtil; @@ -260,7 +261,7 @@ public class TestSortRandom extends LuceneTestCase { } } - return bits; + return new FixedBitDocIdSet(bits); } } } diff --git a/lucene/core/src/test/org/apache/lucene/util/TestDocIdSetBuilder.java b/lucene/core/src/test/org/apache/lucene/util/TestDocIdSetBuilder.java index 8e8d8ab5707..c7da0fc09b5 100644 --- a/lucene/core/src/test/org/apache/lucene/util/TestDocIdSetBuilder.java +++ b/lucene/core/src/test/org/apache/lucene/util/TestDocIdSetBuilder.java @@ -60,8 +60,8 @@ public class TestDocIdSetBuilder extends LuceneTestCase { builder.or(b.build().iterator()); } DocIdSet result = builder.build(); - assertTrue(result instanceof SparseFixedBitSet); - assertEquals(ref, result); + assertTrue(result instanceof SparseFixedBitDocIdSet); + assertEquals(new FixedBitDocIdSet(ref), result); } public void testDense() throws IOException { @@ -84,8 +84,8 @@ public class TestDocIdSetBuilder extends LuceneTestCase { builder.or(b.build().iterator()); } DocIdSet result = builder.build(); - assertTrue(result instanceof FixedBitSet); - assertEquals(ref, result); + assertTrue(result instanceof FixedBitDocIdSet); + assertEquals(new FixedBitDocIdSet(ref), result); } } diff --git a/lucene/core/src/test/org/apache/lucene/util/TestFixedBitSet.java b/lucene/core/src/test/org/apache/lucene/util/TestFixedBitSet.java index 6fa84271a49..d2c9bd6b8ce 100644 --- a/lucene/core/src/test/org/apache/lucene/util/TestFixedBitSet.java +++ b/lucene/core/src/test/org/apache/lucene/util/TestFixedBitSet.java @@ -21,16 +21,17 @@ import java.io.IOException; import java.util.BitSet; import org.apache.lucene.search.DocIdSetIterator; +import org.apache.lucene.util.FixedBitSet.FixedBitSetIterator; -public class TestFixedBitSet extends BaseDocIdSetTestCase { +public class TestFixedBitSet extends BaseDocIdSetTestCase { @Override - public FixedBitSet copyOf(BitSet bs, int length) throws IOException { + public FixedBitDocIdSet copyOf(BitSet bs, int length) throws IOException { final FixedBitSet set = new FixedBitSet(length); for (int doc = bs.nextSetBit(0); doc != -1; doc = bs.nextSetBit(doc + 1)) { set.set(doc); } - return set; + return new FixedBitDocIdSet(set); } void doGet(BitSet a, FixedBitSet b) { @@ -81,7 +82,7 @@ public class TestFixedBitSet extends BaseDocIdSetTestCase { void doIterate1(BitSet a, FixedBitSet b) throws IOException { int aa=-1,bb=-1; - DocIdSetIterator iterator = b.iterator(); + DocIdSetIterator iterator = new FixedBitSetIterator(b, 0); do { aa = a.nextSetBit(aa+1); bb = (bb < b.length() && random().nextBoolean()) ? iterator.nextDoc() : iterator.advance(bb + 1); @@ -91,7 +92,7 @@ public class TestFixedBitSet extends BaseDocIdSetTestCase { void doIterate2(BitSet a, FixedBitSet b) throws IOException { int aa=-1,bb=-1; - DocIdSetIterator iterator = b.iterator(); + DocIdSetIterator iterator = new FixedBitSetIterator(b, 0); do { aa = a.nextSetBit(aa+1); bb = random().nextBoolean() ? iterator.nextDoc() : iterator.advance(bb + 1); diff --git a/lucene/core/src/test/org/apache/lucene/util/TestNotDocIdSet.java b/lucene/core/src/test/org/apache/lucene/util/TestNotDocIdSet.java index 64f75925009..80ad72153e2 100644 --- a/lucene/core/src/test/org/apache/lucene/util/TestNotDocIdSet.java +++ b/lucene/core/src/test/org/apache/lucene/util/TestNotDocIdSet.java @@ -30,7 +30,7 @@ public class TestNotDocIdSet extends BaseDocIdSetTestCase { for (int doc = bs.nextClearBit(0); doc < length; doc = bs.nextClearBit(doc + 1)) { set.set(doc); } - return new NotDocIdSet(length, set); + return new NotDocIdSet(length, new FixedBitDocIdSet(set)); } @Override @@ -48,7 +48,7 @@ public class TestNotDocIdSet extends BaseDocIdSetTestCase { public void testBits() throws IOException { assertNull(new NotDocIdSet(3, DocIdSet.EMPTY).bits()); - assertNotNull(new NotDocIdSet(3, new FixedBitSet(3)).bits()); + assertNotNull(new NotDocIdSet(3, new FixedBitDocIdSet(new FixedBitSet(3))).bits()); } } diff --git a/lucene/core/src/test/org/apache/lucene/util/TestSparseFixedBitSet.java b/lucene/core/src/test/org/apache/lucene/util/TestSparseFixedBitSet.java index 0a8feb18829..a90c83bcb24 100644 --- a/lucene/core/src/test/org/apache/lucene/util/TestSparseFixedBitSet.java +++ b/lucene/core/src/test/org/apache/lucene/util/TestSparseFixedBitSet.java @@ -23,10 +23,10 @@ import java.util.BitSet; import java.util.Collections; import java.util.List; -public class TestSparseFixedBitSet extends BaseDocIdSetTestCase { +public class TestSparseFixedBitSet extends BaseDocIdSetTestCase { @Override - public SparseFixedBitSet copyOf(BitSet bs, int length) throws IOException { + public SparseFixedBitDocIdSet copyOf(BitSet bs, int length) throws IOException { final SparseFixedBitSet set = new SparseFixedBitSet(length); // SparseFixedBitSet can be sensitive to the order of insertion so // randomize insertion a bit @@ -45,15 +45,15 @@ public class TestSparseFixedBitSet extends BaseDocIdSetTestCase= expected.length() ? -1 : expected.nextSetBit(docId + 1)) { if (!actual.get(docId)) { return false; } diff --git a/lucene/join/src/java/org/apache/lucene/search/join/FixedBitSetCachingWrapperFilter.java b/lucene/join/src/java/org/apache/lucene/search/join/FixedBitSetCachingWrapperFilter.java index 1801e3a2e4e..e1840b5fb15 100644 --- a/lucene/join/src/java/org/apache/lucene/search/join/FixedBitSetCachingWrapperFilter.java +++ b/lucene/join/src/java/org/apache/lucene/search/join/FixedBitSetCachingWrapperFilter.java @@ -26,6 +26,7 @@ import org.apache.lucene.search.CachingWrapperFilter; import org.apache.lucene.search.DocIdSet; import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.search.Filter; +import org.apache.lucene.util.FixedBitDocIdSet; import org.apache.lucene.util.FixedBitSet; /** A {@link CachingWrapperFilter} that caches sets using a {@link FixedBitSet}, @@ -42,7 +43,7 @@ public final class FixedBitSetCachingWrapperFilter extends CachingWrapperFilter throws IOException { if (docIdSet == null) { return EMPTY; - } else if (docIdSet instanceof FixedBitSet) { + } else if (docIdSet instanceof FixedBitDocIdSet) { // this is different from CachingWrapperFilter: even when the DocIdSet is // cacheable, we convert it to a FixedBitSet since we require all the // cached filters to be FixedBitSets @@ -54,7 +55,7 @@ public final class FixedBitSetCachingWrapperFilter extends CachingWrapperFilter } else { final FixedBitSet copy = new FixedBitSet(reader.maxDoc()); copy.or(it); - return copy; + return new FixedBitDocIdSet(copy); } } } diff --git a/lucene/join/src/java/org/apache/lucene/search/join/TermsIncludingScoreQuery.java b/lucene/join/src/java/org/apache/lucene/search/join/TermsIncludingScoreQuery.java index fb1744b56b6..d2449786522 100644 --- a/lucene/join/src/java/org/apache/lucene/search/join/TermsIncludingScoreQuery.java +++ b/lucene/join/src/java/org/apache/lucene/search/join/TermsIncludingScoreQuery.java @@ -21,25 +21,26 @@ import java.io.IOException; import java.util.Locale; import java.util.Set; -import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.DocsEnum; import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.Term; import org.apache.lucene.index.Terms; import org.apache.lucene.index.TermsEnum; -import org.apache.lucene.search.LeafCollector; +import org.apache.lucene.search.BulkScorer; import org.apache.lucene.search.ComplexExplanation; import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.search.Explanation; import org.apache.lucene.search.IndexSearcher; +import org.apache.lucene.search.LeafCollector; import org.apache.lucene.search.Query; import org.apache.lucene.search.Scorer; -import org.apache.lucene.search.BulkScorer; import org.apache.lucene.search.Weight; import org.apache.lucene.util.Bits; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRefHash; import org.apache.lucene.util.FixedBitSet; +import org.apache.lucene.util.FixedBitSet.FixedBitSetIterator; class TermsIncludingScoreQuery extends Query { @@ -328,7 +329,7 @@ class TermsIncludingScoreQuery extends Query { FixedBitSet matchingDocs = new FixedBitSet(maxDoc); this.scores = new float[maxDoc]; fillDocsAndScores(matchingDocs, acceptDocs, termsEnum); - this.matchingDocsIterator = matchingDocs.iterator(); + this.matchingDocsIterator = new FixedBitSetIterator(matchingDocs, cost); this.cost = cost; } diff --git a/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java b/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java index e7cba341a3d..69e509c1ecd 100644 --- a/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java +++ b/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java @@ -22,8 +22,8 @@ import java.util.Collection; import java.util.Collections; import java.util.Set; -import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.Term; import org.apache.lucene.search.DocIdSet; import org.apache.lucene.search.Explanation; @@ -33,6 +33,7 @@ import org.apache.lucene.search.Query; import org.apache.lucene.search.Scorer; import org.apache.lucene.search.Weight; import org.apache.lucene.util.Bits; +import org.apache.lucene.util.FixedBitDocIdSet; import org.apache.lucene.util.FixedBitSet; /** @@ -144,11 +145,11 @@ public class ToChildBlockJoinQuery extends Query { // No matches return null; } - if (!(parents instanceof FixedBitSet)) { + if (!(parents instanceof FixedBitDocIdSet)) { throw new IllegalStateException("parentFilter must return FixedBitSet; got " + parents); } - return new ToChildBlockJoinScorer(this, parentScorer, (FixedBitSet) parents, doScores, acceptDocs); + return new ToChildBlockJoinScorer(this, parentScorer, ((FixedBitDocIdSet) parents).bits(), doScores, acceptDocs); } @Override diff --git a/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinFieldComparator.java b/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinFieldComparator.java index 3fdf7ad91be..d1fd0056e68 100644 --- a/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinFieldComparator.java +++ b/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinFieldComparator.java @@ -17,15 +17,16 @@ package org.apache.lucene.search.join; * limitations under the License. */ +import java.io.IOException; + import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.search.DocIdSet; import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.search.FieldComparator; import org.apache.lucene.search.Filter; +import org.apache.lucene.util.FixedBitDocIdSet; import org.apache.lucene.util.FixedBitSet; -import java.io.IOException; - /** * A field comparator that allows parent documents to be sorted by fields * from the nested / child documents. @@ -69,8 +70,8 @@ public abstract class ToParentBlockJoinFieldComparator extends FieldComparator leaves = reader.leaves(); final int subIndex = ReaderUtil.subIndex(childDocID, leaves); final LeafReaderContext leaf = leaves.get(subIndex); - final FixedBitSet bits = (FixedBitSet) parents.getDocIdSet(leaf, null); + final FixedBitSet bits = (FixedBitSet) parents.getDocIdSet(leaf, null).bits(); return leaf.reader().document(bits.nextSetBit(childDocID - leaf.docBase)); } diff --git a/lucene/join/src/test/org/apache/lucene/search/join/TestJoinUtil.java b/lucene/join/src/test/org/apache/lucene/search/join/TestJoinUtil.java index 688589abd3f..846fee06278 100644 --- a/lucene/join/src/test/org/apache/lucene/search/join/TestJoinUtil.java +++ b/lucene/join/src/test/org/apache/lucene/search/join/TestJoinUtil.java @@ -37,12 +37,12 @@ import org.apache.lucene.document.Field; import org.apache.lucene.document.SortedDocValuesField; import org.apache.lucene.document.SortedSetDocValuesField; import org.apache.lucene.document.TextField; -import org.apache.lucene.index.LeafReader; -import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.BinaryDocValues; import org.apache.lucene.index.DocValues; import org.apache.lucene.index.DocsEnum; import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.LeafReader; +import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.MultiFields; import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.index.SlowCompositeReaderWrapper; @@ -67,6 +67,7 @@ import org.apache.lucene.store.Directory; import org.apache.lucene.util.Bits; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.FixedBitSet; +import org.apache.lucene.util.FixedBitSet.FixedBitSetIterator; import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.TestUtil; import org.junit.Test; @@ -504,12 +505,12 @@ public class TestJoinUtil extends LuceneTestCase { // Asserting bit set... if (VERBOSE) { System.out.println("expected cardinality:" + expectedResult.cardinality()); - DocIdSetIterator iterator = expectedResult.iterator(); + DocIdSetIterator iterator = new FixedBitSetIterator(expectedResult, expectedResult.cardinality()); for (int doc = iterator.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = iterator.nextDoc()) { System.out.println(String.format(Locale.ROOT, "Expected doc[%d] with id value %s", doc, indexSearcher.doc(doc).get("id"))); } System.out.println("actual cardinality:" + actualResult.cardinality()); - iterator = actualResult.iterator(); + iterator = new FixedBitSetIterator(actualResult, actualResult.cardinality()); for (int doc = iterator.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = iterator.nextDoc()) { System.out.println(String.format(Locale.ROOT, "Actual doc[%d] with id value %s", doc, indexSearcher.doc(doc).get("id"))); } diff --git a/lucene/misc/src/java/org/apache/lucene/index/PKIndexSplitter.java b/lucene/misc/src/java/org/apache/lucene/index/PKIndexSplitter.java index f69f422c02e..fe55dca838d 100644 --- a/lucene/misc/src/java/org/apache/lucene/index/PKIndexSplitter.java +++ b/lucene/misc/src/java/org/apache/lucene/index/PKIndexSplitter.java @@ -28,6 +28,7 @@ import org.apache.lucene.search.TermRangeFilter; import org.apache.lucene.store.Directory; import org.apache.lucene.util.Bits; import org.apache.lucene.util.FixedBitSet; +import org.apache.lucene.util.FixedBitSet.FixedBitSetIterator; import org.apache.lucene.util.IOUtils; /** @@ -141,7 +142,7 @@ public class PKIndexSplitter { if (in.hasDeletions()) { final Bits oldLiveDocs = in.getLiveDocs(); assert oldLiveDocs != null; - final DocIdSetIterator it = bits.iterator(); + final DocIdSetIterator it = new FixedBitSetIterator(bits, 0L); // the cost is not useful here for (int i = it.nextDoc(); i < maxDoc; i = it.nextDoc()) { if (!oldLiveDocs.get(i)) { // we can safely modify the current bit, as the iterator already stepped over it: diff --git a/lucene/misc/src/java/org/apache/lucene/index/sorter/BlockJoinComparatorSource.java b/lucene/misc/src/java/org/apache/lucene/index/sorter/BlockJoinComparatorSource.java index cb5847c21fd..45e3bcbd7d2 100644 --- a/lucene/misc/src/java/org/apache/lucene/index/sorter/BlockJoinComparatorSource.java +++ b/lucene/misc/src/java/org/apache/lucene/index/sorter/BlockJoinComparatorSource.java @@ -30,6 +30,7 @@ import org.apache.lucene.search.ScoreDoc; // javadocs import org.apache.lucene.search.Scorer; import org.apache.lucene.search.Sort; import org.apache.lucene.search.SortField; +import org.apache.lucene.util.FixedBitDocIdSet; import org.apache.lucene.util.FixedBitSet; /** @@ -148,10 +149,10 @@ public class BlockJoinComparatorSource extends FieldComparatorSource { if (parents == null) { throw new IllegalStateException("LeafReader " + context.reader() + " contains no parents!"); } - if (!(parents instanceof FixedBitSet)) { + if (!(parents instanceof FixedBitDocIdSet)) { throw new IllegalStateException("parentFilter must return FixedBitSet; got " + parents); } - parentBits = (FixedBitSet) parents; + parentBits = (FixedBitSet) parents.bits(); for (int i = 0; i < parentComparators.length; i++) { parentComparators[i] = parentComparators[i].setNextReader(context); } diff --git a/lucene/misc/src/test/org/apache/lucene/index/sorter/TestBlockJoinSorter.java b/lucene/misc/src/test/org/apache/lucene/index/sorter/TestBlockJoinSorter.java index 5d75d9ec738..c0e542c3f68 100644 --- a/lucene/misc/src/test/org/apache/lucene/index/sorter/TestBlockJoinSorter.java +++ b/lucene/misc/src/test/org/apache/lucene/index/sorter/TestBlockJoinSorter.java @@ -41,6 +41,7 @@ import org.apache.lucene.search.Sort; import org.apache.lucene.search.SortField; import org.apache.lucene.search.TermQuery; import org.apache.lucene.util.ArrayUtil; +import org.apache.lucene.util.FixedBitDocIdSet; import org.apache.lucene.util.FixedBitSet; import org.apache.lucene.util.LuceneTestCase; @@ -57,7 +58,7 @@ public class TestBlockJoinSorter extends LuceneTestCase { throws IOException { final FixedBitSet cached = new FixedBitSet(reader.maxDoc()); cached.or(iterator); - return cached; + return new FixedBitDocIdSet(cached); } } @@ -90,7 +91,7 @@ public class TestBlockJoinSorter extends LuceneTestCase { final LeafReader reader = getOnlySegmentReader(indexReader); final Filter parentsFilter = new FixedBitSetCachingWrapperFilter(new QueryWrapperFilter(new TermQuery(new Term("parent", "true")))); - final FixedBitSet parentBits = (FixedBitSet) parentsFilter.getDocIdSet(reader.getContext(), null); + final FixedBitSet parentBits = (FixedBitSet) parentsFilter.getDocIdSet(reader.getContext(), null).bits(); final NumericDocValues parentValues = reader.getNumericDocValues("parent_val"); final NumericDocValues childValues = reader.getNumericDocValues("child_val"); diff --git a/lucene/misc/src/test/org/apache/lucene/uninverting/TestFieldCacheSortRandom.java b/lucene/misc/src/test/org/apache/lucene/uninverting/TestFieldCacheSortRandom.java index bc1aa16466c..3472927a73d 100644 --- a/lucene/misc/src/test/org/apache/lucene/uninverting/TestFieldCacheSortRandom.java +++ b/lucene/misc/src/test/org/apache/lucene/uninverting/TestFieldCacheSortRandom.java @@ -52,6 +52,7 @@ import org.apache.lucene.store.Directory; import org.apache.lucene.uninverting.UninvertingReader.Type; import org.apache.lucene.util.Bits; import org.apache.lucene.util.BytesRef; +import org.apache.lucene.util.FixedBitDocIdSet; import org.apache.lucene.util.FixedBitSet; import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.TestUtil; @@ -290,7 +291,7 @@ public class TestFieldCacheSortRandom extends LuceneTestCase { } } - return bits; + return new FixedBitDocIdSet(bits); } } } diff --git a/lucene/queries/src/java/org/apache/lucene/queries/BooleanFilter.java b/lucene/queries/src/java/org/apache/lucene/queries/BooleanFilter.java index 9c244dbabd1..704f323b4ec 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/BooleanFilter.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/BooleanFilter.java @@ -30,6 +30,7 @@ import org.apache.lucene.search.DocIdSet; import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.search.Filter; import org.apache.lucene.util.Bits; +import org.apache.lucene.util.FixedBitDocIdSet; import org.apache.lucene.util.FixedBitSet; /** @@ -98,7 +99,10 @@ public class BooleanFilter extends Filter implements Iterable { } } - return BitsFilteredDocIdSet.wrap(res, acceptDocs); + if (res == null) { + return null; + } + return BitsFilteredDocIdSet.wrap(new FixedBitDocIdSet(res), acceptDocs); } private static DocIdSetIterator getDISI(Filter filter, LeafReaderContext context) diff --git a/lucene/queries/src/test/org/apache/lucene/queries/BooleanFilterTest.java b/lucene/queries/src/test/org/apache/lucene/queries/BooleanFilterTest.java index c0d0261d960..7d45f06a32f 100644 --- a/lucene/queries/src/test/org/apache/lucene/queries/BooleanFilterTest.java +++ b/lucene/queries/src/test/org/apache/lucene/queries/BooleanFilterTest.java @@ -17,6 +17,8 @@ package org.apache.lucene.queries; * limitations under the License. */ +import java.io.IOException; + import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.analysis.MockTokenizer; import org.apache.lucene.document.Document; @@ -27,19 +29,18 @@ import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.index.SlowCompositeReaderWrapper; import org.apache.lucene.index.Term; import org.apache.lucene.search.BooleanClause.Occur; +import org.apache.lucene.search.DocIdSet; import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.search.Filter; -import org.apache.lucene.search.TermRangeFilter; -import org.apache.lucene.search.DocIdSet; -import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.QueryWrapperFilter; +import org.apache.lucene.search.TermQuery; +import org.apache.lucene.search.TermRangeFilter; import org.apache.lucene.store.Directory; import org.apache.lucene.util.Bits; +import org.apache.lucene.util.FixedBitDocIdSet; import org.apache.lucene.util.FixedBitSet; import org.apache.lucene.util.LuceneTestCase; -import java.io.IOException; - public class BooleanFilterTest extends LuceneTestCase { private Directory directory; private LeafReader reader; @@ -93,7 +94,7 @@ public class BooleanFilterTest extends LuceneTestCase { return new Filter() { @Override public DocIdSet getDocIdSet(LeafReaderContext context, Bits acceptDocs) { - return new FixedBitSet(context.reader().maxDoc()); + return new FixedBitDocIdSet(new FixedBitSet(context.reader().maxDoc())); } }; } diff --git a/lucene/queries/src/test/org/apache/lucene/queries/TermsFilterTest.java b/lucene/queries/src/test/org/apache/lucene/queries/TermsFilterTest.java index 553cda26570..7079a59ecb9 100644 --- a/lucene/queries/src/test/org/apache/lucene/queries/TermsFilterTest.java +++ b/lucene/queries/src/test/org/apache/lucene/queries/TermsFilterTest.java @@ -47,6 +47,7 @@ import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.TopDocs; import org.apache.lucene.store.Directory; import org.apache.lucene.util.BytesRef; +import org.apache.lucene.util.FixedBitDocIdSet; import org.apache.lucene.util.FixedBitSet; import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.TestUtil; @@ -81,20 +82,20 @@ public class TermsFilterTest extends LuceneTestCase { List terms = new ArrayList<>(); terms.add(new Term(fieldName, "19")); - FixedBitSet bits = (FixedBitSet) termsFilter(random().nextBoolean(), terms).getDocIdSet(context, context.reader().getLiveDocs()); + FixedBitDocIdSet bits = (FixedBitDocIdSet) termsFilter(random().nextBoolean(), terms).getDocIdSet(context, context.reader().getLiveDocs()); assertNull("Must match nothing", bits); terms.add(new Term(fieldName, "20")); - bits = (FixedBitSet) termsFilter(random().nextBoolean(), terms).getDocIdSet(context, context.reader().getLiveDocs()); - assertEquals("Must match 1", 1, bits.cardinality()); + bits = (FixedBitDocIdSet) termsFilter(random().nextBoolean(), terms).getDocIdSet(context, context.reader().getLiveDocs()); + assertEquals("Must match 1", 1, bits.bits().cardinality()); terms.add(new Term(fieldName, "10")); - bits = (FixedBitSet) termsFilter(random().nextBoolean(), terms).getDocIdSet(context, context.reader().getLiveDocs()); - assertEquals("Must match 2", 2, bits.cardinality()); + bits = (FixedBitDocIdSet) termsFilter(random().nextBoolean(), terms).getDocIdSet(context, context.reader().getLiveDocs()); + assertEquals("Must match 2", 2, bits.bits().cardinality()); terms.add(new Term(fieldName, "00")); - bits = (FixedBitSet) termsFilter(random().nextBoolean(), terms).getDocIdSet(context, context.reader().getLiveDocs()); - assertEquals("Must match 2", 2, bits.cardinality()); + bits = (FixedBitDocIdSet) termsFilter(random().nextBoolean(), terms).getDocIdSet(context, context.reader().getLiveDocs()); + assertEquals("Must match 2", 2, bits.bits().cardinality()); reader.close(); rd.close(); @@ -126,8 +127,8 @@ public class TermsFilterTest extends LuceneTestCase { if (context.reader().docFreq(new Term(fieldName, "content1")) == 0) { assertNull(docIdSet); } else { - FixedBitSet bits = (FixedBitSet) docIdSet; - assertTrue("Must be >= 0", bits.cardinality() >= 0); + FixedBitDocIdSet bits = (FixedBitDocIdSet) docIdSet; + assertTrue("Must be >= 0", bits.bits().cardinality() >= 0); } } multi.close(); @@ -163,8 +164,8 @@ public class TermsFilterTest extends LuceneTestCase { LeafReaderContext context = reader.leaves().get(0); TermsFilter tf = new TermsFilter(terms); - FixedBitSet bits = (FixedBitSet) tf.getDocIdSet(context, context.reader().getLiveDocs()); - assertEquals("Must be num fields - 1 since we skip only one field", num-1, bits.cardinality()); + FixedBitDocIdSet bits = (FixedBitDocIdSet) tf.getDocIdSet(context, context.reader().getLiveDocs()); + assertEquals("Must be num fields - 1 since we skip only one field", num-1, bits.bits().cardinality()); reader.close(); dir.close(); } @@ -199,8 +200,8 @@ public class TermsFilterTest extends LuceneTestCase { LeafReaderContext context = reader.leaves().get(0); TermsFilter tf = new TermsFilter(new ArrayList<>(terms)); - FixedBitSet bits = (FixedBitSet) tf.getDocIdSet(context, context.reader().getLiveDocs()); - assertEquals(context.reader().numDocs(), bits.cardinality()); + FixedBitDocIdSet bits = (FixedBitDocIdSet) tf.getDocIdSet(context, context.reader().getLiveDocs()); + assertEquals(context.reader().numDocs(), bits.bits().cardinality()); reader.close(); dir.close(); } diff --git a/lucene/sandbox/src/java/org/apache/lucene/sandbox/queries/DuplicateFilter.java b/lucene/sandbox/src/java/org/apache/lucene/sandbox/queries/DuplicateFilter.java index d0871e5a3e5..67b64d3356c 100644 --- a/lucene/sandbox/src/java/org/apache/lucene/sandbox/queries/DuplicateFilter.java +++ b/lucene/sandbox/src/java/org/apache/lucene/sandbox/queries/DuplicateFilter.java @@ -29,7 +29,9 @@ import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.search.Filter; import org.apache.lucene.util.Bits; import org.apache.lucene.util.BytesRef; +import org.apache.lucene.util.FixedBitDocIdSet; import org.apache.lucene.util.FixedBitSet; +import org.apache.lucene.util.SparseFixedBitDocIdSet; import org.apache.lucene.util.SparseFixedBitSet; /** @@ -93,88 +95,84 @@ public class DuplicateFilter extends Filter { } } - private SparseFixedBitSet correctBits(LeafReader reader, Bits acceptDocs) throws IOException { + private DocIdSet correctBits(LeafReader reader, Bits acceptDocs) throws IOException { SparseFixedBitSet bits = new SparseFixedBitSet(reader.maxDoc()); //assume all are INvalid Terms terms = reader.fields().terms(fieldName); - if (terms == null) { - return bits; + if (terms != null) { + TermsEnum termsEnum = terms.iterator(null); + DocsEnum docs = null; + while (true) { + BytesRef currTerm = termsEnum.next(); + if (currTerm == null) { + break; + } else { + docs = termsEnum.docs(acceptDocs, docs, DocsEnum.FLAG_NONE); + int doc = docs.nextDoc(); + if (doc != DocIdSetIterator.NO_MORE_DOCS) { + if (keepMode == KeepMode.KM_USE_FIRST_OCCURRENCE) { + bits.set(doc); + } else { + int lastDoc = doc; + while (true) { + lastDoc = doc; + doc = docs.nextDoc(); + if (doc == DocIdSetIterator.NO_MORE_DOCS) { + break; + } + } + bits.set(lastDoc); + } + } + } + } } + return new SparseFixedBitDocIdSet(bits, bits.approximateCardinality()); + } - TermsEnum termsEnum = terms.iterator(null); - DocsEnum docs = null; - while (true) { - BytesRef currTerm = termsEnum.next(); - if (currTerm == null) { - break; - } else { - docs = termsEnum.docs(acceptDocs, docs, DocsEnum.FLAG_NONE); - int doc = docs.nextDoc(); - if (doc != DocIdSetIterator.NO_MORE_DOCS) { - if (keepMode == KeepMode.KM_USE_FIRST_OCCURRENCE) { - bits.set(doc); - } else { - int lastDoc = doc; + private DocIdSet fastBits(LeafReader reader, Bits acceptDocs) throws IOException { + FixedBitSet bits = new FixedBitSet(reader.maxDoc()); + bits.set(0, reader.maxDoc()); //assume all are valid + Terms terms = reader.fields().terms(fieldName); + + if (terms != null) { + TermsEnum termsEnum = terms.iterator(null); + DocsEnum docs = null; + while (true) { + BytesRef currTerm = termsEnum.next(); + if (currTerm == null) { + break; + } else { + if (termsEnum.docFreq() > 1) { + // unset potential duplicates + docs = termsEnum.docs(acceptDocs, docs, DocsEnum.FLAG_NONE); + int doc = docs.nextDoc(); + if (doc != DocIdSetIterator.NO_MORE_DOCS) { + if (keepMode == KeepMode.KM_USE_FIRST_OCCURRENCE) { + doc = docs.nextDoc(); + } + } + + int lastDoc = -1; while (true) { lastDoc = doc; + bits.clear(lastDoc); doc = docs.nextDoc(); if (doc == DocIdSetIterator.NO_MORE_DOCS) { break; } } - bits.set(lastDoc); - } - } - } - } - return bits; - } - - private FixedBitSet fastBits(LeafReader reader, Bits acceptDocs) throws IOException { - FixedBitSet bits = new FixedBitSet(reader.maxDoc()); - bits.set(0, reader.maxDoc()); //assume all are valid - Terms terms = reader.fields().terms(fieldName); - - if (terms == null) { - return bits; - } - - TermsEnum termsEnum = terms.iterator(null); - DocsEnum docs = null; - while (true) { - BytesRef currTerm = termsEnum.next(); - if (currTerm == null) { - break; - } else { - if (termsEnum.docFreq() > 1) { - // unset potential duplicates - docs = termsEnum.docs(acceptDocs, docs, DocsEnum.FLAG_NONE); - int doc = docs.nextDoc(); - if (doc != DocIdSetIterator.NO_MORE_DOCS) { - if (keepMode == KeepMode.KM_USE_FIRST_OCCURRENCE) { - doc = docs.nextDoc(); + + if (keepMode == KeepMode.KM_USE_LAST_OCCURRENCE) { + // restore the last bit + bits.set(lastDoc); } } - - int lastDoc = -1; - while (true) { - lastDoc = doc; - bits.clear(lastDoc); - doc = docs.nextDoc(); - if (doc == DocIdSetIterator.NO_MORE_DOCS) { - break; - } - } - - if (keepMode == KeepMode.KM_USE_LAST_OCCURRENCE) { - // restore the last bit - bits.set(lastDoc); - } } } } - return bits; + return new FixedBitDocIdSet(bits); } public String getFieldName() { diff --git a/lucene/sandbox/src/test/org/apache/lucene/search/TestTermAutomatonQuery.java b/lucene/sandbox/src/test/org/apache/lucene/search/TestTermAutomatonQuery.java index 7107f9b214a..2da3caa5b9d 100644 --- a/lucene/sandbox/src/test/org/apache/lucene/search/TestTermAutomatonQuery.java +++ b/lucene/sandbox/src/test/org/apache/lucene/search/TestTermAutomatonQuery.java @@ -46,6 +46,7 @@ import org.apache.lucene.index.Term; import org.apache.lucene.store.Directory; import org.apache.lucene.util.Bits; import org.apache.lucene.util.BytesRef; +import org.apache.lucene.util.FixedBitDocIdSet; import org.apache.lucene.util.FixedBitSet; import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.TestUtil; @@ -637,7 +638,7 @@ public class TestTermAutomatonQuery extends LuceneTestCase { } } - return bits; + return new FixedBitDocIdSet(bits); } } } diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/IntersectsPrefixTreeFilter.java b/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/IntersectsPrefixTreeFilter.java index aa9bf1155a1..5ea7e903ee9 100644 --- a/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/IntersectsPrefixTreeFilter.java +++ b/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/IntersectsPrefixTreeFilter.java @@ -19,11 +19,13 @@ package org.apache.lucene.spatial.prefix; import com.spatial4j.core.shape.Shape; import com.spatial4j.core.shape.SpatialRelation; + import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.search.DocIdSet; import org.apache.lucene.spatial.prefix.tree.Cell; import org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree; import org.apache.lucene.util.Bits; +import org.apache.lucene.util.FixedBitDocIdSet; import org.apache.lucene.util.FixedBitSet; import java.io.IOException; @@ -71,7 +73,7 @@ public class IntersectsPrefixTreeFilter extends AbstractVisitingPrefixTreeFilter @Override protected DocIdSet finish() { - return results; + return new FixedBitDocIdSet(results); } @Override diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/WithinPrefixTreeFilter.java b/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/WithinPrefixTreeFilter.java index 758d1bba5d9..5c95cd7b405 100644 --- a/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/WithinPrefixTreeFilter.java +++ b/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/WithinPrefixTreeFilter.java @@ -17,6 +17,17 @@ package org.apache.lucene.spatial.prefix; * limitations under the License. */ +import java.io.IOException; + +import org.apache.lucene.index.LeafReaderContext; +import org.apache.lucene.search.DocIdSet; +import org.apache.lucene.spatial.prefix.tree.Cell; +import org.apache.lucene.spatial.prefix.tree.CellIterator; +import org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree; +import org.apache.lucene.util.Bits; +import org.apache.lucene.util.FixedBitDocIdSet; +import org.apache.lucene.util.FixedBitSet; + import com.spatial4j.core.context.SpatialContext; import com.spatial4j.core.distance.DistanceUtils; import com.spatial4j.core.shape.Circle; @@ -24,15 +35,6 @@ import com.spatial4j.core.shape.Point; import com.spatial4j.core.shape.Rectangle; import com.spatial4j.core.shape.Shape; import com.spatial4j.core.shape.SpatialRelation; -import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.search.DocIdSet; -import org.apache.lucene.spatial.prefix.tree.Cell; -import org.apache.lucene.spatial.prefix.tree.CellIterator; -import org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree; -import org.apache.lucene.util.Bits; -import org.apache.lucene.util.FixedBitSet; - -import java.io.IOException; /** * Finds docs where its indexed shape is {@link org.apache.lucene.spatial.query.SpatialOperation#IsWithin @@ -134,7 +136,7 @@ public class WithinPrefixTreeFilter extends AbstractVisitingPrefixTreeFilter { @Override protected DocIdSet finish() { inside.andNot(outside); - return inside; + return new FixedBitDocIdSet(inside); } @Override diff --git a/solr/core/src/java/org/apache/solr/handler/component/ExpandComponent.java b/solr/core/src/java/org/apache/solr/handler/component/ExpandComponent.java index 54b9c24c32e..d85e12c5cfd 100644 --- a/solr/core/src/java/org/apache/solr/handler/component/ExpandComponent.java +++ b/solr/core/src/java/org/apache/solr/handler/component/ExpandComponent.java @@ -17,15 +17,17 @@ package org.apache.solr.handler.component; -import com.carrotsearch.hppc.IntObjectMap; -import com.carrotsearch.hppc.IntObjectOpenHashMap; -import com.carrotsearch.hppc.IntOpenHashSet; -import com.carrotsearch.hppc.cursors.IntObjectCursor; -import com.carrotsearch.hppc.cursors.ObjectCursor; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.lucene.index.DocValues; import org.apache.lucene.index.LeafReader; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.DocValues; import org.apache.lucene.index.SortedDocValues; import org.apache.lucene.search.Collector; import org.apache.lucene.search.DocIdSetIterator; @@ -41,6 +43,7 @@ import org.apache.lucene.search.TopScoreDocCollector; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.CharsRefBuilder; import org.apache.lucene.util.FixedBitSet; +import org.apache.lucene.util.FixedBitSet.FixedBitSetIterator; import org.apache.solr.common.SolrDocumentList; import org.apache.solr.common.params.ExpandParams; import org.apache.solr.common.params.ShardParams; @@ -60,13 +63,11 @@ import org.apache.solr.search.SolrIndexSearcher; import org.apache.solr.util.plugin.PluginInfoInitialized; import org.apache.solr.util.plugin.SolrCoreAware; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import com.carrotsearch.hppc.IntObjectMap; +import com.carrotsearch.hppc.IntObjectOpenHashMap; +import com.carrotsearch.hppc.IntOpenHashSet; +import com.carrotsearch.hppc.cursors.IntObjectCursor; +import com.carrotsearch.hppc.cursors.ObjectCursor; /** * The ExpandComponent is designed to work with the CollapsingPostFilter. @@ -307,7 +308,7 @@ public class ExpandComponent extends SearchComponent implements PluginInfoInitia public GroupExpandCollector(SortedDocValues docValues, FixedBitSet groupBits, IntOpenHashSet collapsedSet, int limit, Sort sort) throws IOException { int numGroups = collapsedSet.size(); groups = new IntObjectOpenHashMap<>(numGroups * 2); - DocIdSetIterator iterator = groupBits.iterator(); + DocIdSetIterator iterator = new FixedBitSetIterator(groupBits, 0); // cost is not useful here int group; while ((group = iterator.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) { Collector collector = (sort == null) ? TopScoreDocCollector.create(limit, true) : TopFieldCollector.create(sort, limit, false, false, false, true); diff --git a/solr/core/src/java/org/apache/solr/response/SortingResponseWriter.java b/solr/core/src/java/org/apache/solr/response/SortingResponseWriter.java index ee3f143c755..8c2e2b16c5a 100644 --- a/solr/core/src/java/org/apache/solr/response/SortingResponseWriter.java +++ b/solr/core/src/java/org/apache/solr/response/SortingResponseWriter.java @@ -17,11 +17,16 @@ package org.apache.solr.response; -import org.apache.lucene.index.LeafReaderContext; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.Writer; +import java.util.List; + import org.apache.lucene.index.LeafReader; +import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.MultiDocValues; -import org.apache.lucene.index.SortedDocValues; import org.apache.lucene.index.NumericDocValues; +import org.apache.lucene.index.SortedDocValues; import org.apache.lucene.index.SortedSetDocValues; import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.search.Sort; @@ -29,31 +34,27 @@ import org.apache.lucene.search.SortField; import org.apache.lucene.util.ArrayUtil; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.CharsRefBuilder; -import org.apache.lucene.util.LongValues; import org.apache.lucene.util.FixedBitSet; +import org.apache.lucene.util.FixedBitSet.FixedBitSetIterator; +import org.apache.lucene.util.LongValues; import org.apache.solr.common.params.SolrParams; import org.apache.solr.common.util.NamedList; import org.apache.solr.request.SolrQueryRequest; import org.apache.solr.request.SolrRequestInfo; +import org.apache.solr.schema.FieldType; import org.apache.solr.schema.IndexSchema; import org.apache.solr.schema.SchemaField; -import org.apache.solr.schema.FieldType; -import org.apache.solr.schema.TrieFloatField; +import org.apache.solr.schema.StrField; import org.apache.solr.schema.TrieDoubleField; +import org.apache.solr.schema.TrieFloatField; import org.apache.solr.schema.TrieIntField; import org.apache.solr.schema.TrieLongField; -import org.apache.solr.schema.StrField; import org.apache.solr.search.SolrIndexSearcher; import org.apache.solr.search.SortSpec; import org.apache.solr.search.SyntaxError; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.IOException; -import java.io.Writer; -import java.io.PrintWriter; -import java.util.List; - public class SortingResponseWriter implements QueryResponseWriter { @@ -127,8 +128,6 @@ public class SortingResponseWriter implements QueryResponseWriter { SortQueue queue = new SortQueue(queueSize, sortDoc); SortDoc[] outDocs = new SortDoc[queueSize]; - long total = 0; - while(count < totalHits) { //long begin = System.nanoTime(); boolean commaNeeded = false; @@ -136,7 +135,7 @@ public class SortingResponseWriter implements QueryResponseWriter { SortDoc top = queue.top(); for(int i=0; iBitDocSet represents an unordered set of Lucene Document Ids @@ -91,7 +92,7 @@ public class BitDocSet extends DocSetBase { @Override public DocIterator iterator() { return new DocIterator() { - private final FixedBitSetIterator iter = new FixedBitSetIterator(bits); + private final FixedBitSetIterator iter = new FixedBitSetIterator(bits, 0L); // cost is not useful here private int pos = iter.nextDoc(); @Override public boolean hasNext() { @@ -276,7 +277,7 @@ public class BitDocSet extends DocSetBase { final Bits acceptDocs2 = acceptDocs == null ? null : (reader.getLiveDocs() == acceptDocs ? null : acceptDocs); if (context.isTopLevel) { - return BitsFilteredDocIdSet.wrap(bs, acceptDocs); + return BitsFilteredDocIdSet.wrap(new FixedBitDocIdSet(bs), acceptDocs); } final int base = context.docBase; diff --git a/solr/core/src/java/org/apache/solr/search/CollapsingQParserPlugin.java b/solr/core/src/java/org/apache/solr/search/CollapsingQParserPlugin.java index 48051d3fed0..c47adf4d6de 100644 --- a/solr/core/src/java/org/apache/solr/search/CollapsingQParserPlugin.java +++ b/solr/core/src/java/org/apache/solr/search/CollapsingQParserPlugin.java @@ -22,8 +22,8 @@ import java.util.Arrays; import java.util.Iterator; import java.util.Map; -import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.DocValues; +import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.NumericDocValues; import org.apache.lucene.index.SortedDocValues; import org.apache.lucene.queries.function.FunctionQuery; @@ -35,6 +35,7 @@ import org.apache.lucene.search.Query; import org.apache.lucene.search.Scorer; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.FixedBitSet; +import org.apache.lucene.util.FixedBitSet.FixedBitSetIterator; import org.apache.solr.common.SolrException; import org.apache.solr.common.params.ModifiableSolrParams; import org.apache.solr.common.params.SolrParams; @@ -49,8 +50,8 @@ import org.apache.solr.schema.TrieIntField; import org.apache.solr.schema.TrieLongField; import com.carrotsearch.hppc.FloatArrayList; -import com.carrotsearch.hppc.IntOpenHashSet; import com.carrotsearch.hppc.IntIntOpenHashMap; +import com.carrotsearch.hppc.IntOpenHashSet; import com.carrotsearch.hppc.cursors.IntIntCursor; /** @@ -490,7 +491,7 @@ public class CollapsingQParserPlugin extends QParserPlugin { leafDelegate = delegate.getLeafCollector(contexts[currentContext]); DummyScorer dummy = new DummyScorer(); leafDelegate.setScorer(dummy); - DocIdSetIterator it = collapsedSet.iterator(); + DocIdSetIterator it = new FixedBitSetIterator(collapsedSet, 0L); // cost is not useful here int docId = -1; int nullScoreIndex = 0; while((docId = it.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) { @@ -603,7 +604,7 @@ public class CollapsingQParserPlugin extends QParserPlugin { leafDelegate = delegate.getLeafCollector(contexts[currentContext]); DummyScorer dummy = new DummyScorer(); leafDelegate.setScorer(dummy); - DocIdSetIterator it = fieldValueCollapse.getCollapsedSet().iterator(); + DocIdSetIterator it = new FixedBitSetIterator(fieldValueCollapse.getCollapsedSet(), 0); // cost is not useful here int docId = -1; int nullScoreIndex = 0; float[] scores = fieldValueCollapse.getScores(); diff --git a/solr/core/src/java/org/apache/solr/search/DocSetBase.java b/solr/core/src/java/org/apache/solr/search/DocSetBase.java index af074050bdf..66f220ed3fb 100644 --- a/solr/core/src/java/org/apache/solr/search/DocSetBase.java +++ b/solr/core/src/java/org/apache/solr/search/DocSetBase.java @@ -24,6 +24,7 @@ import org.apache.lucene.search.DocIdSet; import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.search.Filter; import org.apache.lucene.util.Bits; +import org.apache.lucene.util.FixedBitDocIdSet; import org.apache.lucene.util.FixedBitSet; import org.apache.solr.common.SolrException; @@ -171,7 +172,7 @@ abstract class DocSetBase implements DocSet { final Bits acceptDocs2 = acceptDocs == null ? null : (reader.getLiveDocs() == acceptDocs ? null : acceptDocs); if (context.isTopLevel) { - return BitsFilteredDocIdSet.wrap(bs, acceptDocs); + return BitsFilteredDocIdSet.wrap(new FixedBitDocIdSet(bs), acceptDocs); } final int base = context.docBase; diff --git a/solr/core/src/test/org/apache/solr/search/TestDocSet.java b/solr/core/src/test/org/apache/solr/search/TestDocSet.java index 669dbd9d42c..a3e44d1b12f 100644 --- a/solr/core/src/test/org/apache/solr/search/TestDocSet.java +++ b/solr/core/src/test/org/apache/solr/search/TestDocSet.java @@ -22,14 +22,14 @@ import java.util.Arrays; import java.util.List; import java.util.Random; -import org.apache.lucene.index.LeafReader; -import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.BinaryDocValues; import org.apache.lucene.index.FieldInfo; import org.apache.lucene.index.FieldInfos; import org.apache.lucene.index.Fields; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexReaderContext; +import org.apache.lucene.index.LeafReader; +import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.MultiReader; import org.apache.lucene.index.NumericDocValues; import org.apache.lucene.index.SortedDocValues; @@ -68,7 +68,7 @@ public class TestDocSet extends LuceneTestCase { public DocSet getHashDocSet(FixedBitSet bs) { int[] docs = new int[bs.cardinality()]; - FixedBitSetIterator iter = new FixedBitSetIterator(bs); + FixedBitSetIterator iter = new FixedBitSetIterator(bs, 0); for (int i=0; i=offset; i--) { arr[i] = iter.nextDoc(); diff --git a/solr/core/src/test/org/apache/solr/search/TestSort.java b/solr/core/src/test/org/apache/solr/search/TestSort.java index d6dac480cdd..a5949df2105 100644 --- a/solr/core/src/test/org/apache/solr/search/TestSort.java +++ b/solr/core/src/test/org/apache/solr/search/TestSort.java @@ -30,18 +30,18 @@ import org.apache.lucene.analysis.core.SimpleAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.StringField; -import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; -import org.apache.lucene.search.LeafCollector; +import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.search.BitsFilteredDocIdSet; import org.apache.lucene.search.Collector; import org.apache.lucene.search.DocIdSet; import org.apache.lucene.search.Filter; -import org.apache.lucene.search.FilterLeafCollector; import org.apache.lucene.search.FilterCollector; +import org.apache.lucene.search.FilterLeafCollector; import org.apache.lucene.search.IndexSearcher; +import org.apache.lucene.search.LeafCollector; import org.apache.lucene.search.MatchAllDocsQuery; import org.apache.lucene.search.ScoreDoc; import org.apache.lucene.search.Sort; @@ -53,6 +53,7 @@ import org.apache.lucene.store.Directory; import org.apache.lucene.store.RAMDirectory; import org.apache.lucene.uninverting.UninvertingReader; import org.apache.lucene.util.Bits; +import org.apache.lucene.util.FixedBitDocIdSet; import org.apache.lucene.util.FixedBitSet; import org.apache.lucene.util.TestUtil; import org.apache.solr.SolrTestCaseJ4; @@ -339,7 +340,7 @@ public class TestSort extends SolrTestCaseJ4 { for (int i=0; i=0; next=iterator.nextDoc()) { ret += next; }