Class OrdinalsBuilder

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public final class OrdinalsBuilder
    extends java.lang.Object
    implements java.io.Closeable
    Simple class to build document ID <-> ordinal mapping. Note: Ordinals are 1 based monotonically increasing positive integers. 0 donates the missing value in this context.
    • Constructor Summary

      Constructors 
      Constructor Description
      OrdinalsBuilder​(int maxDoc)  
      OrdinalsBuilder​(int maxDoc, float acceptableOverheadRatio)  
    • Method Summary

      Modifier and Type Method Description
      OrdinalsBuilder addDoc​(int doc)
      Associates the given document id with the current ordinal.
      Ordinals build()
      Builds an Ordinals instance from the builders current state.
      void close()
      Closes this builder and release all resources.
      long currentOrdinal()
      Returns the current ordinal or 0 if this build has not been advanced via nextOrdinal().
      org.apache.lucene.util.LongsRef docOrds​(int docID)
      Returns a shared LongsRef instance for the given doc ID holding all ordinals associated with it.
      org.apache.lucene.util.packed.PackedInts.Reader getFirstOrdinals()
      Return a PackedInts.Reader instance mapping every doc ID to its first ordinal + 1 if it exists and 0 otherwise.
      int getNumMultiValuesDocs()
      Returns the number distinct of document IDs associated with two or more values.
      int getTotalNumOrds()
      Returns the number of document ID to ordinal pairs in this builder.
      long getValueCount()
      Returns the number of distinct ordinals in this builder.
      int maxDoc()
      Returns the maximum document ID this builder can associate with an ordinal
      long nextOrdinal()
      Advances the OrdinalsBuilder to the next ordinal and return the current ordinal.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DEFAULT_ACCEPTABLE_OVERHEAD_RATIO

        public static final float DEFAULT_ACCEPTABLE_OVERHEAD_RATIO
        Default acceptable overhead ratio. OrdinalsBuilder memory usage is mostly transient so it is likely a better trade-off to trade memory for speed in order to resize less often.
        See Also:
        Constant Field Values
    • Constructor Detail

      • OrdinalsBuilder

        public OrdinalsBuilder​(int maxDoc,
                               float acceptableOverheadRatio)
      • OrdinalsBuilder

        public OrdinalsBuilder​(int maxDoc)
    • Method Detail

      • docOrds

        public org.apache.lucene.util.LongsRef docOrds​(int docID)
        Returns a shared LongsRef instance for the given doc ID holding all ordinals associated with it.
      • getFirstOrdinals

        public org.apache.lucene.util.packed.PackedInts.Reader getFirstOrdinals()
        Return a PackedInts.Reader instance mapping every doc ID to its first ordinal + 1 if it exists and 0 otherwise.
      • nextOrdinal

        public long nextOrdinal()
        Advances the OrdinalsBuilder to the next ordinal and return the current ordinal.
      • currentOrdinal

        public long currentOrdinal()
        Returns the current ordinal or 0 if this build has not been advanced via nextOrdinal().
      • addDoc

        public OrdinalsBuilder addDoc​(int doc)
        Associates the given document id with the current ordinal.
      • getNumMultiValuesDocs

        public int getNumMultiValuesDocs()
        Returns the number distinct of document IDs associated with two or more values.
      • getTotalNumOrds

        public int getTotalNumOrds()
        Returns the number of document ID to ordinal pairs in this builder.
      • getValueCount

        public long getValueCount()
        Returns the number of distinct ordinals in this builder.
      • build

        public Ordinals build()
        Builds an Ordinals instance from the builders current state.
      • maxDoc

        public int maxDoc()
        Returns the maximum document ID this builder can associate with an ordinal
      • close

        public void close()
                   throws java.io.IOException
        Closes this builder and release all resources.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException