The context property of the getTypeToSearch
response object containing methods used to control the context that can be passed for dynamic filtering.
context Methods
The context property of the getTypeToSearch
response object contains the following methods:
NAME/TYPE | DESCRIPTION |
---|---|
function | Used to get the entire context object or to get a single value if a key is passed in. |
function | Used to set a contextual variable that can be used to create dynamic rules. |
function | Used to delete a specific key within the context object. |
function | Deletes every variable currently in the context object. |
context.get Params
The get
method accepts the following option:
NAME/TYPE | DESCRIPTION |
---|---|
string | The key within the context that you want to get the value for. If no key is provided, the entire context object will be returned. |
context.set Params
The set
method accepts the following options:
NAME/TYPE | DESCRIPTION |
---|---|
string | The key that the contextual variable will be set to. This is the value that will be input in the filter configuration in the platform. |
string | The value that the contextual variable will be set to. This is the value that will be used in place of the variable within the filter. |
context.delete Params
The delete
method accepts the following option:
NAME/TYPE | DESCRIPTION |
---|---|
string | The key of the contextual variable that will be deleted. |
Example
In this example we first get a type-to-search object. We then use the context
property to set the "category"
contextual variable. We also pass in some additional context within the search
method to set the gender
variable. These two contexts will be appended to each other and will not override the other unless they have conflicting variable names.
// Start a type to search session
const tts = getTypeToSearch(console.log, { deploymentId: '3d8e3aa4-b1e9-4b1b-9ff6-ca4bc64806d0' });
// Set a contextual varible
tts.context.set('category', 'shoes');
// Configure context without context prop
const additionalContext = {
gender: 'male'
}
tts.search('party shoes', { context: additionalContext });