new Token(stropt, metadataopt)
A token wraps a string representation of a token as it is passed through the text processing pipeline.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
str |
string |
<optional> |
'' | The string token being wrapped. |
metadata |
object |
<optional> |
{} | Metadata associated with this token. |
Methods
clone(fnopt) → {lunr.Token}
Creates a clone of this token. Optionally a function can be applied to the cloned token.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
fn |
lunr.Token~updateFunction |
<optional> |
An optional function to apply to the cloned token. |
Returns:
- Type
- lunr.Token
toString() → {string}
Returns the token string that is being wrapped by this object.
Returns:
- Type
- string
update(fn) → {lunr.Token}
Applies the given function to the wrapped string token.
Parameters:
Name | Type | Description |
---|---|---|
fn |
lunr.Token~updateFunction | A function to apply to the token string. |
Returns:
- Type
- lunr.Token
Example
token.update(function (str, metadata) {
return str.toUpperCase()
})
Type Definitions
updateFunction(str, metadata)
A token update function is used when updating or optionally when cloning a token.
Parameters:
Name | Type | Description |
---|---|---|
str |
string | The string representation of the token. |
metadata |
Object | All metadata associated with this token. |