Examples
If you haven't gone through the prerequisites and the v2 structure, please have a look at Overview
In addition to Products, Categories and CMS Pages, Klevu APIv2 allows you to search for custom entities.
For example, if you want to display results for recipes, articles or physical stores within your search you can do so by utilising the typeOfRecords parameter.
Klevu APIv2 allows you to request multiple Product, Category, CMS Pages and Custom Entity queries all at the same time. All of these queries are usually fired simultaneously, meaning the total time taken is the duration of the slowest query, rather than the total of all queries.
In the example to the right, a single HTTP request is returning:
- 3x search suggestions
- 3x categories
- 5x products with filters
- 3x different products without filters
- 5x cms pages or recipes (a custom entity)
- 1x store (a custom entity)
Furthermore, all of the configuration and preferences found within this documentation can be applied to each and evey query separately, making an extremely powerful and fast way to display search results.
Sometimes customers will search for something which yields few or no results.
In this scenario, you can either present your customer with a 'no results found' message, or you can use the result of another query to show some records which they may be interested in.
We call this a fallback query.
Any query flagged as isFallbackQuery: true will not execute unless certain criteria are met. With this approach you can present customers with alternative results, without needing to make any additional HTTP requests, and also without the jeopardising performance of the initial query.
Sometimes merchants want to take control over which records are included or excluded, or whether certain records should always take precedence over others.
This can be done via query-time manual merchandising.
DEPRECATED: The use of customANDQuery is being deprecated. For better control over custom queries please review and use Advance Filtering
You can even write your own custom queries with Klevu search, to take more control over your results. The example to the right shows how you can build a query to filter results by Small or Medium records which are NOT brand "KKE."
If your store has multiple currencies and you would like to show different values based on the currency your customer is currently viewing, this can be achieved using the priceFieldSuffix parameter.
When specifying a value for priceFieldSuffix, the following fields in your response data will be replaced with the value indexed with Klevu for the corresponding currency:
- price
- salePrice
- currency
A common B2B requirement is different product visibility and prices based on a customer group. With Klevu APIv2 you can specify parameters to filter out products which a particular customer should not see, and also show them specific prices if they differ from the base price.
When specifying a value for priceFieldSuffix, the following fields in your response data will be replaced with the value indexed with Klevu for the corresponding currency and group:
- price
- salePrice
- currency
When specifying a value for visibilityGroupID, any records that do not belong to that group will be excluded from the results.
In the example to the right, the same product is indexed with data for currencies 'GBP' and 'USD'. It's visibility is set to groups 'my_group_1' and 'my_group_3', but not 'my_group_2'.