Class PackedTokenAttributeImpl
- java.lang.Object
-
- org.apache.lucene.util.AttributeImpl
-
- org.apache.lucene.analysis.tokenattributes.CharTermAttributeImpl
-
- org.apache.lucene.analysis.tokenattributes.PackedTokenAttributeImpl
-
- All Implemented Interfaces:
Appendable
,CharSequence
,Cloneable
,CharTermAttribute
,OffsetAttribute
,PositionIncrementAttribute
,PositionLengthAttribute
,TermFrequencyAttribute
,TermToBytesRefAttribute
,TypeAttribute
,Attribute
public class PackedTokenAttributeImpl extends CharTermAttributeImpl implements TypeAttribute, PositionIncrementAttribute, PositionLengthAttribute, OffsetAttribute, TermFrequencyAttribute
Default implementation of the common attributes used by Lucene:
-
-
Field Summary
-
Fields inherited from class org.apache.lucene.analysis.tokenattributes.CharTermAttributeImpl
builder
-
Fields inherited from interface org.apache.lucene.analysis.tokenattributes.TypeAttribute
DEFAULT_TYPE
-
-
Constructor Summary
Constructors Constructor Description PackedTokenAttributeImpl()
Constructs the attribute implementation.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Resets the attributesPackedTokenAttributeImpl
clone()
In most cases the clone is, and should be, deep in order to be able to properly capture the state of all attributes.void
copyTo(AttributeImpl target)
Copies the values from this Attribute into the passed-in target attribute.void
end()
Resets the attributes at endint
endOffset()
Returns this Token's ending offset, one greater than the position of the last character corresponding to this token in the source text.boolean
equals(Object obj)
int
getPositionIncrement()
Returns the position increment of this Token.int
getPositionLength()
Returns the position length of this Token.int
getTermFrequency()
Returns the custom term frequency.int
hashCode()
void
reflectWith(AttributeReflector reflector)
This method is for introspection of attributes, it should simply add the key/values this attribute holds to the givenAttributeReflector
.void
setOffset(int startOffset, int endOffset)
Set the starting and ending offset.void
setPositionIncrement(int positionIncrement)
Set the position increment.void
setPositionLength(int positionLength)
Set the position length of this Token.void
setTermFrequency(int termFrequency)
Set the custom term frequency of the current term within one document.void
setType(String type)
Set the lexical type.int
startOffset()
Returns this Token's starting offset, the position of the first character corresponding to this token in the source text.String
type()
Returns this Token's lexical type.-
Methods inherited from class org.apache.lucene.analysis.tokenattributes.CharTermAttributeImpl
append, append, append, append, append, append, buffer, charAt, copyBuffer, getBytesRef, length, resizeBuffer, setEmpty, setLength, subSequence, toString
-
Methods inherited from class org.apache.lucene.util.AttributeImpl
reflectAsString
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.CharSequence
chars, codePoints
-
-
-
-
Method Detail
-
setPositionIncrement
public void setPositionIncrement(int positionIncrement)
Set the position increment. The default value is one.- Specified by:
setPositionIncrement
in interfacePositionIncrementAttribute
- Parameters:
positionIncrement
- the distance from the prior term- See Also:
PositionIncrementAttribute
-
getPositionIncrement
public int getPositionIncrement()
Returns the position increment of this Token.- Specified by:
getPositionIncrement
in interfacePositionIncrementAttribute
- See Also:
PositionIncrementAttribute
-
setPositionLength
public void setPositionLength(int positionLength)
Set the position length of this Token.The default value is one.
- Specified by:
setPositionLength
in interfacePositionLengthAttribute
- Parameters:
positionLength
- how many positions this token spans.- See Also:
PositionLengthAttribute
-
getPositionLength
public int getPositionLength()
Returns the position length of this Token.- Specified by:
getPositionLength
in interfacePositionLengthAttribute
- See Also:
PositionLengthAttribute
-
startOffset
public final int startOffset()
Returns this Token's starting offset, the position of the first character corresponding to this token in the source text.Note that the difference between
OffsetAttribute.endOffset()
andstartOffset()
may not be equal to termText.length(), as the term text may have been altered by a stemmer or some other filter.- Specified by:
startOffset
in interfaceOffsetAttribute
- See Also:
OffsetAttribute
-
endOffset
public final int endOffset()
Returns this Token's ending offset, one greater than the position of the last character corresponding to this token in the source text. The length of the token in the source text is (endOffset()
-OffsetAttribute.startOffset()
).- Specified by:
endOffset
in interfaceOffsetAttribute
- See Also:
OffsetAttribute
-
setOffset
public void setOffset(int startOffset, int endOffset)
Set the starting and ending offset.- Specified by:
setOffset
in interfaceOffsetAttribute
- See Also:
OffsetAttribute
-
type
public final String type()
Returns this Token's lexical type. Defaults to "word".- Specified by:
type
in interfaceTypeAttribute
- See Also:
TypeAttribute
-
setType
public final void setType(String type)
Set the lexical type.- Specified by:
setType
in interfaceTypeAttribute
- See Also:
TypeAttribute
-
setTermFrequency
public final void setTermFrequency(int termFrequency)
Description copied from interface:TermFrequencyAttribute
Set the custom term frequency of the current term within one document.- Specified by:
setTermFrequency
in interfaceTermFrequencyAttribute
-
getTermFrequency
public final int getTermFrequency()
Description copied from interface:TermFrequencyAttribute
Returns the custom term frequency.- Specified by:
getTermFrequency
in interfaceTermFrequencyAttribute
-
clear
public void clear()
Resets the attributes- Overrides:
clear
in classCharTermAttributeImpl
-
end
public void end()
Resets the attributes at end- Overrides:
end
in classAttributeImpl
-
clone
public PackedTokenAttributeImpl clone()
Description copied from class:AttributeImpl
In most cases the clone is, and should be, deep in order to be able to properly capture the state of all attributes.- Overrides:
clone
in classCharTermAttributeImpl
-
equals
public boolean equals(Object obj)
- Overrides:
equals
in classCharTermAttributeImpl
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classCharTermAttributeImpl
-
copyTo
public void copyTo(AttributeImpl target)
Description copied from class:AttributeImpl
Copies the values from this Attribute into the passed-in target attribute. The target implementation must support all the Attributes this implementation supports.- Overrides:
copyTo
in classCharTermAttributeImpl
-
reflectWith
public void reflectWith(AttributeReflector reflector)
Description copied from class:AttributeImpl
This method is for introspection of attributes, it should simply add the key/values this attribute holds to the givenAttributeReflector
.Implementations look like this (e.g. for a combined attribute implementation):
public void reflectWith(AttributeReflector reflector) { reflector.reflect(CharTermAttribute.class, "term", term()); reflector.reflect(PositionIncrementAttribute.class, "positionIncrement", getPositionIncrement()); }
If you implement this method, make sure that for each invocation, the same set of
Attribute
interfaces and keys are passed toAttributeReflector.reflect(java.lang.Class<? extends org.apache.lucene.util.Attribute>, java.lang.String, java.lang.Object)
in the same order, but possibly different values. So don't automatically exclude e.g.null
properties!- Overrides:
reflectWith
in classCharTermAttributeImpl
- See Also:
AttributeImpl.reflectAsString(boolean)
-
-