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 Payload
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 |
---|---|
End |
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 Token |
Payload | Returns this Token's payload. |
Position |
Set the position increment. This determines the position of this token
relative to the previous Token in a Token The default value is one. Some common uses for this are: |
Start |
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 Term |
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 Term |
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. |
Copy |
|
Equals(Object) | |
Get |
|
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(),
Set |
Reinit(Char[], Int32, Int32, Int32, Int32, String) | Shorthand for calling Clear(),
Set |
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(),
|
Resize |
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
Set |
Set |
Set the starting and ending offset. See StartOffset() and EndOffset() |
Set |
Copies the contents of buffer, starting at offset for length characters, into the termBuffer array. |
Set |
Copies the contents of buffer into the termBuffer array. |
Set |
Copies the contents of buffer, starting at offset and continuing for length characters, into the termBuffer array. |
Set |
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 Resize |
Term |
Returns the internal termBuffer character array which
you can then directly alter. If the array is too
small for your token, use Resize |
Term |
Return number of valid characters (length of the term) in the termBuffer array. |
To |