@Override protected boolean match( int doc ) { return liveDocs.get( doc ); } };
@Override public int nextDoc() { docID++; while (docID < maxDoc) { if (docsWithField.get(docID)) { return docID; } docID++; } docID = NO_MORE_DOCS; return NO_MORE_DOCS; }
@Override public boolean advanceExact(int target) throws IOException { docID = target; return docsWithField.get(target); }
@Override public boolean get(int index) { return !inBits.get(index); }
@Override public boolean advanceExact(int target) throws IOException { docID = target; value = values.get(docID); return value != 0 || docsWithField.get(docID); }
@Override public boolean get(int doc) { FutureObjects.checkIndex(doc, length); return parent.get(doc+start); }
@Override public int get(int docID) { if (liveDocs == null) { return docBase + docID; } else if (liveDocs.get(docID)) { return docBase + (int) delDocMap.get(docID); } else { return -1; } } };
@Override public int get(int docID) { if (liveDocs == null || liveDocs.get(docID)) { return (int) remapped.get(docID); } else { return -1; } } };
@Override public boolean get(int index) { return in.get(docMap.newToOld(index)); }
@Override public int nextDoc() { docID++; while (docID < maxDoc) { value = values.get(docID); if (value != 0 || docsWithField.get(docID)) { return docID; } docID++; } docID = NO_MORE_DOCS; return NO_MORE_DOCS; }
static int countSoftDeletes(DocIdSetIterator softDeletedDocs, Bits hardDeletes) throws IOException { int count = 0; if (softDeletedDocs != null) { int doc; while ((doc = softDeletedDocs.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) { if (hardDeletes == null || hardDeletes.get(doc)) { count++; } } } return count; } }
private boolean assertCheckLiveDocs(Bits bits, int expectedLength, int expectedDeleteCount) { assert bits.length() == expectedLength; int deletedCount = 0; for (int i = 0; i < bits.length(); i++) { if (bits.get(i) == false) { deletedCount++; } } assert deletedCount == expectedDeleteCount : "deleted: " + deletedCount + " != expected: " + expectedDeleteCount; return true; }
@Override public boolean get(int doc) { final int reader = ReaderUtil.subIndex(doc, starts); assert reader != -1; final Bits bits = subs[reader]; if (bits == null) { return defaultValue; } else { assert checkLength(reader, doc); return bits.get(doc-starts[reader]); } }
static PackedLongValues removeDeletes(final int maxDoc, final Bits liveDocs) { final PackedLongValues.Builder docMapBuilder = PackedLongValues.monotonicBuilder(PackedInts.COMPACT); int del = 0; for (int i = 0; i < maxDoc; ++i) { docMapBuilder.add(i - del); if (liveDocs.get(i) == false) { ++del; } } return docMapBuilder.build(); } }
/** Expert: low-level implementation method * Returns an Explanation that describes how <code>doc</code> scored against * <code>weight</code>. * * <p>This is intended to be used in developing Similarity implementations, * and, for good performance, should not be displayed with every hit. * Computing an explanation is as expensive as executing the query over the * entire index. * <p>Applications should call {@link IndexSearcher#explain(Query, int)}. * @throws BooleanQuery.TooManyClauses If a query would exceed * {@link BooleanQuery#getMaxClauseCount()} clauses. */ protected Explanation explain(Weight weight, int doc) throws IOException { int n = ReaderUtil.subIndex(doc, leafContexts); final LeafReaderContext ctx = leafContexts.get(n); int deBasedDoc = doc - ctx.docBase; final Bits liveDocs = ctx.reader().getLiveDocs(); if (liveDocs != null && liveDocs.get(deBasedDoc) == false) { return Explanation.noMatch("Document " + doc + " is deleted"); } return weight.explain(ctx, deBasedDoc); }
/** Specialized method to bulk-score all hits; we * separate this from {@link #scoreRange} to help out * hotspot. * See <a href="https://issues.apache.org/jira/browse/LUCENE-5487">LUCENE-5487</a> */ static void scoreAll(LeafCollector collector, DocIdSetIterator iterator, TwoPhaseIterator twoPhase, Bits acceptDocs) throws IOException { if (twoPhase == null) { for (int doc = iterator.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = iterator.nextDoc()) { if (acceptDocs == null || acceptDocs.get(doc)) { collector.collect(doc); } } } else { // The scorer has an approximation, so run the approximation first, then check acceptDocs, then confirm final DocIdSetIterator approximation = twoPhase.approximation(); for (int doc = approximation.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = approximation.nextDoc()) { if ((acceptDocs == null || acceptDocs.get(doc)) && twoPhase.matches()) { collector.collect(doc); } } } } }
private FixedBitSet sortLiveDocs(Bits liveDocs, Sorter.DocMap sortMap) throws IOException { assert liveDocs != null && sortMap != null; FixedBitSet sortedLiveDocs = new FixedBitSet(liveDocs.length()); sortedLiveDocs.set(0, liveDocs.length()); for (int i = 0; i < liveDocs.length(); i++) { if (liveDocs.get(i) == false) { sortedLiveDocs.clear(sortMap.oldToNew(i)); } } return sortedLiveDocs; }
/** * Make a copy of the given bits. */ public static FixedBitSet copyOf(Bits bits) { if (bits instanceof FixedBits) { // restore the original FixedBitSet FixedBits fixedBits = (FixedBits) bits; bits = new FixedBitSet(fixedBits.bits, fixedBits.length); } if (bits instanceof FixedBitSet) { return ((FixedBitSet)bits).clone(); } else { int length = bits.length(); FixedBitSet bitSet = new FixedBitSet(length); bitSet.set(0, length); for (int i = 0; i < length; ++i) { if (bits.get(i) == false) { bitSet.clear(i); } } return bitSet; } }
boolean verifyDocCounts(CodecReader reader) { int count = 0; Bits liveDocs = getLiveDocs(); if (liveDocs != null) { for(int docID = 0; docID < info.info.maxDoc(); docID++) { if (liveDocs.get(docID)) { count++; } } } else { count = info.info.maxDoc(); } assert numDocs() == count: "info.maxDoc=" + info.info.maxDoc() + " info.getDelCount()=" + info.getDelCount() + " info.getSoftDelCount()=" + info.getSoftDelCount() + " pendingDeletes=" + toString() + " count=" + count + " numDocs: " + numDocs(); assert reader.numDocs() == numDocs() : "reader.numDocs() = " + reader.numDocs() + " numDocs() " + numDocs(); assert reader.numDeletedDocs() <= info.info.maxDoc(): "delCount=" + reader.numDeletedDocs() + " info.maxDoc=" + info.info.maxDoc() + " rld.pendingDeleteCount=" + numPendingDeletes() + " info.getDelCount()=" + info.getDelCount(); return true; }