@Override public float matchCost() { return inner.matchCost(); // underestimate }
private ConjunctionTwoPhaseIterator(DocIdSetIterator approximation, List<? extends TwoPhaseIterator> twoPhaseIterators) { super(approximation); assert twoPhaseIterators.size() > 0; CollectionUtil.timSort(twoPhaseIterators, new Comparator<TwoPhaseIterator>() { @Override public int compare(TwoPhaseIterator o1, TwoPhaseIterator o2) { return Float.compare(o1.matchCost(), o2.matchCost()); } }); this.twoPhaseIterators = twoPhaseIterators.toArray(new TwoPhaseIterator[twoPhaseIterators.size()]); // Compute the matchCost as the total matchCost of the sub iterators. // TODO: This could be too high because the matching is done cheapest first: give the lower matchCosts a higher weight. float totalMatchCost = 0; for (TwoPhaseIterator tpi : twoPhaseIterators) { totalMatchCost += tpi.matchCost(); } matchCost = totalMatchCost; }
/** * Return a {@link TwoPhaseIterator} view of this ConjunctionSpans. */ @Override public TwoPhaseIterator asTwoPhaseIterator() { float totalMatchCost = 0; // Compute the matchCost as the total matchCost/positionsCostant of the sub spans. for (Spans spans : subSpans) { TwoPhaseIterator tpi = spans.asTwoPhaseIterator(); if (tpi != null) { totalMatchCost += tpi.matchCost(); } else { totalMatchCost += spans.positionsCost(); } } final float matchCost = totalMatchCost; return new TwoPhaseIterator(conjunction) { @Override public boolean matches() throws IOException { return twoPhaseCurrentDocMatches(); } @Override public float matchCost() { return matchCost; } }; }
private static float matchCost( DocIdSetIterator reqApproximation, TwoPhaseIterator reqTwoPhaseIterator, DocIdSetIterator exclApproximation, TwoPhaseIterator exclTwoPhaseIterator) { float matchCost = 2; // we perform 2 comparisons to advance exclApproximation if (reqTwoPhaseIterator != null) { // this two-phase iterator must always be matched matchCost += reqTwoPhaseIterator.matchCost(); } // match cost of the prohibited clause: we need to advance the approximation // and match the two-phased iterator final float exclMatchCost = ADVANCE_COST + (exclTwoPhaseIterator == null ? 0 : exclTwoPhaseIterator.matchCost()); // upper value for the ratio of documents that reqApproximation matches that // exclApproximation also matches float ratio; if (reqApproximation.cost() <= 0) { ratio = 1f; } else if (exclApproximation.cost() <= 0) { ratio = 0f; } else { ratio = (float) Math.min(reqApproximation.cost(), exclApproximation.cost()) / reqApproximation.cost(); } matchCost += ratio * exclMatchCost; return matchCost; }
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; } }
@Override public TwoPhaseIterator asTwoPhaseIterator() { float sumMatchCost = 0; // See also DisjunctionScorer.asTwoPhaseIterator() long sumApproxCost = 0; for (DisiWrapper w : byDocQueue) { if (w.twoPhaseView != null) { long costWeight = (w.cost <= 1) ? 1 : w.cost; sumMatchCost += w.twoPhaseView.matchCost() * costWeight; sumApproxCost += costWeight; } } if (sumApproxCost == 0) { // no sub spans supports approximations computePositionsCost(); return null; } final float matchCost = sumMatchCost / sumApproxCost; return new TwoPhaseIterator(new DisjunctionDISIApproximation(byDocQueue)) { @Override public boolean matches() throws IOException { return twoPhaseCurrentDocMatches(); } @Override public float matchCost() { return matchCost; } }; }
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; } }
@Override public float matchCost() { return in.matchCost(); } };
@Override public float matchCost() { return 1000f // random constant for the score computation + (inTwoPhase == null ? 0 : inTwoPhase.matchCost()); } };
@Override public float matchCost() { return 1000f // random constant for the score computation + (inTwoPhase == null ? 0 : inTwoPhase.matchCost()); } };
@Override public float matchCost() { return in.matchCost(); } };
@Override public float matchCost() { return 1000f // random constant for the score computation + (inTwoPhase == null ? 0 : inTwoPhase.matchCost()); } };
@Override public float matchCost() { return in.matchCost(); } };
@Override public float matchCost() { return 1000f // random constant for the score computation + (inTwoPhase == null ? 0 : inTwoPhase.matchCost()); } };
@Override public float matchCost() { return 1000f // random constant for the score computation + (inTwoPhase == null ? 0 : inTwoPhase.matchCost()); } };
@Override public float matchCost() { return in.matchCost(); } };