Search in sources :

Example 11 with BitDocIdSet

use of org.apache.lucene.util.BitDocIdSet in project lucene-solr by apache.

the class TestConjunctionDISI method testRecursiveConjunctionApproximation.

// This test makes sure that when nesting scorers with ConjunctionDISI, confirmations are pushed to the root.
public void testRecursiveConjunctionApproximation() throws IOException {
    final int iters = atLeast(100);
    for (int iter = 0; iter < iters; ++iter) {
        final int maxDoc = TestUtil.nextInt(random(), 100, 10000);
        final int numIterators = TestUtil.nextInt(random(), 2, 5);
        final FixedBitSet[] sets = new FixedBitSet[numIterators];
        Scorer conjunction = null;
        boolean hasApproximation = false;
        for (int i = 0; i < numIterators; ++i) {
            final FixedBitSet set = randomSet(maxDoc);
            final Scorer newIterator;
            switch(random().nextInt(3)) {
                case 0:
                    // simple iterator
                    sets[i] = set;
                    newIterator = new ConstantScoreScorer(null, 0f, anonymizeIterator(new BitDocIdSet(set).iterator()));
                    break;
                case 1:
                    // bitSet iterator
                    sets[i] = set;
                    newIterator = new ConstantScoreScorer(null, 0f, new BitDocIdSet(set).iterator());
                    break;
                default:
                    // scorer with approximation
                    final FixedBitSet confirmed = clearRandomBits(set);
                    sets[i] = confirmed;
                    final TwoPhaseIterator approximation = approximation(new BitDocIdSet(set).iterator(), confirmed);
                    newIterator = scorer(approximation);
                    hasApproximation = true;
                    break;
            }
            if (conjunction == null) {
                conjunction = newIterator;
            } else {
                final DocIdSetIterator conj = ConjunctionDISI.intersectScorers(Arrays.asList(conjunction, newIterator));
                conjunction = scorer(conj, TwoPhaseIterator.unwrap(conj));
            }
        }
        TwoPhaseIterator twoPhaseIterator = conjunction.twoPhaseIterator();
        assertEquals(hasApproximation, twoPhaseIterator != null);
        if (hasApproximation) {
            assertEquals(intersect(sets), toBitSet(maxDoc, TwoPhaseIterator.asDocIdSetIterator(twoPhaseIterator)));
        } else {
            assertEquals(intersect(sets), toBitSet(maxDoc, conjunction.iterator()));
        }
    }
}
Also used : BitDocIdSet(org.apache.lucene.util.BitDocIdSet) FixedBitSet(org.apache.lucene.util.FixedBitSet)

Aggregations

BitDocIdSet (org.apache.lucene.util.BitDocIdSet)11 FixedBitSet (org.apache.lucene.util.FixedBitSet)10 DocIdSet (org.apache.lucene.search.DocIdSet)4 IOException (java.io.IOException)3 LeafReader (org.apache.lucene.index.LeafReader)3 DocIdSetIterator (org.apache.lucene.search.DocIdSetIterator)3 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)2 Bits (org.apache.lucene.util.Bits)2 LinkedList (java.util.LinkedList)1 IndexReader (org.apache.lucene.index.IndexReader)1 IndexReaderContext (org.apache.lucene.index.IndexReaderContext)1 IndexSearcher (org.apache.lucene.search.IndexSearcher)1 Scorer (org.apache.lucene.search.Scorer)1 Weight (org.apache.lucene.search.Weight)1 Cell (org.apache.lucene.spatial.prefix.tree.Cell)1 CellIterator (org.apache.lucene.spatial.prefix.tree.CellIterator)1 SpatialRelation (org.locationtech.spatial4j.shape.SpatialRelation)1