Package org.apache.lucene.index
Class TermStates
- java.lang.Object
-
- org.apache.lucene.index.TermStates
-
public final class TermStates extends java.lang.ObjectMaintains aIndexReaderTermStateview overIndexReaderinstances containing a single term. TheTermStatesdoesn't track if the givenTermStateobjects are valid, neither if theTermStateinstances refer to the same terms in the associated readers.
-
-
Field Summary
Fields Modifier and Type Field Description private intdocFreqprivate static TermStateEMPTY_TERMSTATEprivate TermState[]statesprivate Termtermprivate java.lang.ObjecttopReaderContextIdentityprivate longtotalTermFreq
-
Constructor Summary
Constructors Modifier Constructor Description TermStates(IndexReaderContext context)Creates an emptyTermStatesfrom aIndexReaderContextTermStates(IndexReaderContext context, TermState state, int ord, int docFreq, long totalTermFreq)privateTermStates(Term term, IndexReaderContext context)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaccumulateStatistics(int docFreq, long totalTermFreq)Expert: Accumulate term statistics.static TermStatesbuild(IndexReaderContext context, Term term, boolean needsStats)voidclear()Clears theTermStatesinternal state and removes all registeredTermStatesintdocFreq()Returns the accumulated document frequency of allTermStateinstances passed toregister(TermState, int, int, long).TermStateget(LeafReaderContext ctx)private static TermsEnumloadTermsEnum(LeafReaderContext ctx, Term term)voidregister(TermState state, int ord)Expert: Registers and associates aTermStatewith an leaf ordinal.voidregister(TermState state, int ord, int docFreq, long totalTermFreq)Registers and associates aTermStatewith an leaf ordinal.java.lang.StringtoString()longtotalTermFreq()Returns the accumulated term frequency of allTermStateinstances passed toregister(TermState, int, int, long).booleanwasBuiltFor(IndexReaderContext context)Expert: Return whether thisTermStateswas built for the givenIndexReaderContext.
-
-
-
Constructor Detail
-
TermStates
private TermStates(Term term, IndexReaderContext context)
-
TermStates
public TermStates(IndexReaderContext context)
Creates an emptyTermStatesfrom aIndexReaderContext
-
TermStates
public TermStates(IndexReaderContext context, TermState state, int ord, int docFreq, long totalTermFreq)
-
-
Method Detail
-
wasBuiltFor
public boolean wasBuiltFor(IndexReaderContext context)
Expert: Return whether thisTermStateswas built for the givenIndexReaderContext. This is typically used for assertions.
-
build
public static TermStates build(IndexReaderContext context, Term term, boolean needsStats) throws java.io.IOException
Creates aTermStatesfrom a top-levelIndexReaderContextand the givenTerm. This method will lookup the given term in all context's leaf readers and register each of the readers containing the term in the returnedTermStatesusing the leaf reader's ordinal.Note: the given context must be a top-level context.
- Parameters:
needsStats- iftruethen all leaf contexts will be visited up-front to collect term statistics. Otherwise, theTermStateobjects will be built only when requested- Throws:
java.io.IOException
-
loadTermsEnum
private static TermsEnum loadTermsEnum(LeafReaderContext ctx, Term term) throws java.io.IOException
- Throws:
java.io.IOException
-
clear
public void clear()
Clears theTermStatesinternal state and removes all registeredTermStates
-
register
public void register(TermState state, int ord, int docFreq, long totalTermFreq)
Registers and associates aTermStatewith an leaf ordinal. The leaf ordinal should be derived from aIndexReaderContext's leaf ord.
-
register
public void register(TermState state, int ord)
Expert: Registers and associates aTermStatewith an leaf ordinal. The leaf ordinal should be derived from aIndexReaderContext's leaf ord. On the contrary toregister(TermState, int, int, long)this method does NOT update term statistics.
-
accumulateStatistics
public void accumulateStatistics(int docFreq, long totalTermFreq)Expert: Accumulate term statistics.
-
get
public TermState get(LeafReaderContext ctx) throws java.io.IOException
Returns theTermStatefor a leaf reader context ornullif noTermStatefor the context was registered.- Parameters:
ctx- theLeafReaderContextto get theTermStatefor.- Returns:
- the
TermStatefor the given readers ord ornullif noTermStatefor the reader was registered - Throws:
java.io.IOException
-
docFreq
public int docFreq()
Returns the accumulated document frequency of allTermStateinstances passed toregister(TermState, int, int, long).- Returns:
- the accumulated document frequency of all
TermStateinstances passed toregister(TermState, int, int, long).
-
totalTermFreq
public long totalTermFreq()
Returns the accumulated term frequency of allTermStateinstances passed toregister(TermState, int, int, long).- Returns:
- the accumulated term frequency of all
TermStateinstances passed toregister(TermState, int, int, long).
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-