Class OrdinalsBuilder
- java.lang.Object
-
- org.elasticsearch.index.fielddata.ordinals.OrdinalsBuilder
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public final class OrdinalsBuilder extends java.lang.Object implements java.io.CloseableSimple class to build document ID <-> ordinal mapping. Note: Ordinals are1based monotonically increasing positive integers.0donates the missing value in this context.
-
-
Field Summary
Fields Modifier and Type Field Description static floatDEFAULT_ACCEPTABLE_OVERHEAD_RATIODefault acceptable overhead ratio.static java.lang.StringFORCE_MULTI_ORDINALSWhether to for the use ofMultiOrdinalsto store the ordinals for testing purposes.
-
Constructor Summary
Constructors Constructor Description OrdinalsBuilder(int maxDoc)OrdinalsBuilder(int maxDoc, float acceptableOverheadRatio)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description OrdinalsBuilderaddDoc(int doc)Associates the given document id with the current ordinal.Ordinalsbuild()Builds anOrdinalsinstance from the builders current state.org.apache.lucene.util.BitSetbuildDocsWithValuesSet()Builds aBitSetwhere each documents bit is that that has one or more ordinals associated with it.org.apache.lucene.util.BytesRefIteratorbuildFromTerms(org.apache.lucene.index.TermsEnum termsEnum)This method iterates all terms in the givenTermsEnumand associates each terms ordinal with the terms documents.voidclose()Closes this builder and release all resources.longcurrentOrdinal()Returns the current ordinal or0if this build has not been advanced vianextOrdinal().org.apache.lucene.util.LongsRefdocOrds(int docID)Returns a sharedLongsRefinstance for the given doc ID holding all ordinals associated with it.org.apache.lucene.util.packed.PackedInts.ReadergetFirstOrdinals()Return aPackedInts.Readerinstance mapping every doc ID to its first ordinal + 1 if it exists and 0 otherwise.intgetNumDocsWithValue()Returns the number distinct of document IDs with one or more values.intgetNumMultiValuesDocs()Returns the number distinct of document IDs associated with two or more values.intgetNumSingleValuedDocs()Returns the number distinct of document IDs associated with exactly one value.intgetTotalNumOrds()Returns the number of document ID to ordinal pairs in this builder.longgetValueCount()Returns the number of distinct ordinals in this builder.booleanisMultiValued()Returnstrueiff this builder contains a document ID that is associated with more than one ordinal.intmaxDoc()Returns the maximum document ID this builder can associate with an ordinallongnextOrdinal()Advances theOrdinalsBuilderto the next ordinal and return the current ordinal.
-
-
-
Field Detail
-
FORCE_MULTI_ORDINALS
public static final java.lang.String FORCE_MULTI_ORDINALS
Whether to for the use ofMultiOrdinalsto store the ordinals for testing purposes.- See Also:
- Constant Field Values
-
DEFAULT_ACCEPTABLE_OVERHEAD_RATIO
public static final float DEFAULT_ACCEPTABLE_OVERHEAD_RATIO
Default acceptable overhead ratio.OrdinalsBuildermemory 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
-
-
Method Detail
-
docOrds
public org.apache.lucene.util.LongsRef docOrds(int docID)
Returns a sharedLongsRefinstance for the given doc ID holding all ordinals associated with it.
-
getFirstOrdinals
public org.apache.lucene.util.packed.PackedInts.Reader getFirstOrdinals()
Return aPackedInts.Readerinstance mapping every doc ID to its first ordinal + 1 if it exists and 0 otherwise.
-
nextOrdinal
public long nextOrdinal()
Advances theOrdinalsBuilderto the next ordinal and return the current ordinal.
-
currentOrdinal
public long currentOrdinal()
Returns the current ordinal or0if this build has not been advanced vianextOrdinal().
-
addDoc
public OrdinalsBuilder addDoc(int doc)
Associates the given document id with the current ordinal.
-
isMultiValued
public boolean isMultiValued()
Returnstrueiff this builder contains a document ID that is associated with more than one ordinal. Otherwisefalse;
-
getNumDocsWithValue
public int getNumDocsWithValue()
Returns the number distinct of document IDs with one or more values.
-
getNumSingleValuedDocs
public int getNumSingleValuedDocs()
Returns the number distinct of document IDs associated with exactly one value.
-
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.
-
buildDocsWithValuesSet
public org.apache.lucene.util.BitSet buildDocsWithValuesSet()
Builds aBitSetwhere each documents bit is that that has one or more ordinals associated with it. if every document has an ordinal associated with it this method returnsnull
-
maxDoc
public int maxDoc()
Returns the maximum document ID this builder can associate with an ordinal
-
buildFromTerms
public org.apache.lucene.util.BytesRefIterator buildFromTerms(org.apache.lucene.index.TermsEnum termsEnum) throws java.io.IOExceptionThis method iterates all terms in the givenTermsEnumand associates each terms ordinal with the terms documents. The caller must exhaust the returnedBytesRefIteratorwhich returns all values where the first returned value is associated with the ordinal1etc.- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOExceptionCloses this builder and release all resources.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
-