Example usage for org.apache.lucene.search.spans Spans asTwoPhaseIterator

List of usage examples for org.apache.lucene.search.spans Spans asTwoPhaseIterator

Introduction

In this page you can find the example usage for org.apache.lucene.search.spans Spans asTwoPhaseIterator.

Prototype

public TwoPhaseIterator asTwoPhaseIterator() 

Source Link

Document

Optional method: Return a TwoPhaseIterator view of this Scorer .

Usage

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

License:Apache License

/**
 * Return a {@link TwoPhaseIterator} view of this ConjunctionSpans.
 *//*w  w w  .j  a v  a  2s.  com*/
@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;
        }
    };
}