Package org.apache.lucene.index
Class FilteredTermsEnum
java.lang.Object
org.apache.lucene.index.TermsEnum
org.apache.lucene.index.FilteredTermsEnum
- All Implemented Interfaces:
BytesRefIterator
- Direct Known Subclasses:
PrefixTermsEnum
,SingleTermsEnum
,TermRangeTermsEnum
Abstract class for enumerating a subset of all terms.
Term enumerations are always ordered by
getComparator()
. Each term in the enumeration is
greater than all that precede it.
Please note: Consumers of this enum cannot
call seek()
, it is forward only; it throws
UnsupportedOperationException
when a seeking method
is called.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static enum
Return value, if term should be accepted or the iteration shouldEND
.Nested classes/interfaces inherited from class org.apache.lucene.index.TermsEnum
TermsEnum.SeekStatus
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionFilteredTermsEnum
(TermsEnum tenum) Creates a filteredTermsEnum
on a terms enum.FilteredTermsEnum
(TermsEnum tenum, boolean startWithSeek) Creates a filteredTermsEnum
on a terms enum. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract FilteredTermsEnum.AcceptStatus
Return if term is accepted, not accepted or the iteration should ended (and possibly seek).Returns the related attributes, the returnedAttributeSource
is shared with the delegateTermsEnum
.int
docFreq()
Returns the number of documents containing the current term.GetDocsEnum
for the current term, with control over whether freqs are required.docsAndPositions
(Bits bits, DocsAndPositionsEnum reuse, int flags) GetDocsAndPositionsEnum
for the current term, with control over whether offsets and payloads are required.Return theBytesRef
Comparator used to sort terms provided by the iterator.next()
Increments the iteration to the nextBytesRef
in the iterator.protected BytesRef
nextSeekTerm
(BytesRef currentTerm) On the first call tonext()
or ifaccept(org.apache.lucene.util.BytesRef)
returnsFilteredTermsEnum.AcceptStatus.YES_AND_SEEK
orFilteredTermsEnum.AcceptStatus.NO_AND_SEEK
, this method will be called to eventually seek the underlying TermsEnum to a new position.long
ord()
Returns ordinal position for current term.This enum does not support seeking!void
seekExact
(long ord) This enum does not support seeking!boolean
This enum does not support seeking!void
This enum does not support seeking!protected final void
setInitialSeekTerm
(BytesRef term) Use this method to set the initialBytesRef
to seek before iterating.term()
Returns current term.Returns the filtered enums term statelong
Returns the total number of occurrences of this term across all documents (the sum of the freq() for each doc that has this term).Methods inherited from class org.apache.lucene.index.TermsEnum
docs, docsAndPositions
-
Constructor Details
-
Method Details
-
accept
Return if term is accepted, not accepted or the iteration should ended (and possibly seek).- Throws:
IOException
-
setInitialSeekTerm
Use this method to set the initialBytesRef
to seek before iterating. This is a convenience method for subclasses that do not overridenextSeekTerm(org.apache.lucene.util.BytesRef)
. If the initial seek term isnull
(default), the enum is empty.You can only use this method, if you keep the default implementation of
nextSeekTerm(org.apache.lucene.util.BytesRef)
. -
nextSeekTerm
On the first call tonext()
or ifaccept(org.apache.lucene.util.BytesRef)
returnsFilteredTermsEnum.AcceptStatus.YES_AND_SEEK
orFilteredTermsEnum.AcceptStatus.NO_AND_SEEK
, this method will be called to eventually seek the underlying TermsEnum to a new position. On the first call,currentTerm
will benull
, later calls will provide the term the underlying enum is positioned at. This method returns per default only one time the initial seek term and thennull
, so no repositioning is ever done.Override this method, if you want a more sophisticated TermsEnum, that repositions the iterator during enumeration. If this method always returns
null
the enum is empty.Please note: This method should always provide a greater term than the last enumerated term, else the behaviour of this enum violates the contract for TermsEnums.
- Throws:
IOException
-
attributes
Returns the related attributes, the returnedAttributeSource
is shared with the delegateTermsEnum
.- Overrides:
attributes
in classTermsEnum
-
term
Description copied from class:TermsEnum
Returns current term. Do not call this when the enum is unpositioned.- Specified by:
term
in classTermsEnum
- Throws:
IOException
-
getComparator
Description copied from interface:BytesRefIterator
Return theBytesRef
Comparator used to sort terms provided by the iterator. This may return null if there are no items or the iterator is not sorted. Callers may invoke this method many times, so it's best to cache a single instance & reuse it. -
docFreq
Description copied from class:TermsEnum
Returns the number of documents containing the current term. Do not call this when the enum is unpositioned.TermsEnum.SeekStatus.END
.- Specified by:
docFreq
in classTermsEnum
- Throws:
IOException
-
totalTermFreq
Description copied from class:TermsEnum
Returns the total number of occurrences of this term across all documents (the sum of the freq() for each doc that has this term). This will be -1 if the codec doesn't support this measure. Note that, like other term measures, this measure does not take deleted documents into account.- Specified by:
totalTermFreq
in classTermsEnum
- Throws:
IOException
-
seekExact
This enum does not support seeking!- Overrides:
seekExact
in classTermsEnum
- Throws:
UnsupportedOperationException
- In general, subclasses do not support seeking.IOException
-
seekCeil
This enum does not support seeking!- Specified by:
seekCeil
in classTermsEnum
- Throws:
UnsupportedOperationException
- In general, subclasses do not support seeking.IOException
-
seekExact
This enum does not support seeking!- Specified by:
seekExact
in classTermsEnum
- Throws:
UnsupportedOperationException
- In general, subclasses do not support seeking.IOException
-
ord
Description copied from class:TermsEnum
Returns ordinal position for current term. This is an optional method (the codec may throwUnsupportedOperationException
). Do not call this when the enum is unpositioned.- Specified by:
ord
in classTermsEnum
- Throws:
IOException
-
docs
Description copied from class:TermsEnum
GetDocsEnum
for the current term, with control over whether freqs are required. Do not call this when the enum is unpositioned. This method will not return null.- Specified by:
docs
in classTermsEnum
- Parameters:
bits
- unset bits are documents that should not be returnedreuse
- pass a prior DocsEnum for possible reuseflags
- specifies which optional per-document values you require; seeDocsEnum.FLAG_FREQS
- Throws:
IOException
- See Also:
-
docsAndPositions
public DocsAndPositionsEnum docsAndPositions(Bits bits, DocsAndPositionsEnum reuse, int flags) throws IOException Description copied from class:TermsEnum
GetDocsAndPositionsEnum
for the current term, with control over whether offsets and payloads are required. Some codecs may be able to optimize their implementation when offsets and/or payloads are not required. Do not call this when the enum is unpositioned. This will return null if positions were not indexed.- Specified by:
docsAndPositions
in classTermsEnum
- Parameters:
bits
- unset bits are documents that should not be returnedreuse
- pass a prior DocsAndPositionsEnum for possible reuseflags
- specifies which optional per-position values you require; seeDocsAndPositionsEnum.FLAG_OFFSETS
andDocsAndPositionsEnum.FLAG_PAYLOADS
.- Throws:
IOException
-
seekExact
This enum does not support seeking!- Overrides:
seekExact
in classTermsEnum
- Parameters:
term
- the term the TermState corresponds tostate
- theTermState
- Throws:
UnsupportedOperationException
- In general, subclasses do not support seeking.IOException
-
termState
Returns the filtered enums term state- Overrides:
termState
in classTermsEnum
- Throws:
IOException
- See Also:
-
next
Description copied from interface:BytesRefIterator
Increments the iteration to the nextBytesRef
in the iterator. Returns the resultingBytesRef
ornull
if the end of the iterator is reached. The returned BytesRef may be re-used across calls to next. After this method returns null, do not call it again: the results are undefined.- Returns:
- the next
BytesRef
in the iterator ornull
if the end of the iterator is reached. - Throws:
IOException
- If there is a low-level I/O error.
-