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

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

Introduction

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

Prototype

protected TwoPhaseIterator(DocIdSetIterator approximation) 

Source Link

Document

Takes the approximation to be returned by #approximation .

Usage

From source file:org.opengrok.suggest.query.customized.CustomExactPhraseScorer.java

License:Apache License

@Override
public TwoPhaseIterator twoPhaseIterator() {
    return new TwoPhaseIterator(conjunction) {
        @Override/*from  w ww.  ja  v a  2 s.  c  om*/
        public boolean matches() throws IOException {
            // custom  interrupt handler
            if (Thread.currentThread().isInterrupted()) {
                throw new IOException("Interrupted while scoring documents");
            }
            return phraseFreq() > 0; // custom  only necessary part left
        }

        @Override
        public float matchCost() {
            return 0; // custom  default value
        }
    };
}

From source file:org.opengrok.suggest.query.customized.CustomSloppyPhraseScorer.java

License:Apache License

@Override
public TwoPhaseIterator twoPhaseIterator() {
    return new TwoPhaseIterator(conjunction) {
        @Override/*from  w w  w.ja  va 2 s  .c  om*/
        public boolean matches() throws IOException {
            // custom  interrupt handler
            if (Thread.currentThread().isInterrupted()) {
                throw new IOException("Interrupted while scoring documents");
            }
            sloppyFreq = phraseFreq(); // check for phrase
            return sloppyFreq != 0F;
        }

        @Override
        public float matchCost() {
            return 0; // custom  default value
        }

        @Override
        public String toString() {
            return "CustomSloppyPhraseScorer@asTwoPhaseIterator(" + CustomSloppyPhraseScorer.this + ")";
        }
    };
}

From source file:org.vootoo.search.function.ValueSourceCollectorFilter.java

License:Apache License

@Override
public DocIdSet getDocIdSet(@SuppressWarnings("rawtypes") final Map context,
        final LeafReaderContext readerContext, Bits acceptDocs) throws IOException {
    collectorFilterable.doSetNextReader(context, readerContext);
    //TODO  check getDocIdSet use
    return BitsFilteredDocIdSet.wrap(new DocIdSet() {
        @Override/* w ww. j av a 2  s.  c  om*/
        public long ramBytesUsed() {
            return 0;
        }

        @Override
        public DocIdSetIterator iterator() throws IOException {
            final DocIdSetIterator approximation = DocIdSetIterator.all(readerContext.reader().maxDoc()); // no approximation!
            TwoPhaseIterator twoPhaseIterator = new TwoPhaseIterator(approximation) {
                @Override
                public boolean matches() throws IOException {
                    return collectorFilterable.matches(approximation.docID());
                }

                @Override
                public float matchCost() {
                    return 100; // TODO: use cost of ValueSourceScorer.this.matches()
                }
            };
            return TwoPhaseIterator.asDocIdSetIterator(twoPhaseIterator);
        }

        @Override
        public Bits bits() {
            return null; // don't use random access
        }
    }, acceptDocs);
}

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

License:Apache License

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