@@ -0,0 +1,2271 @@
+/*%0A * Copyright 2012 Greplin, Inc. All Rights Reserved.%0A */%0A%0Apackage com.greplin.lucene.query;%0A%0Aimport org.apache.lucene.search.DocIdSet;%0Aimport org.apache.lucene.search.DocIdSetIterator;%0A%0Aimport java.io.IOException;%0A%0A/**%0A* A sub-slice of a DocIdSet.%0A*/%0Apublic class DocIdSetSlice extends DocIdSet %7B%0A%0A  /**%0A   * The underlying DocIdSet.%0A   */%0A  private final DocIdSet underlying;%0A%0A  /**%0A   * The start of the slice.%0A   */%0A  private final int start;%0A%0A  /**%0A   * The end of the slice.%0A   */%0A  private final int end;%0A%0A%0A  /**%0A   * Constructs a DocIdSet that is a slice of another DocIdSet.%0A   * @param underlying the underlying DocIdSet%0A   * @param start the start of the slice%0A   * @param end the end of the slice%0A   */%0A  public DocIdSetSlice(%0A      final DocIdSet underlying, final int start, final int end) %7B%0A    assert start %3E= 0;%0A    assert end %3E= start;%0A    this.underlying = underlying;%0A    this.start = start;%0A    this.end = end;%0A  %7D%0A%0A%0A  /**%0A   * Internal iterator implementation for slices.%0A   */%0A  private final class Iterator extends DocIdSetIterator %7B%0A%0A    /**%0A     * The underlying iterator.%0A     */%0A    private final DocIdSetIterator underlying;%0A%0A%0A    /**%0A     * Constructs an iterator.%0A     * @throws IOException if IO errors are encountered.%0A     */%0A    private Iterator() throws IOException %7B%0A      this.underlying = DocIdSetSlice.this.underlying.iterator();%0A    %7D%0A%0A%0A    @Override%0A    public int docID() %7B%0A      int docId = this.underlying.docID();%0A      return docId %3C DocIdSetSlice.this.end%0A          ? docId - DocIdSetSlice.this.start : NO_MORE_DOCS;%0A    %7D%0A%0A%0A    @Override%0A    public int nextDoc() throws IOException %7B%0A      if (this.underlying.docID() == -1) %7B%0A        this.underlying.advance(DocIdSetSlice.this.start);%0A      %7D else %7B%0A        this.underlying.nextDoc();%0A      %7D%0A      return docID();%0A    %7D%0A%0A%0A    @Override%0A    public int advance(final int target) throws IOException %7B%0A      if (target == Integer.MAX_VALUE) %7B%0A        this.underlying.advance(target);%0A        return docID();%0A      %7D%0A      assert DocIdSetSlice.this.start + target %3E= 0;%0A      this.underlying.advance(DocIdSetSlice.this.start + target);%0A      return docID();%0A    %7D%0A  %7D%0A%0A  @Override%0A  public DocIdSetIterator iterator() throws IOException %7B%0A    return new Iterator();%0A  %7D%0A%0A%7D%0A

Add utility for sub-slices of DocIdSets