Package org.apache.lucene.facet.search
Class PayloadIntDecodingIterator
- java.lang.Object
-
- org.apache.lucene.facet.search.PayloadIntDecodingIterator
-
- All Implemented Interfaces:
CategoryListIterator
public class PayloadIntDecodingIterator extends Object implements CategoryListIterator
A payload deserializer comes with its own working space (buffer). One need to define theIndexReader
andTerm
in which the payload resides. The iterator then consumes the payload information of each document and decodes it into categories. A typical use case of this class is:IndexReader reader = [open your reader]; Term t = new Term("field", "where-payload-exists"); CategoryListIterator cli = new PayloadIntDecodingIterator(reader, t); if (!cli.init()) { // it means there are no payloads / documents associated with that term. // Usually a sanity check. However, init() must be called. } DocIdSetIterator disi = [you usually iterate on something else, such as a Scorer]; int doc; while ((doc = disi.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) { cli.setdoc(doc); long category; while ((category = cli.nextCategory()) < Integer.MAX_VALUE) { } }
- WARNING: This API is experimental and might change in incompatible ways in the next release.
-
-
Constructor Summary
Constructors Constructor Description PayloadIntDecodingIterator(IndexReader indexReader, Term term, IntDecoder decoder)
PayloadIntDecodingIterator(IndexReader indexReader, Term term, IntDecoder decoder, byte[] buffer)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object other)
int
hashCode()
boolean
init()
Initializes the iterator.long
nextCategory()
Returns the next category for the current document that is set throughCategoryListIterator.skipTo(int)
, or a number higher thanInteger.MAX_VALUE
.boolean
skipTo(int docId)
Skips forward to document docId.
-
-
-
Constructor Detail
-
PayloadIntDecodingIterator
public PayloadIntDecodingIterator(IndexReader indexReader, Term term, IntDecoder decoder) throws IOException
- Throws:
IOException
-
PayloadIntDecodingIterator
public PayloadIntDecodingIterator(IndexReader indexReader, Term term, IntDecoder decoder, byte[] buffer) throws IOException
- Throws:
IOException
-
-
Method Detail
-
init
public boolean init() throws IOException
Description copied from interface:CategoryListIterator
Initializes the iterator. This method must be called before any calls toCategoryListIterator.skipTo(int)
, and its return value indicates whether there are any relevant documents for this iterator. If it returns false, any call toCategoryListIterator.skipTo(int)
will return false as well.
NOTE: calling this method twice may result in skipping over documents for some implementations. Also, calling it again after all documents were consumed may yield unexpected behavior.- Specified by:
init
in interfaceCategoryListIterator
- Throws:
IOException
-
nextCategory
public long nextCategory() throws IOException
Description copied from interface:CategoryListIterator
Returns the next category for the current document that is set throughCategoryListIterator.skipTo(int)
, or a number higher thanInteger.MAX_VALUE
. No assumptions can be made on the order of the categories.- Specified by:
nextCategory
in interfaceCategoryListIterator
- Throws:
IOException
-
skipTo
public boolean skipTo(int docId) throws IOException
Description copied from interface:CategoryListIterator
Skips forward to document docId. Returns true iff this document exists and has any categories. This method must be called before callingCategoryListIterator.nextCategory()
for a particular document.
NOTE: Users should call this method with increasing docIds, and implementations can assume that this is the case.- Specified by:
skipTo
in interfaceCategoryListIterator
- Throws:
IOException
-
-