Package org.apache.lucene.queries.spans

## Class Spans

- java.lang.Object
- - org.apache.lucene.search.DocIdSetIterator
  - - org.apache.lucene.queries.spans.Spans

- Direct Known Subclasses:
    `FilterSpans`, `NearSpansOrdered`, `NearSpansUnordered`, `TermSpans`

      public abstract class Spans
      extends DocIdSetIterator

  Iterates through combinations of start/end positions per-doc. Each start/end position represents a range of term positions within the current document. These are enumerated in order, by increasing document number, within that by increasing start position and finally by increasing end position.

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `static int` | `NO_MORE_POSITIONS` |

    - ### Fields inherited from class org.apache.lucene.search.DocIdSetIterator

      `NO_MORE_DOCS`

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `Spans()` |

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `TwoPhaseIterator` | `asTwoPhaseIterator()` | Optional method: Return a `TwoPhaseIterator` view of this `Scorer`.
    `abstract void` | `collect​(SpanCollector collector)` | Collect postings data from the leaves of the current Spans.
    `protected void` | `doCurrentSpans()` | Called each time the scorer's SpanScorer is advanced during frequency calculation
    `protected void` | `doStartCurrentDoc()` | Called before the current doc's frequency is calculated
    `abstract int` | `endPosition()` | Returns the end position for the current start position, or -1 when `nextStartPosition()` was not yet called on the current doc.
    `abstract int` | `nextStartPosition()` | Returns the next start position for the current doc.
    `abstract float` | `positionsCost()` | Return an estimation of the cost of using the positions of this `Spans` for any single document, but only after `asTwoPhaseIterator()` returned `null`.
    `abstract int` | `startPosition()` | Returns the start position in the current doc, or -1 when `nextStartPosition()` was not yet called on the current doc.
    `String` | `toString()` |
    `abstract int` | `width()` | Return the width of the match, which is typically used to sloppy freq.

    - ### Methods inherited from class org.apache.lucene.search.DocIdSetIterator

      `advance, all, cost, docID, empty, nextDoc, range, slowAdvance`

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

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

- - ### Field Detail

    - #### NO_MORE_POSITIONS

          public static final int NO_MORE_POSITIONS

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### Spans

          public Spans()

  - ### Method Detail

    - #### nextStartPosition

          public abstract int nextStartPosition()
                                         throws IOException

      Returns the next start position for the current doc. There is always at least one start/end position per doc. After the last start/end position at the current doc this returns `NO_MORE_POSITIONS`.
      Throws:
        `IOException`

    - #### startPosition

          public abstract int startPosition()

      Returns the start position in the current doc, or -1 when `nextStartPosition()` was not yet called on the current doc. After the last start/end position at the current doc this returns `NO_MORE_POSITIONS`.

    - #### endPosition

          public abstract int endPosition()

      Returns the end position for the current start position, or -1 when `nextStartPosition()` was not yet called on the current doc. After the last start/end position at the current doc this returns `NO_MORE_POSITIONS`.

    - #### width

          public abstract int width()

      Return the width of the match, which is typically used to sloppy freq. It is only legal to call this method when the iterator is on a valid doc ID and positioned. The return value must be positive, and lower values means that the match is better.

    - #### collect

          public abstract void collect​(SpanCollector collector)
                                throws IOException

      Collect postings data from the leaves of the current Spans.

      This method should only be called after `nextStartPosition()`, and before `NO_MORE_POSITIONS` has been reached.

      Parameters:
        `collector` - a SpanCollector
      Throws:
        `IOException`
      WARNING: This API is experimental and might change in incompatible ways in the next release.

    - #### positionsCost

          public abstract float positionsCost()

      Return an estimation of the cost of using the positions of this `Spans` for any single document, but only after `asTwoPhaseIterator()` returned `null`. Otherwise this method should not be called. The returned value is independent of the current document.
      WARNING: This API is experimental and might change in incompatible ways in the next release.

    - #### asTwoPhaseIterator

          public TwoPhaseIterator asTwoPhaseIterator()

      Optional method: Return a `TwoPhaseIterator` view of this `Scorer`. A return value of `null` indicates that two-phase iteration is not supported.
      See Also:
        `Scorer.twoPhaseIterator()`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### doStartCurrentDoc

          protected void doStartCurrentDoc()
                                    throws IOException

      Called before the current doc's frequency is calculated
      Throws:
        `IOException`

    - #### doCurrentSpans

          protected void doCurrentSpans()
                                 throws IOException

      Called each time the scorer's SpanScorer is advanced during frequency calculation
      Throws:
        `IOException`