/** * 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 advance(int target) throws IOException { return in.advance(target); }