/** * Returns true if the current document matches. * <p> * This is called during two-phase processing. */ // return true if the current document matches @SuppressWarnings("fallthrough") private final boolean twoPhaseCurrentDocMatches() throws IOException { atFirstInCurrentDoc = false; startPos = in.nextStartPosition(); assert startPos != NO_MORE_POSITIONS; for (;;) { switch(accept(in)) { case YES: atFirstInCurrentDoc = true; return true; case NO: startPos = in.nextStartPosition(); if (startPos != NO_MORE_POSITIONS) { break; } // else fallthrough case NO_MORE_IN_CURRENT_DOC: startPos = -1; return false; } } }
@Override public int nextStartPosition() throws IOException { if (atFirstInCurrentDoc) { atFirstInCurrentDoc = false; return matchStart; } oneExhaustedInCurrentDoc = false; while (subSpans[0].nextStartPosition() != NO_MORE_POSITIONS && !oneExhaustedInCurrentDoc) { if (stretchToOrder() && matchWidth <= allowedSlop) { return matchStart; } } return matchStart = matchEnd = NO_MORE_POSITIONS; }
@Override public final int nextStartPosition() throws IOException { if (atFirstInCurrentDoc) { atFirstInCurrentDoc = false; return startPos; } for (;;) { startPos = in.nextStartPosition(); if (startPos == NO_MORE_POSITIONS) { return NO_MORE_POSITIONS; } switch(accept(in)) { case YES: return startPos; case NO: break; case NO_MORE_IN_CURRENT_DOC: return startPos = NO_MORE_POSITIONS; // startPos ahead for the current doc. } } }
@Override boolean twoPhaseCurrentDocMatches() throws IOException { assert unpositioned(); oneExhaustedInCurrentDoc = false; while (subSpans[0].nextStartPosition() != NO_MORE_POSITIONS && !oneExhaustedInCurrentDoc) { if (stretchToOrder() && matchWidth <= allowedSlop) { return atFirstInCurrentDoc = true; } } return false; }
private static int advancePosition(Spans spans, int position) throws IOException { if (spans instanceof SpanNearQuery.GapSpans) { return ((SpanNearQuery.GapSpans)spans).skipToPosition(position); } while (spans.startPosition() < position) { spans.nextStartPosition(); } return spans.startPosition(); }
@Override boolean twoPhaseCurrentDocMatches() throws IOException { oneExhaustedInCurrentDoc = false; assert littleSpans.startPosition() == -1; while (littleSpans.nextStartPosition() != NO_MORE_POSITIONS) { while (bigSpans.endPosition() < littleSpans.endPosition()) { if (bigSpans.nextStartPosition() == NO_MORE_POSITIONS) { oneExhaustedInCurrentDoc = true; return false; } } if (bigSpans.startPosition() <= littleSpans.startPosition()) { atFirstInCurrentDoc = true; return true; } } oneExhaustedInCurrentDoc = true; return false; }
@Override boolean twoPhaseCurrentDocMatches() throws IOException { oneExhaustedInCurrentDoc = false; assert littleSpans.startPosition() == -1; while (bigSpans.nextStartPosition() != NO_MORE_POSITIONS) { while (littleSpans.startPosition() < bigSpans.startPosition()) { if (littleSpans.nextStartPosition() == NO_MORE_POSITIONS) { oneExhaustedInCurrentDoc = true; return false; } } if (bigSpans.endPosition() >= littleSpans.endPosition()) { atFirstInCurrentDoc = true; return true; } } oneExhaustedInCurrentDoc = true; return false; }
@Override public int nextStartPosition() throws IOException { if (atFirstInCurrentDoc) { atFirstInCurrentDoc = false; return bigSpans.startPosition(); } while (bigSpans.nextStartPosition() != NO_MORE_POSITIONS) { while (littleSpans.startPosition() < bigSpans.startPosition()) { if (littleSpans.nextStartPosition() == NO_MORE_POSITIONS) { oneExhaustedInCurrentDoc = true; return NO_MORE_POSITIONS; } } if (bigSpans.endPosition() >= littleSpans.endPosition()) { return bigSpans.startPosition(); } } oneExhaustedInCurrentDoc = true; return NO_MORE_POSITIONS; } };
@Override public int nextStartPosition() throws IOException { if (atFirstInCurrentDoc) { atFirstInCurrentDoc = false; return littleSpans.startPosition(); } while (littleSpans.nextStartPosition() != NO_MORE_POSITIONS) { while (bigSpans.endPosition() < littleSpans.endPosition()) { if (bigSpans.nextStartPosition() == NO_MORE_POSITIONS) { oneExhaustedInCurrentDoc = true; return NO_MORE_POSITIONS; } } if (bigSpans.startPosition() <= littleSpans.startPosition()) { return littleSpans.startPosition(); } } oneExhaustedInCurrentDoc = true; return NO_MORE_POSITIONS; } };
@Override public int nextStartPosition() throws IOException { if (topPositionSpans == null) { byPositionQueue.clear(); fillPositionQueue(); // fills byPositionQueue at first position topPositionSpans = byPositionQueue.top(); } else { topPositionSpans.nextStartPosition(); topPositionSpans = byPositionQueue.updateTop(); } return topPositionSpans.startPosition(); }
int prevEndPos = -1; int startPos = spans.nextStartPosition(); assert startPos != Spans.NO_MORE_POSITIONS : "initial startPos NO_MORE_POSITIONS, " + spans; do { prevStartPos = startPos; prevEndPos = endPos; startPos = spans.nextStartPosition(); } while (startPos != Spans.NO_MORE_POSITIONS);
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; }
excludeSpans.nextStartPosition(); if (excludeSpans.nextStartPosition() == NO_MORE_POSITIONS) { return AcceptStatus.YES; // no more exclude at current doc.
void fillPositionQueue() throws IOException { // called at first nextStartPosition assert byPositionQueue.size() == 0; // add all matching Spans at current doc to byPositionQueue DisiWrapper listAtCurrentDoc = byDocQueue.topList(); while (listAtCurrentDoc != null) { Spans spansAtDoc = listAtCurrentDoc.spans; if (lastDocTwoPhaseMatched == listAtCurrentDoc.doc) { // matched by DisjunctionDisiApproximation if (listAtCurrentDoc.twoPhaseView != null) { // matched by approximation if (listAtCurrentDoc.lastApproxNonMatchDoc == listAtCurrentDoc.doc) { // matches() returned false spansAtDoc = null; } else { if (listAtCurrentDoc.lastApproxMatchDoc != listAtCurrentDoc.doc) { if (!listAtCurrentDoc.twoPhaseView.matches()) { spansAtDoc = null; } } } } } if (spansAtDoc != null) { assert spansAtDoc.docID() == listAtCurrentDoc.doc; assert spansAtDoc.startPosition() == -1; spansAtDoc.nextStartPosition(); assert spansAtDoc.startPosition() != NO_MORE_POSITIONS; byPositionQueue.add(spansAtDoc); } listAtCurrentDoc = listAtCurrentDoc.next; } assert byPositionQueue.size() > 0; }
@Override boolean twoPhaseCurrentDocMatches() throws IOException { assert unpositioned(); oneExhaustedInCurrentDoc = false; while (subSpans[0].nextStartPosition() != NO_MORE_POSITIONS && !oneExhaustedInCurrentDoc) { if (stretchToOrder() && matchWidth <= allowedSlop) { return atFirstInCurrentDoc = true; } } return false; }
@Override boolean twoPhaseCurrentDocMatches() throws IOException { assert unpositioned(); oneExhaustedInCurrentDoc = false; while (subSpans[0].nextStartPosition() != NO_MORE_POSITIONS && !oneExhaustedInCurrentDoc) { if (stretchToOrder() && matchWidth <= allowedSlop) { return atFirstInCurrentDoc = true; } } return false; }
@Override boolean twoPhaseCurrentDocMatches() throws IOException { assert unpositioned(); oneExhaustedInCurrentDoc = false; while (subSpans[0].nextStartPosition() != NO_MORE_POSITIONS && !oneExhaustedInCurrentDoc) { if (stretchToOrder() && matchWidth <= allowedSlop) { return atFirstInCurrentDoc = true; } } return false; }
@Override public int nextStartPosition() throws IOException { if (topPositionSpans == null) { byPositionQueue.clear(); fillPositionQueue(); // fills byPositionQueue at first position topPositionSpans = byPositionQueue.top(); } else { topPositionSpans.nextStartPosition(); topPositionSpans = byPositionQueue.updateTop(); } return topPositionSpans.startPosition(); }
@Override public int nextStartPosition() throws IOException { if (topPositionSpans == null) { byPositionQueue.clear(); fillPositionQueue(); // fills byPositionQueue at first position topPositionSpans = byPositionQueue.top(); } else { topPositionSpans.nextStartPosition(); topPositionSpans = byPositionQueue.updateTop(); } return topPositionSpans.startPosition(); }