DictionaryFieldContext (Product Recommendation Engine)
DictionaryFieldContext (Product Recommendation Engine)
Example Implementation
dictionary-field-context.fn.ts
import {buildDictionaryFieldContext} from '@coveo/headless';
import {useContext} from 'react';
import {AppContext} from '../../context/engine';
export function DictionaryFieldContext() {
const {engine} = useContext(AppContext);
const ctx = buildDictionaryFieldContext(engine!);
ctx.set({price_currency: 'fr', price_discounted: 'fr'});
return null;
}
The DictionaryFieldContext
controller allows specifying which dictionary field keys to retrieve.
Methods
add
Adds (or, if one is already present, replaces) a new dictionary field context key-value pair.
Parameters
-
field:
string
The dictionary field name.
-
key:
string
The dictionary field key for which to retrieve a value.
remove
Removes a dictionary field from the query.
Parameters
-
field:
string
The field to remove.
set
Sets the dictionary field context for the query. This replaces any existing context with the new one.
Parameters
-
context:
Record<string, string>
The dictionary field context to set for the query.
subscribe
Adds a callback that’s invoked on state change.
Parameters
-
listener:
() => void
A callback that’s invoked on state change.
Returns Unsubscribe
: A function to remove the listener.
Attributes
state
The state of the DictionaryFieldContext
controller.
Properties
-
values:
Record<string, string>
An object holding the dictionary field context fields and keys to retrieve values for.
Initialize
buildDictionaryFieldContext
Creates a DictionaryFieldContext
controller instance.
Parameters
-
engine:
CoreEngine
The headless engine.
Returns DictionaryFieldContext
Related Types
Unsubscribe
Call signatures
-
(): void