Class PostingsEnum

java.lang.Object
org.apache.lucene.search.DocIdSetIterator
org.apache.lucene.index.PostingsEnum
Direct Known Subclasses:
FilterLeafReader.FilterPostingsEnum, ImpactsEnum, MultiPhraseQuery.UnionPostingsEnum, MultiPostingsEnum

public abstract class PostingsEnum extends DocIdSetIterator
Iterates through the postings. NOTE: you must first call DocIdSetIterator.nextDoc() before using any of the per-doc methods.
  • Field Details

  • Constructor Details

    • PostingsEnum

      protected PostingsEnum()
      Sole constructor. (For invocation by subclass constructors, typically implicit.)
  • Method Details

    • featureRequested

      public static boolean featureRequested(int flags, short feature)
      Returns true if the given feature is requested in the flags, false otherwise.
    • freq

      public abstract int freq() throws IOException
      Returns term frequency in the current document, or 1 if the field was indexed with IndexOptions.DOCS. Do not call this before DocIdSetIterator.nextDoc() is first called, nor after DocIdSetIterator.nextDoc() returns DocIdSetIterator.NO_MORE_DOCS.

      NOTE: if the PostingsEnum was obtain with NONE, the result of this method is undefined.

      Throws:
      IOException
    • nextPosition

      public abstract int nextPosition() throws IOException
      Returns the next position, or -1 if positions were not indexed. Calling this more than freq() times is undefined.
      Throws:
      IOException
    • startOffset

      public abstract int startOffset() throws IOException
      Returns start offset for the current position, or -1 if offsets were not indexed.
      Throws:
      IOException
    • endOffset

      public abstract int endOffset() throws IOException
      Returns end offset for the current position, or -1 if offsets were not indexed.
      Throws:
      IOException
    • getPayload

      public abstract BytesRef getPayload() throws IOException
      Returns the payload at this position, or null if no payload was indexed. You should not modify anything (neither members of the returned BytesRef nor bytes in the byte[]).
      Throws:
      IOException
    • nextPostings

      public void nextPostings(int upTo, DocAndFloatFeatureBuffer buffer) throws IOException
      Fill a buffer of doc IDs and frequencies with some number of doc IDs and their corresponding frequencies, starting at the current doc ID, and ending before upTo. Because it starts on the current doc ID, it is illegal to call this method if the current doc ID is -1.

      An empty buffer after this method returns indicates that there are no postings left between the current doc ID and upTo.

      Implementations should ideally fill the buffer with a number of entries comprised between 8 and a couple hundreds, to keep heap requirements contained, while still being large enough to enable operations on the buffer to auto-vectorize efficiently.

      The default implementation is provided below:

       int batchSize = 16; // arbitrary
       buffer.growNoCopy(batchSize);
       int size = 0;
       for (int doc = docID(); doc < upTo && size < batchSize; doc = nextDoc()) {
         buffer.docs[size] = doc;
         buffer.freqs[size] = freq();
         ++size;
       }
       buffer.size = size;
       

      NOTE: The provided DocAndFloatFeatureBuffer should not hold references to internal data structures.

      Throws:
      IOException
      NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.