Filter by category

Now that you have implemented search, we will learn how to constrain the search to certain categories alone. There are 2 kinds of categories in Amazon: SearchIdex and BrowseNode. We will how to use both of them as constraint for search.

Search within a SearchIndex

SearchIndex is the root category in an Amazon site. Here is list of SearchIndices in In this example, we will restrict search results of "headphones" to "Electronics" SearchIndex alone.

CommerceDNA.itemSearch({keywords:'headphones', categories:'Electronics'})

Once the user enters a text in the search box, you can use that value to do the search:

Fork this code »

You should be able to see the results under "Electronics" SearchIndex.

Search within a BrowseNode

Now, if you want to constrain further by "Headphones" BrowseNode under Electronics, you can find its id (493964 in this case) and refine the category list:

CommerceDNA.itemSearch({keywords:'headphones', categories:'Electronics,493964'})

You can add as many number of categories to constrain and get the appropriate results.

Deploying it in production »