Using Dynamic Refinements
The SearchRefinements resource returns dynamic refinements like Actor, Author, Brand, etc. when a relevant search request is made. For example, a search request for "mystery novels" inside Books
category returns relevant Authors, a search request for "smartphones" inside Electronics
category returns relevant Brands and so on. These dynamic refinements are returned under OtherRefinements container of the SearchRefinements resources. For more information, refer SearchRefinements.
The dynamic refinements returned under SearchRefinements resource can be used to filter search results. Every dynamic refinement maps to a SearchItems request parameter. The Id
attribute of a dynamic refinement represents the mapping SearchItems request parameter. For example, the Id
attribute of the Author refinement is Author
which is a SearchItems request parameter. This tutorial is about how the you can use dynamic refinements to filter search results.
For the tutorial, let's assume we're searching for "java 8" under Books category.
Step 1: Initial Search Request
- Let's start our search for "java 8" under Books SearchIndex using the following payload. Note that we've requested the SearchRefinement resource here.
{
"Keywords": "java 8",
"SearchIndex": "Books",
"Resources": ["SearchRefinements"],
"PartnerTag": "xyz-20",
"PartnerType": "Associates",
"Marketplace": "www.amazon.com",
"Operation": "SearchItems"
}
- The search result returns several "java 8" books. Lookout for the SearchRefinements response in the API output. It contains relevant Authors for the search request under OtherRefinements container which looks like this:
"SearchRefinements": {
"OtherRefinements": [
{
"Id": "Author",
"DisplayName": "Author",
"Bins": [
{
"DisplayName": "Ray Yao",
"Id": "Ray Yao"
},
{
"DisplayName": "Herbert Schildt",
"Id": "Herbert Schildt"
},
{
"DisplayName": "P.J. Deitel",
"Id": "P.J. Deitel"
},
{
"DisplayName": "H.M. Deitel",
"Id": "H.M. Deitel"
},
{
"DisplayName": "Jeanne Boyarsky",
"Id": "Jeanne Boyarsky"
},
{
"DisplayName": "John Lewis",
"Id": "John Lewis"
},
{
"DisplayName": "Nancy Krulik",
"Id": "Nancy Krulik"
}
]
}
]
}
- From the response, we see several relevant Authors for our search request. Let's say we want all java 8 books from "Herbert Schildt". To do that, we need to use the Id attribute of the Bin for Herbert Schildt which is
Herbert Schildt
. Let's use this to fire a subsequent request and filter our search results from this author.
Step 2: Filter Search Results using Author Refinement
- The subsequent search request now filters the search results by the Author "Herbert Schildt":
{
"Keywords": "java 8",
"SearchIndex": "Books",
"Author": "Herbert Schildt",
"Resources": ["SearchRefinements"],
"PartnerTag": "xyz-20",
"PartnerType": "Associates",
"Marketplace": "www.amazon.com",
"Operation": "SearchItems"
}
- We see that the search results now contains java 8 books from the author - Herbert Schildt.
There may be cases when you might get a certain refinement as response but the same doesn't work while firing subsequent request. For instance, you may get Artist
refinement in DigitalMusic
category searches but when Artist
filter is used, you may get NoResults
. In such cases, use the refinement values in Keywords
to get desired results.