Examples
Modify Request
Below are some common uses of modifying the query request. You can find guides for more elaborate customizations within the How-To section of the Template JS documentation.
Please review : The Modify Request Overview for complete details on the syntax used for modifying the outgoing query.
Facet/Filter Options Count
Increase the default maximum number of filter options (10) to "20" for every query.
klevu.modifyRequest("all", function (data, scope) {
klevu.each(data.request.current.recordQueries, function (key, query) {
klevu.setObjectPath(query, "filters.filtersToReturn.options.limit", 20);
})
});API Parameter | Description |
|---|---|
options.limit | Specify the maximum number of options to be included per filter. |
See : Klevu API documentation on Retrieving Filters for more details and options
Run-time Boosting
Influence the relevancy algorithm by assigning weight to different aspects at the time of query.
klevu.modifyRequest("landing","productList.boost.filters", [
{
"key": "brand",
"values": ["ACME"],
"weight": 200
}
]);API Parameter | Description |
|---|---|
boost | Query-level aspects to influence the relevancy rankings |
See : Klevu API Personalisation for more details and more options
Constrain Result Set (Advanced Filtering)
You can add a groupCondition to restrict the result set to specific attributes and values. This constraint is typically applied "behind the scenes" to create specialized result set experiences.
Some examples include:
- Brand specific listings
- Curated landing pages
- Automotive fitment
klevu.modifyRequest("landing","productList.settings.groupCondition", {
"groupOperator": "ALL_OF",
"conditions": [
{
"key": "brand",
"valueOperator": "INCLUDE",
"values": [
"ACME"
]
}
]
});API Parameter | Description |
|---|---|
groupOperator | Defines the condition of filtering (ALL_OF, ANY_OF, NONE_OF) |
conditions | The array of attributes (key) to apply to the condition |
See : Klevu API Advanced Filtering for more details and more options