org.apache.lucene.facet.search
Class PayloadIntDecodingIterator

java.lang.Object
  extended by 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 the IndexReader and Term 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
PayloadIntDecodingIterator(IndexReader indexReader, Term term, IntDecoder decoder)
           
PayloadIntDecodingIterator(IndexReader indexReader, Term term, IntDecoder decoder, byte[] buffer)
           
 
Method Summary
 boolean equals(Object other)
           
 int hashCode()
           
 boolean init()
          Initializes the iterator.
 long nextCategory()
          Returns the next category for the current document that is set through CategoryListIterator.skipTo(int), or a number higher than Integer.MAX_VALUE.
 boolean skipTo(int docId)
          Skips forward to document docId.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

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

equals

public boolean equals(Object other)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

init

public boolean init()
             throws IOException
Description copied from interface: CategoryListIterator
Initializes the iterator. This method must be called before any calls to CategoryListIterator.skipTo(int), and its return value indicates whether there are any relevant documents for this iterator. If it returns false, any call to CategoryListIterator.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 interface CategoryListIterator
Throws:
IOException

nextCategory

public long nextCategory()
                  throws IOException
Description copied from interface: CategoryListIterator
Returns the next category for the current document that is set through CategoryListIterator.skipTo(int), or a number higher than Integer.MAX_VALUE. No assumptions can be made on the order of the categories.

Specified by:
nextCategory in interface CategoryListIterator
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 calling CategoryListIterator.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 interface CategoryListIterator
Throws:
IOException


Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.