Package org.apache.lucene.search
Class TwoPhaseIterator
- java.lang.Object
-
- org.apache.lucene.search.TwoPhaseIterator
-
public abstract class TwoPhaseIterator extends Object
Returned byScorer.twoPhaseIterator()
to expose an approximation of aDocIdSetIterator
. When theapproximation()
'sDocIdSetIterator.nextDoc()
orDocIdSetIterator.advance(int)
return,matches()
needs to be checked in order to know whether the returned doc ID actually matches.- WARNING: This API is experimental and might change in incompatible ways in the next release.
-
-
Field Summary
Fields Modifier and Type Field Description protected DocIdSetIterator
approximation
-
Constructor Summary
Constructors Modifier Constructor Description protected
TwoPhaseIterator(DocIdSetIterator approximation)
Takes the approximation to be returned byapproximation
.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description DocIdSetIterator
approximation()
Return an approximation.static DocIdSetIterator
asDocIdSetIterator(TwoPhaseIterator twoPhaseIterator)
Return aDocIdSetIterator
view of the providedTwoPhaseIterator
.abstract float
matchCost()
An estimate of the expected cost to determine that a single documentmatches()
.abstract boolean
matches()
Return whether the current doc ID thatapproximation()
is on matches.static TwoPhaseIterator
unwrap(DocIdSetIterator iterator)
If the givenDocIdSetIterator
has been created withasDocIdSetIterator(org.apache.lucene.search.TwoPhaseIterator)
, then this will return the wrappedTwoPhaseIterator
.
-
-
-
Field Detail
-
approximation
protected final DocIdSetIterator approximation
-
-
Constructor Detail
-
TwoPhaseIterator
protected TwoPhaseIterator(DocIdSetIterator approximation)
Takes the approximation to be returned byapproximation
. Not null.
-
-
Method Detail
-
asDocIdSetIterator
public static DocIdSetIterator asDocIdSetIterator(TwoPhaseIterator twoPhaseIterator)
Return aDocIdSetIterator
view of the providedTwoPhaseIterator
.
-
unwrap
public static TwoPhaseIterator unwrap(DocIdSetIterator iterator)
If the givenDocIdSetIterator
has been created withasDocIdSetIterator(org.apache.lucene.search.TwoPhaseIterator)
, then this will return the wrappedTwoPhaseIterator
. Otherwise this returnsnull
.
-
approximation
public DocIdSetIterator approximation()
Return an approximation. The returnedDocIdSetIterator
is a superset of the matching documents, and each match needs to be confirmed withmatches()
in order to know whether it matches or not.
-
matches
public abstract boolean matches() throws IOException
Return whether the current doc ID thatapproximation()
is on matches. This method should only be called when the iterator is positioned -- ie. not whenDocIdSetIterator.docID()
is-1
orDocIdSetIterator.NO_MORE_DOCS
-- and at most once.- Throws:
IOException
-
matchCost
public abstract float matchCost()
An estimate of the expected cost to determine that a single documentmatches()
. This can be called before iterating the documents ofapproximation()
. Returns an expected cost in number of simple operations like addition, multiplication, comparing two numbers and indexing an array. The returned value must be positive.
-
-