private Spans buildConjunctionSpans() throws IOException { if (requiredSpans.size() == 1) { return requiredSpans.get(0); } else { if (inOrder) { return new NearSpansOrdered(requiredSpans, slop); } else { return new NearSpansUnordered(requiredSpans, slop); } } }
@Override public boolean nextPosition() throws IOException { // Initialise the first spans if (!subSpans[0].nextPosition()) { matchStart = matchEnd = PositionsIterator.NO_MORE_POS; return false; } // Ensure that all the spans are ordered while (stretchToOrder()) { // check if the spans are within the allowed slop if (shrinkToAfterShortestMatch()) { return true; } // the spans were not in the allowed slop, try the next one // subSpans[0] has been advanced after the possible match, no need to call subSpans[0].nextPosition() } // if we are out of the loop, then this means that one of the sub-span is exhausted matchStart = matchEnd = PositionsIterator.NO_MORE_POS; return false; }
/** * Order the subSpans within the same document and same node by advancing all later spans * after the previous one. */ private boolean stretchToOrder() throws IOException { for (int i = 1; i < subSpans.length; i++) { while (!isSpansOrdered(subSpans[i-1].start(), subSpans[i-1].end(), subSpans[i].start(), subSpans[i].end())) { if (!subSpans[i].nextPosition()) { return false; } } } return true; }
int ppStart = prevSpans.start(); int ppEnd = prevSpans.end(); if (!isSpansOrdered(ppStart, ppEnd, lastStart, lastEnd)) {
@Override public Scorer scorer(final AtomicReaderContext context, final Bits acceptDocs) throws IOException { final List<Spans> spans = new ArrayList<Spans>(); for (final Weight w : weights) { final Scorer scorer = w.scorer(context, acceptDocs); if (scorer == null) { return null; } if (!(scorer instanceof SpanScorer)) { throw new IllegalArgumentException("SpanScorer expected"); } spans.add(((SpanScorer) scorer).getSpans()); } int slop = NearSpanQuery.this.getSlop(); NearSpans nearSpans = inOrder ? new NearSpansOrdered(spans, slop) : new NearSpansUnordered(spans, slop); return new SpanScorer(this, nearSpans); }