/**
  * Check whether two Spans in the same document are ordered with possible overlap.
  *
  * @return true iff spans1 starts before spans2 or the spans start at the same position, and
  *     spans1 ends before spans2.
  */
 static boolean positionsOrdered(Spans spans1, Spans spans2) {
   assert spans1.docID() == spans2.docID()
       : "doc1 " + spans1.docID() + " != doc2 " + spans2.docID();
   int start1 = spans1.startPosition();
   int start2 = spans2.startPosition();
   return (start1 == start2) ? (spans1.endPosition() < spans2.endPosition()) : (start1 < start2);
 }
  /**
   * Collect all Spans extracted from a Scorer using a SpanCollector
   *
   * @param scorer the scorer to extract Spans from
   * @param collector the SpanCollector
   * @param errorOnNoSpans if true, throw an error if no Spans can be extracted from the Scorer or
   *     any of its children
   * @throws IOException on error
   */
  public static void collect(Scorer scorer, SpanCollector collector, boolean errorOnNoSpans)
      throws IOException {

    List<Spans> allSpans = getSpans(scorer, errorOnNoSpans);
    int doc = scorer.docID();

    for (Spans spans : allSpans) {
      int spanDoc = spans.docID();
      // if the Scorer advances lazily, then not all of its subspans may be on
      // the correct document
      if (spanDoc == doc || (spanDoc < doc && spans.advance(doc) == doc)) {
        while (spans.nextStartPosition() != Spans.NO_MORE_POSITIONS) {
          spans.collect(collector);
        }
      }
    }
  }
 @Override
 public int docID() {
   return in.docID();
 }