org.apache.lucene.util

## Class DocIdSetBuilder

- java.lang.Object
- - org.apache.lucene.util.DocIdSetBuilder

-     public final class DocIdSetBuilder
      extends Object

  A builder of `DocIdSet`s. At first it uses a sparse structure to gather documents, and then upgrades to a non-sparse bit set once enough hits match.
  NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `DocIdSetBuilder(int maxDoc)` Create a builder that can contain doc IDs between `0` and `maxDoc`.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `add(DocIdSetIterator iter)` Add the content of the provided `DocIdSetIterator` to this builder.
    `void` | `add(int doc)` Add a document to this builder.
    `DocIdSet` | `build()` Build a `DocIdSet` from the accumulated doc IDs.
    `DocIdSet` | `build(long costHint)` Expert: build a `DocIdSet` with a hint on the cost that the resulting `DocIdSet` would have.
    `void` | `grow(int numDocs)` Reserve space so that this builder can hold `numDocs` MORE documents.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### DocIdSetBuilder

          public DocIdSetBuilder(int maxDoc)

      Create a builder that can contain doc IDs between `0` and `maxDoc`.

  - ### Method Detail

    - #### add

          public void add(DocIdSetIterator iter)
                   throws IOException

      Add the content of the provided `DocIdSetIterator` to this builder. NOTE: if you need to build a `DocIdSet` out of a single `DocIdSetIterator`, you should rather use `RoaringDocIdSet.Builder`.
      Throws:
        `IOException`

    - #### grow

          public void grow(int numDocs)

      Reserve space so that this builder can hold `numDocs` MORE documents.

    - #### add

          public void add(int doc)

      Add a document to this builder. NOTE: doc IDs do not need to be provided in order. NOTE: if you plan on adding several docs at once, look into using `grow(int)` to reserve space.

    - #### build

          public DocIdSet build()

      Build a `DocIdSet` from the accumulated doc IDs.

    - #### build

          public DocIdSet build(long costHint)

      Expert: build a `DocIdSet` with a hint on the cost that the resulting `DocIdSet` would have.

Copyright © 2000-2017 Apache Software Foundation. All Rights Reserved.