Example usage for org.apache.lucene.search TwoPhaseIterator matchCost

List of usage examples for org.apache.lucene.search TwoPhaseIterator matchCost

Introduction

In this page you can find the example usage for org.apache.lucene.search TwoPhaseIterator matchCost.

Prototype

public abstract float matchCost();

Source Link

Document

An estimate of the expected cost to determine that a single document #matches() .

Usage

From source file:org.codelibs.elasticsearch.common.lucene.search.function.MinScoreScorer.java

License:Apache License

@Override
public TwoPhaseIterator twoPhaseIterator() {
    final TwoPhaseIterator inTwoPhase = this.in.twoPhaseIterator();
    final DocIdSetIterator approximation = inTwoPhase == null ? in.iterator() : inTwoPhase.approximation();
    return new TwoPhaseIterator(approximation) {

        @Override/*from w w  w.  j  a va2 s .  com*/
        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());
        }
    };
}

From source file:org.codelibs.elasticsearch.search.profile.query.ProfileScorer.java

License:Apache License

@Override
public TwoPhaseIterator twoPhaseIterator() {
    final TwoPhaseIterator in = scorer.twoPhaseIterator();
    if (in == null) {
        return null;
    }/*from  w  w  w.j  a  v a  2  s  . com*/
    final DocIdSetIterator inApproximation = in.approximation();
    final DocIdSetIterator approximation = new DocIdSetIterator() {

        @Override
        public int advance(int target) throws IOException {
            profile.startTime(QueryTimingType.ADVANCE);
            try {
                return inApproximation.advance(target);
            } finally {
                profile.stopAndRecordTime();
            }
        }

        @Override
        public int nextDoc() throws IOException {
            profile.startTime(QueryTimingType.NEXT_DOC);
            try {
                return inApproximation.nextDoc();
            } finally {
                profile.stopAndRecordTime();
            }
        }

        @Override
        public int docID() {
            return inApproximation.docID();
        }

        @Override
        public long cost() {
            return inApproximation.cost();
        }
    };
    return new TwoPhaseIterator(approximation) {
        @Override
        public boolean matches() throws IOException {
            profile.startTime(QueryTimingType.MATCH);
            try {
                return in.matches();
            } finally {
                profile.stopAndRecordTime();
            }
        }

        @Override
        public float matchCost() {
            return in.matchCost();
        }
    };
}

From source file:org.elasticsearch.search.profile.ProfileScorer.java

License:Apache License

@Override
public TwoPhaseIterator twoPhaseIterator() {
    final TwoPhaseIterator in = scorer.twoPhaseIterator();
    if (in == null) {
        return null;
    }//w w w. j a  va  2s . c om
    final DocIdSetIterator inApproximation = in.approximation();
    final DocIdSetIterator approximation = new DocIdSetIterator() {

        @Override
        public int advance(int target) throws IOException {
            profile.startTime(ProfileBreakdown.TimingType.ADVANCE);
            try {
                return inApproximation.advance(target);
            } finally {
                profile.stopAndRecordTime();
            }
        }

        @Override
        public int nextDoc() throws IOException {
            profile.startTime(ProfileBreakdown.TimingType.NEXT_DOC);
            try {
                return inApproximation.nextDoc();
            } finally {
                profile.stopAndRecordTime();
            }
        }

        @Override
        public int docID() {
            return inApproximation.docID();
        }

        @Override
        public long cost() {
            return inApproximation.cost();
        }
    };
    return new TwoPhaseIterator(approximation) {
        @Override
        public boolean matches() throws IOException {
            profile.startTime(ProfileBreakdown.TimingType.MATCH);
            try {
                return in.matches();
            } finally {
                profile.stopAndRecordTime();
            }
        }

        @Override
        public float matchCost() {
            return in.matchCost();
        }
    };
}

From source file:uk.co.flax.luwak.util.XConjunctionSpans.java

License:Apache License

/**
 * Return a {@link TwoPhaseIterator} view of this ConjunctionSpans.
 *//*from   ww w.ja  va  2s  .c o m*/
@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;
        }
    };
}