/** Confirms whether or not the given {@link TwoPhaseIterator} * matches on the current document. */ private static boolean matchesOrNull(TwoPhaseIterator it) throws IOException { return it == null || it.matches(); }
@Override public boolean matches() throws IOException { for (TwoPhaseIterator twoPhaseIterator : twoPhaseIterators) { // match cheapest first if (twoPhaseIterator.matches() == false) { return false; } } return true; }
@Override public boolean matches() throws IOException { return inner.matches() && twoPhaseCurrentDocMatches(); }
DisiWrapper getSubMatches() throws IOException { // iteration order does not matter for (DisiWrapper w : unverifiedMatches) { if (w.twoPhaseView.matches()) { w.next = verifiedMatches; verifiedMatches = w; } } unverifiedMatches.clear(); return verifiedMatches; }
private int doNext(int doc) throws IOException { for (;; doc = approximation.nextDoc()) { if (doc == NO_MORE_DOCS) { return NO_MORE_DOCS; } else if (twoPhaseIterator.matches()) { return doc; } } }
boolean twoPhaseCurrentDocMatches() throws IOException { DisiWrapper listAtCurrentDoc = byDocQueue.topList(); // remove the head of the list as long as it does not match final int currentDoc = listAtCurrentDoc.doc; while (listAtCurrentDoc.twoPhaseView != null) { if (listAtCurrentDoc.twoPhaseView.matches()) { // use this spans for positions at current doc: listAtCurrentDoc.lastApproxMatchDoc = currentDoc; break; } // do not use this spans for positions at current doc: listAtCurrentDoc.lastApproxNonMatchDoc = currentDoc; listAtCurrentDoc = listAtCurrentDoc.next; if (listAtCurrentDoc == null) { return false; } } lastDocTwoPhaseMatched = currentDoc; topPositionSpans = null; return true; }
if (w.twoPhaseView.matches()) { w.next = null; verifiedMatches = w;
/** * Returns {@link Matches} for a specific document, or {@code null} if the document * does not match the parent query * * A query match that contains no position information (for example, a Point or * DocValues query) will return {@link MatchesUtils#MATCH_WITH_NO_TERMS} * * @param context the reader's context to create the {@link Matches} for * @param doc the document's id relative to the given context's reader * @lucene.experimental */ public Matches matches(LeafReaderContext context, int doc) throws IOException { Scorer scorer = scorer(context); if (scorer == null) { return null; } final TwoPhaseIterator twoPhase = scorer.twoPhaseIterator(); if (twoPhase == null) { if (scorer.iterator().advance(doc) != doc) { return null; } } else { if (twoPhase.approximation().advance(doc) != doc || twoPhase.matches() == false) { return null; } } return MatchesUtils.MATCH_WITH_NO_TERMS; }
/** Specialized method to bulk-score a range of hits; we * separate this from {@link #scoreAll} to help out * hotspot. * See <a href="https://issues.apache.org/jira/browse/LUCENE-5487">LUCENE-5487</a> */ static int scoreRange(LeafCollector collector, DocIdSetIterator iterator, TwoPhaseIterator twoPhase, Bits acceptDocs, int currentDoc, int end) throws IOException { if (twoPhase == null) { while (currentDoc < end) { if (acceptDocs == null || acceptDocs.get(currentDoc)) { collector.collect(currentDoc); } currentDoc = iterator.nextDoc(); } return currentDoc; } else { final DocIdSetIterator approximation = twoPhase.approximation(); while (currentDoc < end) { if ((acceptDocs == null || acceptDocs.get(currentDoc)) && twoPhase.matches()) { collector.collect(currentDoc); } currentDoc = approximation.nextDoc(); } return currentDoc; } }
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; }
/** Specialized method to bulk-score all hits; we * separate this from {@link #scoreRange} to help out * hotspot. * See <a href="https://issues.apache.org/jira/browse/LUCENE-5487">LUCENE-5487</a> */ static void scoreAll(LeafCollector collector, DocIdSetIterator iterator, TwoPhaseIterator twoPhase, Bits acceptDocs) throws IOException { if (twoPhase == null) { for (int doc = iterator.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = iterator.nextDoc()) { if (acceptDocs == null || acceptDocs.get(doc)) { collector.collect(doc); } } } else { // The scorer has an approximation, so run the approximation first, then check acceptDocs, then confirm final DocIdSetIterator approximation = twoPhase.approximation(); for (int doc = approximation.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = approximation.nextDoc()) { if ((acceptDocs == null || acceptDocs.get(doc)) && twoPhase.matches()) { collector.collect(doc); } } } } }
@Override public Explanation explain(LeafReaderContext context, int doc) throws IOException { final Scorer s = scorer(context); final boolean exists; if (s == null) { exists = false; } else { final TwoPhaseIterator twoPhase = s.twoPhaseIterator(); if (twoPhase == null) { exists = s.iterator().advance(doc) == doc; } else { exists = twoPhase.approximation().advance(doc) == doc && twoPhase.matches(); } } if (exists) { return Explanation.match( score, getQuery().toString() + (score == 1f ? "" : "^" + score)); } else { return Explanation.noMatch(getQuery().toString() + " doesn't match id " + doc); } }
@Override public boolean matches() throws IOException { // we need to check the two-phase iterator first // otherwise calling score() is illegal if (inTwoPhase != null && inTwoPhase.matches() == false) { return false; } return in.score() >= minScore; }
@Override public boolean matches() throws IOException { matchTimer.start(); try { return in.matches(); } finally { matchTimer.stop(); } }
return previousMatched = twoPhase == null || twoPhase.matches(); } catch (IOException e) { throw new IllegalStateException("Cannot validate match", e);
@Override public boolean matches() throws IOException { for (TwoPhaseIterator twoPhaseIterator : twoPhaseIterators) { // match cheapest first if (twoPhaseIterator.matches() == false) { return false; } } return true; }
/** Confirms whether or not the given {@link TwoPhaseIterator} * matches on the current document. */ private static boolean matchesOrNull(TwoPhaseIterator it) throws IOException { return it == null || it.matches(); }
@Override public boolean matches() throws IOException { // we need to check the two-phase iterator first // otherwise calling score() is illegal if (inTwoPhase != null && inTwoPhase.matches() == false) { return false; } return in.score() >= minScore; }
DisiWrapper getSubMatches() throws IOException { // iteration order does not matter for (DisiWrapper w : unverifiedMatches) { if (w.twoPhaseView.matches()) { w.next = verifiedMatches; verifiedMatches = w; } } unverifiedMatches.clear(); return verifiedMatches; }