private static void addTwoPhaseIterator(TwoPhaseIterator twoPhaseIter, List<DocIdSetIterator> allIterators, List<TwoPhaseIterator> twoPhaseIterators) { addIterator(twoPhaseIter.approximation(), allIterators, twoPhaseIterators); if (twoPhaseIter.getClass() == ConjunctionTwoPhaseIterator.class) { // Check for exactly this class for collapsing Collections.addAll(twoPhaseIterators, ((ConjunctionTwoPhaseIterator) twoPhaseIter).twoPhaseIterators); } else { twoPhaseIterators.add(twoPhaseIter); } }
if (inner != null) { return new TwoPhaseIterator(inner.approximation()) { @Override public boolean matches() throws IOException {
/** Construct a <code>ReqExclScorer</code>. * @param reqScorer The scorer that must match, except where * @param exclScorer indicates exclusion. */ public ReqExclScorer(Scorer reqScorer, Scorer exclScorer) { super(reqScorer.weight); this.reqScorer = reqScorer; reqTwoPhaseIterator = reqScorer.twoPhaseIterator(); if (reqTwoPhaseIterator == null) { reqApproximation = reqScorer.iterator(); } else { reqApproximation = reqTwoPhaseIterator.approximation(); } exclTwoPhaseIterator = exclScorer.twoPhaseIterator(); if (exclTwoPhaseIterator == null) { exclApproximation = exclScorer.iterator(); } else { exclApproximation = exclTwoPhaseIterator.approximation(); } }
public DisiWrapper(Spans spans) { this.scorer = null; this.spans = spans; this.iterator = spans; this.cost = iterator.cost(); this.doc = -1; this.twoPhaseView = spans.asTwoPhaseIterator(); if (twoPhaseView != null) { approximation = twoPhaseView.approximation(); matchCost = twoPhaseView.matchCost(); } else { approximation = iterator; matchCost = 0f; } this.lastApproxNonMatchDoc = -2; this.lastApproxMatchDoc = -2; } }
public DisiWrapper(Scorer scorer) { this.scorer = scorer; this.spans = null; this.iterator = scorer.iterator(); this.cost = iterator.cost(); this.doc = -1; this.twoPhaseView = scorer.twoPhaseIterator(); if (twoPhaseView != null) { approximation = twoPhaseView.approximation(); matchCost = twoPhaseView.matchCost(); } else { approximation = iterator; matchCost = 0f; } }
DocIdSetIterator excludeApproximation = excludeTwoPhase == null ? null : excludeTwoPhase.approximation();
@Override public int score(LeafCollector collector, Bits acceptDocs, int min, int max) throws IOException { collector.setScorer(scorer); if (scorer.docID() == -1 && min == 0 && max == DocIdSetIterator.NO_MORE_DOCS) { scoreAll(collector, iterator, twoPhase, acceptDocs); return DocIdSetIterator.NO_MORE_DOCS; } else { int doc = scorer.docID(); if (doc < min) { if (twoPhase == null) { doc = iterator.advance(min); } else { doc = twoPhase.approximation().advance(min); } } return scoreRange(collector, iterator, twoPhase, acceptDocs, doc, max); } }
/** * 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; } }
/** 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 TwoPhaseIterator twoPhaseIterator() { final TwoPhaseIterator inTwoPhase = this.in.twoPhaseIterator(); final DocIdSetIterator approximation = inTwoPhase == null ? in.iterator() : inTwoPhase.approximation(); return new TwoPhaseIterator(approximation) { @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 float matchCost() { return 1000f // random constant for the score computation + (inTwoPhase == null ? 0 : inTwoPhase.matchCost()); } }; } }
return null; final DocIdSetIterator inApproximation = in.approximation(); final DocIdSetIterator approximation = new DocIdSetIterator() {
iterator = scorer.iterator(); } else { iterator = twoPhase.approximation();
private static void addTwoPhaseIterator(TwoPhaseIterator twoPhaseIter, List<DocIdSetIterator> allIterators, List<TwoPhaseIterator> twoPhaseIterators) { addIterator(twoPhaseIter.approximation(), allIterators, twoPhaseIterators); if (twoPhaseIter.getClass() == ConjunctionTwoPhaseIterator.class) { // Check for exactly this class for collapsing Collections.addAll(twoPhaseIterators, ((ConjunctionTwoPhaseIterator) twoPhaseIter).twoPhaseIterators); } else { twoPhaseIterators.add(twoPhaseIter); } }
private static void addTwoPhaseIterator(TwoPhaseIterator twoPhaseIter, List<DocIdSetIterator> allIterators, List<TwoPhaseIterator> twoPhaseIterators) { addIterator(twoPhaseIter.approximation(), allIterators, twoPhaseIterators); twoPhaseIterators.add(twoPhaseIter); }
private static void addTwoPhaseIterator(TwoPhaseIterator twoPhaseIter, List<DocIdSetIterator> allIterators, List<TwoPhaseIterator> twoPhaseIterators) { addIterator(twoPhaseIter.approximation(), allIterators, twoPhaseIterators); twoPhaseIterators.add(twoPhaseIter); }
DocsAndCost(Scorer scorer, Collector sidewaysCollector) { final TwoPhaseIterator twoPhase = scorer.twoPhaseIterator(); if (twoPhase == null) { this.approximation = scorer.iterator(); this.twoPhase = null; } else { this.approximation = twoPhase.approximation(); this.twoPhase = twoPhase; } this.sidewaysCollector = sidewaysCollector; } }
DocsAndCost(Scorer scorer, Collector sidewaysCollector) { final TwoPhaseIterator twoPhase = scorer.twoPhaseIterator(); if (twoPhase == null) { this.approximation = scorer.iterator(); this.twoPhase = null; } else { this.approximation = twoPhase.approximation(); this.twoPhase = twoPhase; } this.sidewaysCollector = sidewaysCollector; } }
public DisiWrapper(Scorer scorer) { this.scorer = scorer; this.spans = null; this.iterator = scorer.iterator(); this.cost = iterator.cost(); this.doc = -1; this.twoPhaseView = scorer.twoPhaseIterator(); if (twoPhaseView != null) { approximation = twoPhaseView.approximation(); matchCost = twoPhaseView.matchCost(); } else { approximation = iterator; matchCost = 0f; } }