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

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

Introduction

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

Prototype

public abstract float positionsCost();

Source Link

Document

Return an estimation of the cost of using the positions of this Spans for any single document, but only after #asTwoPhaseIterator returned null .

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 .  ja  va2  s.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;
        }
    };
}