Package org.apache.lucene.index
Class TermStates
java.lang.Object
org.apache.lucene.index.TermStates
Maintains a
IndexReader TermState view over IndexReader instances
containing a single term. The TermStates doesn't track if the given TermState
objects are valid, neither if the TermState instances refer to the same terms in the
associated readers.- WARNING: This API is experimental and might change in incompatible ways in the next release.
-
Constructor Summary
ConstructorsConstructorDescriptionTermStates(IndexReaderContext context) Creates an emptyTermStatesfrom aIndexReaderContextTermStates(IndexReaderContext context, TermState state, int ord, int docFreq, long totalTermFreq) -
Method Summary
Modifier and TypeMethodDescriptionvoidaccumulateStatistics(int docFreq, long totalTermFreq) Expert: Accumulate term statistics.static TermStatesbuild(IndexSearcher indexSearcher, 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).get(LeafReaderContext ctx) voidExpert: Registers and associates aTermStatewith an leaf ordinal.voidRegisters and associates aTermStatewith an leaf ordinal.toString()longReturns the accumulated term frequency of allTermStateinstances passed toregister(TermState, int, int, long).booleanwasBuiltFor(IndexReaderContext context) Expert: Return whether thisTermStateswas built for the givenIndexReaderContext.
-
Constructor Details
-
TermStates
Creates an emptyTermStatesfrom aIndexReaderContext -
TermStates
public TermStates(IndexReaderContext context, TermState state, int ord, int docFreq, long totalTermFreq)
-
-
Method Details
-
wasBuiltFor
Expert: Return whether thisTermStateswas built for the givenIndexReaderContext. This is typically used for assertions.- NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.
-
build
public static TermStates build(IndexSearcher indexSearcher, Term term, boolean needsStats) throws 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:
IOException
-
clear
public void clear()Clears theTermStatesinternal state and removes all registeredTermStates -
register
Registers and associates aTermStatewith an leaf ordinal. The leaf ordinal should be derived from aIndexReaderContext's leaf ord. -
register
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
Returns aSupplierfor aTermStatefor the givenLeafReaderContext. This may returnnullif some cheap checks help figure out that this term doesn't exist in this leaf. TheSuppliermay then also returnnullif the term doesn't exist.Calling this method typically schedules some I/O in the background, so it is recommended to retrieve
Suppliers across all required terms first before callingSupplier.get()on allSuppliers so that the I/O for these terms can be performed in parallel.- Parameters:
ctx- theLeafReaderContextto get theTermStatefor.- Returns:
- a Supplier for a TermState.
- Throws:
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
-