Class Token
A Token is an occurrence of a term from the text of a field. It consists of a term's text, the start and end offset of the term in the text of the field, and a type string.
The start and end offsets permit applications to re-associate a token with its source text, e.g., to display highlighted query terms in a document browser, or to show matching text fragments in a KWIC display, etc.
The type is a string, assigned by a lexical analyzer
(a.k.a. tokenizer), naming the lexical or syntactic class that the token
belongs to. For example an end of sentence marker token might be implemented
with type "eos". The default token type is "word".
A Token can optionally have metadata (a.k.a. Payload) in the form of a variable length byte array. Use PayloadLength and GetPayload(Byte[], Int32) to retrieve the payloads from the index.
Inheritance
Namespace:
Assembly: Lucene.Net.NetCore.dll
Syntax
public class Token : Attribute, ITermAttribute, ITypeAttribute, IPositionIncrementAttribute, IFlagsAttribute, IOffsetAttribute, IPayloadAttribute, IAttribute
Constructors
Name | Description |
---|---|
Token() | Constructs a Token will null text. |
Token(String, Int32, Int32) | Constructs a Token with the given term text, and start & end offsets. The type defaults to "word." NOTE: for better indexing speed you should instead use the char[] termBuffer methods to set the term text. |
Token(Char[], Int32, Int32, Int32, Int32) | Constructs a Token with the given term buffer (offset & length), start and end offsets |
Token(Int32, Int32) | Constructs a Token with null text and start & end offsets. |
Token(Int32, Int32, String) | Constructs a Token with null text and start & end offsets plus the Token type. |
Token(Int32, Int32, Int32) | Constructs a Token with null text and start & end offsets plus flags. NOTE: flags is EXPERIMENTAL. |
Token(String, Int32, Int32, Int32) | Constructs a Token with the given text, start and end offsets, & type. NOTE: for better indexing speed you should instead use the char[] termBuffer methods to set the term text. |
Token(String, Int32, Int32, String) | Constructs a Token with the given text, start and end offsets, & type. NOTE: for better indexing speed you should instead use the char[] termBuffer methods to set the term text. |
Fields
Name | Description |
---|---|
DEFAULT_TYPE | |
TOKEN_ATTRIBUTE_FACTORY | Convenience factory that returns |
Properties
Name | Description |
---|---|
EndOffset | Gets or sets 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 - startOffset). |
Flags | EXPERIMENTAL: While we think this is here to stay, we may want to change it to be a long.
Get the bitset for any bits that have been set. This is completely distinct from Type, although they do share similar purposes. The flags can be used to encode information about the token for use by other TokenFilters. |
Payload | Returns this Token's payload. |
PositionIncrement | Set the position increment. This determines the position of this token relative to the previous Token in a TokenStream, used in phrase searching. The default value is one. Some common uses for this are: |
StartOffset | Gets or sets this Token's starting offset, the position of the first character corresponding to this token in the source text. Note that the difference between endOffset() and startOffset() may not be equal to TermLength(), as the term text may have been altered by a stemmer or some other filter. |
Term | Returns the Token's term text. This method has a performance penalty because the text is stored internally in a char[]. If possible, use TermBuffer() and TermLength() directly instead. If you really need a String, use this method, which is nothing more than a convenience call to new String(token.termBuffer(), 0, token.termLength()) |
Type | Returns this Token's lexical type. Defaults to "word". |
Methods
Name | Description |
---|---|
Clear() | Resets the term text, payload, flags, and positionIncrement, startOffset, endOffset and token type to default. |
Clone() | |
Clone(Char[], Int32, Int32, Int32, Int32) | Makes a clone, but replaces the term buffer & start/end offset in the process. This is more efficient than doing a full clone (and then calling setTermBuffer) because it saves a wasted copy of the old termBuffer. |
CopyTo(Attribute) | |
Equals(Object) | |
GetHashCode() | |
Reinit(Token) | Copy the prototype token's fields into this one. Note: Payloads are shared. |
Reinit(Token, Char[], Int32, Int32) | Copy the prototype token's fields into this one, with a different term. Note: Payloads are shared. |
Reinit(Token, String) | Copy the prototype token's fields into this one, with a different term. Note: Payloads are shared. |
Reinit(Char[], Int32, Int32, Int32, Int32) | Shorthand for calling Clear(), SetTermBuffer(Char[], Int32, Int32), StartOffset, EndOffset Type on Token.DEFAULT_TYPE |
Reinit(Char[], Int32, Int32, Int32, Int32, String) | Shorthand for calling Clear(), SetTermBuffer(Char[], Int32, Int32), StartOffset, EndOffset, Type |
Reinit(String, Int32, Int32) | Shorthand for calling Clear(),
|
Reinit(String, Int32, Int32, Int32, Int32) | Shorthand for calling Clear(),
|
Reinit(String, Int32, Int32, Int32, Int32, String) | Shorthand for calling Clear(),
|
Reinit(String, Int32, Int32, String) | Shorthand for calling Clear(),
|
ResizeTermBuffer(Int32) | Grows the termBuffer to at least size newSize, preserving the
existing content. Note: If the next operation is to change
the contents of the term buffer use
SetTermBuffer(Char[], Int32, Int32),
|
SetOffset(Int32, Int32) | Set the starting and ending offset. See StartOffset() and EndOffset() |
SetTermBuffer(Char[], Int32, Int32) | Copies the contents of buffer, starting at offset for length characters, into the termBuffer array. |
SetTermBuffer(String) | Copies the contents of buffer into the termBuffer array. |
SetTermBuffer(String, Int32, Int32) | Copies the contents of buffer, starting at offset and continuing for length characters, into the termBuffer array. |
SetTermLength(Int32) | Set number of valid characters (length of the term) in the termBuffer array. Use this to truncate the termBuffer or to synchronize with external manipulation of the termBuffer. Note: to grow the size of the array, use ResizeTermBuffer(Int32) first. |
TermBuffer() | Returns the internal termBuffer character array which you can then directly alter. If the array is too small for your token, use ResizeTermBuffer(Int32) to increase it. After altering the buffer be sure to call SetTermLength(Int32) to record the number of valid characters that were placed into the termBuffer. |
TermLength() | Return number of valid characters (length of the term) in the termBuffer array. |
ToString() |