Refine search
private int firstDocFromNextBlock() throws IOException { while (true) { block += 1; if (block >= docIdSets.length) { sub = null; return doc = NO_MORE_DOCS; } else if (docIdSets[block] != null) { sub = docIdSets[block].iterator(); final int subNext = sub.nextDoc(); assert subNext != NO_MORE_DOCS; return doc = (block << 16) | subNext; } } }
@Override public Bits bits() throws IOException { final Bits inBits = in.bits(); if (inBits == null) { return null; } return new Bits() { @Override public boolean get(int index) { return !inBits.get(index); } @Override public int length() { return inBits.length(); } }; }
@Override public long ramBytesUsed() { return BASE_RAM_BYTES_USED + in.ramBytesUsed(); }
DocIdSetIterator docIdSetIterator = entry.docIdSet.iterator(); if (docIdSetIterator == null) { continue; while ((docID = docIdSetIterator.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) { if (needsScores) { assert scorerIt != null && scorerIt.docID() < docID; scorerIt.advance(docID); assert scorerIt.docID() == docID;
/** * Returns a cacheable version of the given set of document ids. Optimized * for cases where the target doc id set is sparse, specifically when less * than 1/32 of the documents match the input. * @param docIdSet the set to make cacheable. * @return the cacheable version. * @throws IOException if IO errors occur. */ public static DocIdSet cacheableSparse(@Nullable final DocIdSet docIdSet) throws IOException { if (docIdSet == null) { return DocIdSet.EMPTY_DOCIDSET; } else if (docIdSet.isCacheable()) { return docIdSet; } else { DocIdSetIterator it = docIdSet.iterator(); IntList docIds = new ArrayIntList(); // null is allowed to be returned by iterator(), // in this case we wrap with the empty set, // which is cacheable. if (it == null) { return DocIdSet.EMPTY_DOCIDSET; } else { while (it.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) { docIds.add(it.docID()); } return new IntListDocIdSet(docIds); } } }
@Override public DocIdSetIterator iterator() throws IOException { final DocIdSetIterator inIterator = in.iterator(); return new DocIdSetIterator() {
/** * Provide the DocIdSet to be cached, using the DocIdSet provided * by the wrapped Filter. <p>This implementation returns the given {@link DocIdSet}, * if {@link DocIdSet#isCacheable} returns <code>true</code>, else it calls * {@link #cacheImpl(DocIdSetIterator, org.apache.lucene.index.LeafReader)} * <p>Note: This method returns {@linkplain DocIdSet#EMPTY} if the given docIdSet * is <code>null</code> or if {@link DocIdSet#iterator()} return <code>null</code>. The empty * instance is use as a placeholder in the cache instead of the <code>null</code> value. */ protected DocIdSet docIdSetToCache(DocIdSet docIdSet, LeafReader reader) throws IOException { if (docIdSet == null || docIdSet.isCacheable()) { return docIdSet; } else { final DocIdSetIterator it = docIdSet.iterator(); if (it == null) { return null; } else { return cacheImpl(it, reader); } } }
@Override public int advance(int target) throws IOException { final int targetBlock = target >>> 16; if (targetBlock != block) { block = targetBlock; if (block >= docIdSets.length) { sub = null; return doc = NO_MORE_DOCS; } if (docIdSets[block] == null) { return firstDocFromNextBlock(); } sub = docIdSets[block].iterator(); } final int subNext = sub.advance(target & 0xFFFF); if (subNext == NO_MORE_DOCS) { return firstDocFromNextBlock(); } return doc = (block << 16) | subNext; }
return null; final Bits bits = set.bits(); boolean useRandomAccess = bits != null && strategy.alwaysUseRandomAccess(); final DocIdSetIterator iterator; iterator = set.iterator(); if (iterator == null) { return null; useRandomAccess = strategy.useRandomAccess(bits, iterator.cost()); final DocIdSetIterator approximation = DocIdSetIterator.all(context.reader().maxDoc()); final TwoPhaseIterator twoPhase = new TwoPhaseIterator(approximation) { @Override
public Explanation explain (IndexReader ir, int i) throws IOException { Explanation inner = weight.explain (ir, i); if (getBoost()!=1) { Explanation preBoost = inner; inner = new Explanation(inner.getValue()*getBoost(),"product of:"); inner.addDetail(new Explanation(getBoost(),"boost")); inner.addDetail(preBoost); } Filter f = FilteredQuery.this.filter; DocIdSetIterator docIdSetIterator = f.getDocIdSet(ir).iterator(); if (docIdSetIterator.skipTo(i) && (docIdSetIterator.doc() == i)) { return inner; } else { Explanation result = new Explanation (0.0f, "failure to match filter: " + f.toString()); result.addDetail(inner); return result; } }
/** This DocIdSet implementation is cacheable if the inner set is cacheable. */ @Override public boolean isCacheable() { return _innerSet.isCacheable(); }
@Test public void testIteratorMatchesTestArray() throws IOException { DocIdSet docIdSet0_9 = arrayToDocIdSet( testDataFrom0to9 ); DocIdSetIterator docIdSetIterator = docIdSet0_9.iterator(); assertTrue( docIdSetIterator.nextDoc() != DocIdSetIterator.NO_MORE_DOCS ); assertEquals( 0, docIdSetIterator.docID() ); assertEquals( 9, docIdSetIterator.advance( 9 ) ); assertEquals( DocIdSetIterator.NO_MORE_DOCS, docIdSetIterator.advance( 10 ) ); }
currentIdIterator = currentDocs.docIdSet.iterator(); if ( currentIdIterator != null )
/** * Provide the DocIdSet to be cached, using the DocIdSet provided * by the wrapped Filter. <p>This implementation returns the given {@link DocIdSet}, * if {@link DocIdSet#isCacheable} returns <code>true</code>, else it calls * {@link #cacheImpl(DocIdSetIterator, org.apache.lucene.index.LeafReader)} * <p>Note: This method returns {@linkplain DocIdSet#EMPTY} if the given docIdSet * is <code>null</code> or if {@link DocIdSet#iterator()} return <code>null</code>. The empty * instance is use as a placeholder in the cache instead of the <code>null</code> value. */ protected DocIdSet docIdSetToCache(DocIdSet docIdSet, LeafReader reader) throws IOException { if (docIdSet == null || docIdSet.isCacheable()) { return docIdSet; } else { final DocIdSetIterator it = docIdSet.iterator(); if (it == null) { return null; } else { return cacheImpl(it, reader); } } }
/** * Check if the given doc id set contains the given doc id. * @param docIdSet the doc id set * @param docId the doc id * @return whether the given doc id set contains the given doc id * @throws IOException if IO errors occur */ public static boolean contains( @Nullable final DocIdSet docIdSet, final int docId) throws IOException { if (docIdSet == null) { return false; } if (docIdSet instanceof FixedBitSet) { return ((FixedBitSet) docIdSet).get(docId); } return docIdSet.iterator().advance(docId) == docId; }
public Explanation explain (IndexReader ir, int i) throws IOException { Explanation inner = weight.explain (ir, i); if (getBoost()!=1) { Explanation preBoost = inner; inner = new Explanation(inner.getValue()*getBoost(),"product of:"); inner.addDetail(new Explanation(getBoost(),"boost")); inner.addDetail(preBoost); } Filter f = FilteredQuery.this.filter; DocIdSetIterator docIdSetIterator = f.getDocIdSet(ir).iterator(); if (docIdSetIterator.skipTo(i) && (docIdSetIterator.doc() == i)) { return inner; } else { Explanation result = new Explanation (0.0f, "failure to match filter: " + f.toString()); result.addDetail(inner); return result; } }
static boolean isCheapToCache(DocIdSet set) { // the produced doc set is already cacheable, so caching has no // overhead at all. TODO: extend this to sets whose iterators have a low // cost? return set == null || set.isCacheable(); }
private void replayTo( Collector collector ) throws IOException { for ( MatchingDocs docs : getMatchingDocs() ) { LeafCollector leafCollector = collector.getLeafCollector( docs.context ); Scorer scorer; DocIdSetIterator idIterator = docs.docIdSet.iterator(); if ( isKeepScores() ) { scorer = new ReplayingScorer( docs.scores ); } else { scorer = new ConstantScoreScorer( null, Float.NaN, idIterator ); } leafCollector.setScorer( scorer ); int doc; while ( (doc = idIterator.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS ) { leafCollector.collect( doc ); } } }
private Scorer scorer(DocIdSet set) throws IOException { if (set == null) { return null; } final DocIdSetIterator disi = set.iterator(); if (disi == null) { return null; } return new ConstantScoreScorer(this, score(), disi); }
/** * Provide the DocIdSet to be cached, using the DocIdSet provided * by the wrapped Filter. <p>This implementation returns the given {@link DocIdSet}, * if {@link DocIdSet#isCacheable} returns <code>true</code>, else it calls * {@link #cacheImpl(DocIdSetIterator, org.apache.lucene.index.LeafReader)} * <p>Note: This method returns {@linkplain DocIdSet#EMPTY} if the given docIdSet * is <code>null</code> or if {@link DocIdSet#iterator()} return <code>null</code>. The empty * instance is use as a placeholder in the cache instead of the <code>null</code> value. */ protected DocIdSet docIdSetToCache(DocIdSet docIdSet, LeafReader reader) throws IOException { if (docIdSet == null || docIdSet.isCacheable()) { return docIdSet; } else { final DocIdSetIterator it = docIdSet.iterator(); if (it == null) { return null; } else { return cacheImpl(it, reader); } } }