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
builderFields inherited from interface org.apache.lucene.analysis.tokenattributes.TypeAttribute
DEFAULT_TYPE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Resets the attributesclone()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 endfinal intReturns this Token's ending offset, one greater than the position of the last character corresponding to this token in the source text.booleanintReturns the position increment of this Token.intReturns the position length of this Token.final intReturns 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.final voidsetTermFrequency(int termFrequency) Set the custom term frequency of the current term within one document.final voidSet the lexical type.final intReturns this Token's starting offset, the position of the first character corresponding to this token in the source text.final 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, toStringMethods inherited from class org.apache.lucene.util.AttributeImpl
reflectAsStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.CharSequence
chars, codePoints, isEmpty
-
Constructor Details
-
PackedTokenAttributeImpl
public PackedTokenAttributeImpl()Constructs the attribute implementation.
-
-
Method Details
-
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:
-
getPositionIncrement
public int getPositionIncrement()Returns the position increment of this Token.- Specified by:
getPositionIncrementin interfacePositionIncrementAttribute- See Also:
-
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:
-
getPositionLength
public int getPositionLength()Returns the position length of this Token.- Specified by:
getPositionLengthin interfacePositionLengthAttribute- See Also:
-
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:
-
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:
-
setOffset
public void setOffset(int startOffset, int endOffset) Set the starting and ending offset.- Specified by:
setOffsetin interfaceOffsetAttribute- See Also:
-
type
Returns this Token's lexical type. Defaults to "word".- Specified by:
typein interfaceTypeAttribute- See Also:
-
setType
Set the lexical type.- Specified by:
setTypein interfaceTypeAttribute- See Also:
-
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
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
- Overrides:
equalsin classCharTermAttributeImpl
-
hashCode
public int hashCode()- Overrides:
hashCodein classCharTermAttributeImpl
-
copyTo
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
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:
-