List of usage examples for org.apache.lucene.util BitSet nextSetBit
public abstract int nextSetBit(int index);
From source file:org.codelibs.elasticsearch.search.aggregations.bucket.nested.ReverseNestedAggregator.java
License:Apache License
@Override protected LeafBucketCollector getLeafCollector(LeafReaderContext ctx, final LeafBucketCollector sub) throws IOException { // In ES if parent is deleted, then also the children are deleted, so the child docs this agg receives // must belong to parent docs that is alive. For this reason acceptedDocs can be null here. final BitSet parentDocs = parentBitsetProducer.getBitSet(ctx); if (parentDocs == null) { return LeafBucketCollector.NO_OP_COLLECTOR; }//from www. j a va 2 s . co m final LongIntHashMap bucketOrdToLastCollectedParentDoc = new LongIntHashMap(32); return new LeafBucketCollectorBase(sub, null) { @Override public void collect(int childDoc, long bucket) throws IOException { // fast forward to retrieve the parentDoc this childDoc belongs to final int parentDoc = parentDocs.nextSetBit(childDoc); assert childDoc <= parentDoc && parentDoc != DocIdSetIterator.NO_MORE_DOCS; int keySlot = bucketOrdToLastCollectedParentDoc.indexOf(bucket); if (bucketOrdToLastCollectedParentDoc.indexExists(keySlot)) { int lastCollectedParentDoc = bucketOrdToLastCollectedParentDoc.indexGet(keySlot); if (parentDoc > lastCollectedParentDoc) { collectBucket(sub, parentDoc, bucket); bucketOrdToLastCollectedParentDoc.indexReplace(keySlot, parentDoc); } } else { collectBucket(sub, parentDoc, bucket); bucketOrdToLastCollectedParentDoc.indexInsert(keySlot, bucket, parentDoc); } } }; }
From source file:org.elasticsearch.index.shard.ShardSplittingQuery.java
License:Apache License
private void markChildDocs(BitSet parentDocs, BitSet matchingDocs) { int currentDeleted = 0; while (currentDeleted < matchingDocs.length() && (currentDeleted = matchingDocs.nextSetBit(currentDeleted)) != DocIdSetIterator.NO_MORE_DOCS) { int previousParent = parentDocs.prevSetBit(Math.max(0, currentDeleted - 1)); for (int i = previousParent + 1; i < currentDeleted; i++) { matchingDocs.set(i);/* www. j a va 2 s. c o m*/ } currentDeleted++; } }