- java.lang.Object
-
- org.apache.lucene.index.TermStates
-
public final class TermStates extends java.lang.Object
Maintains aIndexReader
TermState
view overIndexReader
instances containing a single term. TheTermStates
doesn't track if the givenTermState
objects are valid, neither if theTermState
instances refer to the same terms in the associated readers.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
TermStates.TermStateInfo
Wrapper over TermState, ordinal value, term doc frequency and total term frequency
-
Field Summary
Fields Modifier and Type Field Description private int
docFreq
private static TermState
EMPTY_TERMSTATE
private TermState[]
states
private Term
term
private java.lang.Object
topReaderContextIdentity
private long
totalTermFreq
-
Constructor Summary
Constructors Modifier Constructor Description TermStates(IndexReaderContext context)
Creates an emptyTermStates
from aIndexReaderContext
TermStates(IndexReaderContext context, TermState state, int ord, int docFreq, long totalTermFreq)
private
TermStates(Term term, IndexReaderContext context)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
accumulateStatistics(int docFreq, long totalTermFreq)
Expert: Accumulate term statistics.static TermStates
build(IndexSearcher indexSearcher, Term term, boolean needsStats)
void
clear()
Clears theTermStates
internal state and removes all registeredTermState
sint
docFreq()
Returns the accumulated document frequency of allTermState
instances passed toregister(TermState, int, int, long)
.TermState
get(LeafReaderContext ctx)
private static TermsEnum
loadTermsEnum(LeafReaderContext ctx, Term term)
void
register(TermState state, int ord)
Expert: Registers and associates aTermState
with an leaf ordinal.void
register(TermState state, int ord, int docFreq, long totalTermFreq)
Registers and associates aTermState
with an leaf ordinal.java.lang.String
toString()
long
totalTermFreq()
Returns the accumulated term frequency of allTermState
instances passed toregister(TermState, int, int, long)
.boolean
wasBuiltFor(IndexReaderContext context)
Expert: Return whether thisTermStates
was built for the givenIndexReaderContext
.
-
-
-
Constructor Detail
-
TermStates
private TermStates(Term term, IndexReaderContext context)
-
TermStates
public TermStates(IndexReaderContext context)
Creates an emptyTermStates
from 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 thisTermStates
was built for the givenIndexReaderContext
. This is typically used for assertions.
-
build
public static TermStates build(IndexSearcher indexSearcher, Term term, boolean needsStats) throws java.io.IOException
Creates aTermStates
from a top-levelIndexReaderContext
and 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 returnedTermStates
using the leaf reader's ordinal.Note: the given context must be a top-level context.
- Parameters:
needsStats
- iftrue
then all leaf contexts will be visited up-front to collect term statistics. Otherwise, theTermState
objects 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 theTermStates
internal state and removes all registeredTermState
s
-
register
public void register(TermState state, int ord, int docFreq, long totalTermFreq)
Registers and associates aTermState
with 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 aTermState
with 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 theTermState
for a leaf reader context ornull
if noTermState
for the context was registered.- Parameters:
ctx
- theLeafReaderContext
to get theTermState
for.- Returns:
- the
TermState
for the given readers ord ornull
if noTermState
for the reader was registered - Throws:
java.io.IOException
-
docFreq
public int docFreq()
Returns the accumulated document frequency of allTermState
instances passed toregister(TermState, int, int, long)
.- Returns:
- the accumulated document frequency of all
TermState
instances passed toregister(TermState, int, int, long)
.
-
totalTermFreq
public long totalTermFreq()
Returns the accumulated term frequency of allTermState
instances passed toregister(TermState, int, int, long)
.- Returns:
- the accumulated term frequency of all
TermState
instances passed toregister(TermState, int, int, long)
.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-