|
| Token () |
| Constructs a Token will null text. More...
|
|
| Token (int32_t start, int32_t end) |
| Constructs a Token with null text and start and end offsets. More...
|
|
| Token (int32_t start, int32_t end, const String &type) |
| Constructs a Token with null text and start and end offsets plus the Token type. More...
|
|
| Token (int32_t start, int32_t end, int32_t flags) |
| Constructs a Token with null text and start and end offsets plus flags. More...
|
|
| Token (const String &text, int32_t start, int32_t end) |
| Constructs a Token with the given term text, start and 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. More...
|
|
| Token (const String &text, int32_t start, int32_t end, const String &type) |
| Constructs a Token with the given term text, start and end offsets and type. NOTE: for better indexing speed you should instead use the char[] termBuffer methods to set the term text. More...
|
|
| Token (const String &text, int32_t start, int32_t end, int32_t flags) |
| Constructs a Token with the given term text, start and end offsets and flags. NOTE: for better indexing speed you should instead use the char[] termBuffer methods to set the term text. More...
|
|
| Token (CharArray startTermBuffer, int32_t termBufferOffset, int32_t termBufferLength, int32_t start, int32_t end) |
| Constructs a Token with the given term buffer (offset and length), start and end offsets. More...
|
|
virtual | ~Token () |
|
virtual String | getClassName () |
|
boost::shared_ptr< Token > | shared_from_this () |
|
virtual void | setPositionIncrement (int32_t positionIncrement) |
| Set the position increment. This determines the position of this token relative to the previous Token in a TokenStream , used in phrase searching. More...
|
|
virtual int32_t | getPositionIncrement () |
| Returns the position increment of this Token. More...
|
|
virtual String | term () |
| Returns the Token's term text. More...
|
|
virtual void | setTermBuffer (const wchar_t *buffer, int32_t offset, int32_t length) |
| Copies the contents of buffer, starting at offset for length characters, into the termBuffer array. More...
|
|
virtual void | setTermBuffer (const String &buffer) |
| Copies the contents of buffer into the termBuffer array. More...
|
|
virtual void | setTermBuffer (const String &buffer, int32_t offset, int32_t length) |
| Copies the contents of buffer, starting at offset and continuing for length characters, into the termBuffer array. More...
|
|
virtual CharArray | termBuffer () |
| Returns the internal termBuffer character array which you can then directly alter. If the array is too small for your token, use resizeTermBuffer(int) to increase it. After altering the buffer be sure to call setTermLength to record the number of valid characters that were placed into the termBuffer. More...
|
|
virtual wchar_t * | termBufferArray () |
| Optimized implementation of termBuffer. More...
|
|
virtual CharArray | resizeTermBuffer (int32_t newSize) |
| 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[], int, int) , setTermBuffer(String) , or setTermBuffer(String, int, int) to optimally combine the resize with the setting of the termBuffer. More...
|
|
virtual int32_t | termLength () |
| Return number of valid characters (length of the term) in the termBuffer array. More...
|
|
virtual void | setTermLength (int32_t length) |
| 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(int) first. More...
|
|
virtual int32_t | startOffset () |
| Returns this Token's starting offset, the position of the first character corresponding to this token in the source text. More...
|
|
virtual void | setStartOffset (int32_t offset) |
| Set the starting offset. More...
|
|
virtual int32_t | 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 - startOffset). More...
|
|
virtual void | setEndOffset (int32_t offset) |
| Set the ending offset. More...
|
|
virtual void | setOffset (int32_t startOffset, int32_t endOffset) |
| Set the starting and ending offset. More...
|
|
virtual String | type () |
| Returns this Token's lexical type. Defaults to "word". More...
|
|
virtual void | setType (const String &type) |
| Set the lexical type. More...
|
|
virtual int32_t | getFlags () |
| 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 TokenFilter s. More...
|
|
virtual void | setFlags (int32_t flags) |
|
virtual PayloadPtr | getPayload () |
| Returns this Token's payload. More...
|
|
virtual void | setPayload (const PayloadPtr &payload) |
| Sets this Token's payload. More...
|
|
virtual String | toString () |
| Returns a string representation of the object. More...
|
|
virtual void | clear () |
| Resets the term text, payload, flags, and positionIncrement, startOffset, endOffset and token type to default. More...
|
|
virtual LuceneObjectPtr | clone (const LuceneObjectPtr &other=LuceneObjectPtr()) |
| Shallow clone. Subclasses must override this if they need to clone any members deeply. More...
|
|
TokenPtr | clone (CharArray newTermBuffer, int32_t newTermOffset, int32_t newTermLength, int32_t newStartOffset, int32_t newEndOffset) |
| Makes a clone, but replaces the term buffer and 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. More...
|
|
virtual bool | equals (const LuceneObjectPtr &other) |
| All values used for computation of hashCode() should be checked here for equality. More...
|
|
virtual int32_t | hashCode () |
| Subclasses must implement this method and should compute a hashCode similar to this: More...
|
|
TokenPtr | reinit (CharArray newTermBuffer, int32_t newTermOffset, int32_t newTermLength, int32_t newStartOffset, int32_t newEndOffset, const String &newType) |
| Shorthand for calling clear , setTermBuffer(char[], int, int) , setStartOffset , setEndOffset , setType . More...
|
|
TokenPtr | reinit (CharArray newTermBuffer, int32_t newTermOffset, int32_t newTermLength, int32_t newStartOffset, int32_t newEndOffset) |
| Shorthand for calling clear , setTermBuffer(char[], int, int) , setStartOffset , setEndOffset , setType on Token::DEFAULT_TYPE. More...
|
|
TokenPtr | reinit (const String &newTerm, int32_t newStartOffset, int32_t newEndOffset, const String &newType) |
| Shorthand for calling clear , setTermBuffer(String) , setStartOffset , setEndOffset , setType . More...
|
|
TokenPtr | reinit (const String &newTerm, int32_t newTermOffset, int32_t newTermLength, int32_t newStartOffset, int32_t newEndOffset, const String &newType) |
| Shorthand for calling clear , setTermBuffer(String) , setStartOffset , setEndOffset , setType . More...
|
|
TokenPtr | reinit (const String &newTerm, int32_t newStartOffset, int32_t newEndOffset) |
| Shorthand for calling clear , setTermBuffer(String) , setStartOffset , setEndOffset , setType on Token::DEFAULT_TYPE. More...
|
|
TokenPtr | reinit (const String &newTerm, int32_t newTermOffset, int32_t newTermLength, int32_t newStartOffset, int32_t newEndOffset) |
| Shorthand for calling clear , setTermBuffer(String, int, int) , setStartOffset , setEndOffset , setType on Token::DEFAULT_TYPE. More...
|
|
void | reinit (const TokenPtr &prototype) |
| Copy the prototype token's fields into this one. Note: Payloads are shared. More...
|
|
void | reinit (const TokenPtr &prototype, const String &newTerm) |
| Copy the prototype token's fields into this one, with a different term. Note: Payloads are shared. More...
|
|
void | reinit (const TokenPtr &prototype, CharArray newTermBuffer, int32_t offset, int32_t length) |
| Copy the prototype token's fields into this one, with a different term. Note: Payloads are shared. More...
|
|
virtual void | copyTo (const AttributePtr &target) |
| Copies the values from this Attribute into the passed-in target attribute. The target implementation must support all the Attributes this implementation supports. More...
|
|
virtual | ~Attribute () |
|
virtual String | getClassName () |
|
boost::shared_ptr< Attribute > | shared_from_this () |
|
virtual void | clear ()=0 |
| Clears the values in this Attribute and resets it to its default value. If this implementation implements more than one Attribute interface it clears all. More...
|
|
virtual int32_t | hashCode ()=0 |
| Subclasses must implement this method and should compute a hashCode similar to this: More...
|
|
virtual bool | equals (const LuceneObjectPtr &other)=0 |
| All values used for computation of hashCode() should be checked here for equality. More...
|
|
virtual void | copyTo (const AttributePtr &target)=0 |
| Copies the values from this Attribute into the passed-in target attribute. The target implementation must support all the Attributes this implementation supports. More...
|
|
virtual LuceneObjectPtr | clone (const LuceneObjectPtr &other=LuceneObjectPtr())=0 |
| Shallow clone. Subclasses must override this if they need to clone any members deeply. More...
|
|
virtual | ~LuceneObject () |
|
virtual void | initialize () |
| Called directly after instantiation to create objects that depend on this object being fully constructed. More...
|
|
virtual LuceneObjectPtr | clone (const LuceneObjectPtr &other=LuceneObjectPtr()) |
| Return clone of this object. More...
|
|
virtual int32_t | hashCode () |
| Return hash code for this object. More...
|
|
virtual bool | equals (const LuceneObjectPtr &other) |
| Return whether two objects are equal. More...
|
|
virtual int32_t | compareTo (const LuceneObjectPtr &other) |
| Compare two objects. More...
|
|
virtual String | toString () |
| Returns a string representation of the object. More...
|
|
virtual | ~LuceneSync () |
|
virtual SynchronizePtr | getSync () |
| Return this object synchronize lock. More...
|
|
virtual LuceneSignalPtr | getSignal () |
| Return this object signal. More...
|
|
virtual void | lock (int32_t timeout=0) |
| Lock this object using an optional timeout. More...
|
|
virtual void | unlock () |
| Unlock this object. More...
|
|
virtual bool | holdsLock () |
| Returns true if this object is currently locked by current thread. More...
|
|
virtual void | wait (int32_t timeout=0) |
| Wait for signal using an optional timeout. More...
|
|
virtual void | notifyAll () |
| Notify all threads waiting for signal. More...
|
|
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, eg., to display highlighted query terms in a document browser, or to show matching text fragments in a <abbr title="KeyWord In Context">KWIC</abbr> 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 TermPositions#getPayloadLength()
and TermPositions#getPayload(byte[], int)
to retrieve the payloads from the index.
Tokenizers and TokenFilters should try to re-use a Token instance when possible for best performance, by implementing the TokenStream#incrementToken()
API. Failing that, to create a new Token you should first use one of the constructors that starts with null text. To load the token from a char[] use setTermBuffer(char[], int, int)
. To load from a String use setTermBuffer(String)
or setTermBuffer(String, int, int)
. Alternatively you can get the Token's termBuffer by calling either termBuffer()
, if you know that your text is shorter than the capacity of the termBuffer or resizeTermBuffer(int)
, if there is any possibility that you may need to grow the buffer. Fill in the characters of your term into this buffer, with String#getChars(int, int, char[], int)
if loading from a string, or with System#arraycopy(Object, int, Object, int, int)
, and finally call setTermLength(int)
to set the length of the term text.
Typical Token reuse patterns:
Copying text from a string (type is reset to DEFAULT_TYPE
if not specified):
return reusableToken->reinit(string, startOffset, endOffset[, type]);
Copying some text from a string (type is reset to DEFAULT_TYPE
if not specified):
return reusableToken->reinit(string, 0, string.length(), startOffset, endOffset[, type]);
Copying text from char[] buffer (type is reset to DEFAULT_TYPE
if not specified):
return reusableToken->reinit(buffer, 0, buffer.length, startOffset, endOffset[, type]);
Copying some text from a char[] buffer (type is reset to DEFAULT_TYPE
if not specified):
return reusableToken->reinit(buffer, start, end - start, startOffset, endOffset[, type]);
Copying from one one Token to another (type is reset to DEFAULT_TYPE
if not specified):
return reusableToken.reinit(source.termBuffer(), 0, source.termLength(), source.startOffset(), source.endOffset()[, source.type()]);
A few things to note: clear() initializes all of the fields to default values. This was changed in contrast to Lucene 2.4, but should affect no one. Because TokenStreams can be chained, one cannot assume that the Token's current type is correct. The startOffset and endOffset represent the start and offset in the source text, so be careful in adjusting them. When caching a reusable token, clone it. When injecting a cached token into a stream that can be reset, clone it again.
- See also
- Payload