Class AcceptDocs

java.lang.Object
org.apache.lucene.search.AcceptDocs

public abstract class AcceptDocs extends Object
Higher-level abstraction for document acceptance filtering. Can be consumed in either random-access (Bits) or sequential (DocIdSetIterator) pattern.
WARNING: This API is experimental and might change in incompatible ways in the next release.
  • Constructor Details

    • AcceptDocs

      public AcceptDocs()
  • Method Details

    • bits

      public abstract Bits bits() throws IOException
      Random access to the accepted documents.
      Returns:
      Bits instance for random access, or null if all documents are accepted
      Throws:
      IOException - if an I/O error occurs
    • iterator

      public abstract DocIdSetIterator iterator() throws IOException
      Create a new iterator of accepted docs. There accepted docs already ignore deleted docs.

      NOTE: If you also plan on calling bits() or cost(), it is recommended to call these methods before iterator() for better performance.

      Returns:
      DocIdSetIterator for sequential access
      Throws:
      IOException - if an I/O error occurs
    • cost

      public abstract int cost() throws IOException
      Return an approximation of the number of accepted documents. This is typically useful to decide whether to consume these accept docs using random access (bits()) or sequential access (iterator()).

      NOTE: This must not be called after iterator().

      Returns:
      approximate cost
      Throws:
      IOException
    • fromLiveDocs

      public static AcceptDocs fromLiveDocs(Bits bits, int maxDoc)
      Create AcceptDocs from a Bits instance representing live documents. A null instance is interpreted as matching all documents, like in LeafReader.getLiveDocs().
      Parameters:
      bits - the Bits instance for random access
      maxDoc - the number of documents in the reader
      Returns:
      AcceptDocs wrapping the Bits
    • fromIteratorSupplier

      public static AcceptDocs fromIteratorSupplier(IOSupplier<DocIdSetIterator> iteratorSupplier, Bits liveDocs, int maxDoc)
      Create AcceptDocs from an IOSupplier of DocIdSetIterator, optionally filtered by live documents.
      Parameters:
      iteratorSupplier - a DocIdSetIterator iterator
      liveDocs - Bits representing live documents, or null if no deleted docs.
      maxDoc - the number of documents in the reader
      Returns:
      AcceptDocs wrapping the iterator