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 voidclear()Resets the attributesPackedTokenAttributeImplclone()In most cases the clone is, and should be, deep in order to be able to properly capture the state of all attributes.voidcopyTo(AttributeImpl target)Copies the values from this Attribute into the passed-in target attribute.voidend()Resets the attributes at endintendOffset()Returns this Token's ending offset, one greater than the position of the last character corresponding to this token in the source text.booleanequals(Object obj)intgetPositionIncrement()Returns the position increment of this Token.intgetPositionLength()Returns the position length of this Token.intgetTermFrequency()Returns the custom term frequency.inthashCode()voidreflectWith(AttributeReflector reflector)This method is for introspection of attributes, it should simply add the key/values this attribute holds to the givenAttributeReflector.voidsetOffset(int startOffset, int endOffset)Set the starting and ending offset.voidsetPositionIncrement(int positionIncrement)Set the position increment.voidsetPositionLength(int positionLength)Set the position length of this Token.voidsetTermFrequency(int termFrequency)Set the custom term frequency of the current term within one document.voidsetType(String type)Set the lexical type.intstartOffset()Returns this Token's starting offset, the position of the first character corresponding to this token in the source text.Stringtype()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:
setPositionIncrementin 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:
getPositionIncrementin interfacePositionIncrementAttribute- See Also:
PositionIncrementAttribute
-
setPositionLength
public void setPositionLength(int positionLength)
Set the position length of this Token.The default value is one.
- Specified by:
setPositionLengthin 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:
getPositionLengthin 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:
startOffsetin 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:
endOffsetin interfaceOffsetAttribute- See Also:
OffsetAttribute
-
setOffset
public void setOffset(int startOffset, int endOffset)Set the starting and ending offset.- Specified by:
setOffsetin interfaceOffsetAttribute- See Also:
OffsetAttribute
-
type
public final String type()
Returns this Token's lexical type. Defaults to "word".- Specified by:
typein interfaceTypeAttribute- See Also:
TypeAttribute
-
setType
public final void setType(String type)
Set the lexical type.- Specified by:
setTypein interfaceTypeAttribute- See Also:
TypeAttribute
-
setTermFrequency
public final void setTermFrequency(int termFrequency)
Description copied from interface:TermFrequencyAttributeSet the custom term frequency of the current term within one document.- Specified by:
setTermFrequencyin interfaceTermFrequencyAttribute
-
getTermFrequency
public final int getTermFrequency()
Description copied from interface:TermFrequencyAttributeReturns the custom term frequency.- Specified by:
getTermFrequencyin interfaceTermFrequencyAttribute
-
clear
public void clear()
Resets the attributes- Overrides:
clearin classCharTermAttributeImpl
-
end
public void end()
Resets the attributes at end- Overrides:
endin classAttributeImpl
-
clone
public PackedTokenAttributeImpl clone()
Description copied from class:AttributeImplIn most cases the clone is, and should be, deep in order to be able to properly capture the state of all attributes.- Overrides:
clonein classCharTermAttributeImpl
-
equals
public boolean equals(Object obj)
- Overrides:
equalsin classCharTermAttributeImpl
-
hashCode
public int hashCode()
- Overrides:
hashCodein classCharTermAttributeImpl
-
copyTo
public void copyTo(AttributeImpl target)
Description copied from class:AttributeImplCopies the values from this Attribute into the passed-in target attribute. The target implementation must support all the Attributes this implementation supports.- Overrides:
copyToin classCharTermAttributeImpl
-
reflectWith
public void reflectWith(AttributeReflector reflector)
Description copied from class:AttributeImplThis 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
Attributeinterfaces 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.nullproperties!- Overrides:
reflectWithin classCharTermAttributeImpl- See Also:
AttributeImpl.reflectAsString(boolean)
-
-