public NearSpansUnordered(int allowedSlop, List<Spans> subSpans) throws IOException { super(subSpans); this.allowedSlop = allowedSlop; this.spanWindow = new SpanTotalLengthEndPositionWindow(); }
void startDocument() throws IOException { clear(); totalSpanLength = 0; maxEndPosition = -1; for (Spans spans : subSpans) { assert spans.startPosition() == -1; spans.nextStartPosition(); assert spans.startPosition() != NO_MORE_POSITIONS; add(spans); if (spans.endPosition() > maxEndPosition) { maxEndPosition = spans.endPosition(); } int spanLength = spans.endPosition() - spans.startPosition(); assert spanLength >= 0; totalSpanLength += spanLength; } }
@Override public int nextStartPosition() throws IOException { if (atFirstInCurrentDoc) { atFirstInCurrentDoc = false; return spanWindow.top().startPosition(); } assert spanWindow.top().startPosition() != -1; assert spanWindow.top().startPosition() != NO_MORE_POSITIONS; while (true) { if (! spanWindow.nextPosition()) { oneExhaustedInCurrentDoc = true; return NO_MORE_POSITIONS; } if (spanWindow.atMatch()) { return spanWindow.top().startPosition(); } } }
boolean nextPosition() throws IOException { Spans topSpans = top(); assert topSpans.startPosition() != NO_MORE_POSITIONS; int spanLength = topSpans.endPosition() - topSpans.startPosition(); int nextStartPos = topSpans.nextStartPosition(); if (nextStartPos == NO_MORE_POSITIONS) { return false; } totalSpanLength -= spanLength; spanLength = topSpans.endPosition() - topSpans.startPosition(); totalSpanLength += spanLength; if (topSpans.endPosition() > maxEndPosition) { maxEndPosition = topSpans.endPosition(); } updateTop(); return true; }
@Override public int width() { return spanWindow.maxEndPosition - spanWindow.top().startPosition(); }
boolean atMatch() { boolean res = (maxEndPosition - top().startPosition() - totalSpanLength) <= allowedSlop; return res; } }
@Override boolean twoPhaseCurrentDocMatches() throws IOException { // at doc with all subSpans spanWindow.startDocument(); while (true) { if (spanWindow.atMatch()) { atFirstInCurrentDoc = true; oneExhaustedInCurrentDoc = false; return true; } if (! spanWindow.nextPosition()) { return false; } } }
@Override public int nextStartPosition() throws IOException { if (atFirstInCurrentDoc) { atFirstInCurrentDoc = false; return spanWindow.top().startPosition(); } assert spanWindow.top().startPosition() != -1; assert spanWindow.top().startPosition() != NO_MORE_POSITIONS; while (true) { if (! spanWindow.nextPosition()) { oneExhaustedInCurrentDoc = true; return NO_MORE_POSITIONS; } if (spanWindow.atMatch()) { return spanWindow.top().startPosition(); } } }
void startDocument() throws IOException { clear(); totalSpanLength = 0; maxEndPosition = -1; for (Spans spans : subSpans) { assert spans.startPosition() == -1; spans.nextStartPosition(); assert spans.startPosition() != NO_MORE_POSITIONS; add(spans); if (spans.endPosition() > maxEndPosition) { maxEndPosition = spans.endPosition(); } int spanLength = spans.endPosition() - spans.startPosition(); assert spanLength >= 0; totalSpanLength += spanLength; } }
boolean nextPosition() throws IOException { Spans topSpans = top(); assert topSpans.startPosition() != NO_MORE_POSITIONS; int spanLength = topSpans.endPosition() - topSpans.startPosition(); int nextStartPos = topSpans.nextStartPosition(); if (nextStartPos == NO_MORE_POSITIONS) { return false; } totalSpanLength -= spanLength; spanLength = topSpans.endPosition() - topSpans.startPosition(); totalSpanLength += spanLength; if (topSpans.endPosition() > maxEndPosition) { maxEndPosition = topSpans.endPosition(); } updateTop(); return true; }
@Override boolean twoPhaseCurrentDocMatches() throws IOException { // at doc with all subSpans spanWindow.startDocument(); while (true) { if (spanWindow.atMatch()) { atFirstInCurrentDoc = true; oneExhaustedInCurrentDoc = false; return true; } if (! spanWindow.nextPosition()) { return false; } } }
@Override public int width() { return spanWindow.maxEndPosition - spanWindow.top().startPosition(); }
boolean atMatch() { boolean res = (maxEndPosition - top().startPosition() - totalSpanLength) <= allowedSlop; return res; } }
public NearSpansUnordered(int allowedSlop, List<Spans> subSpans) throws IOException { super(subSpans); this.allowedSlop = allowedSlop; this.spanWindow = new SpanTotalLengthEndPositionWindow(); }