Adding rules
You can use the widget.items.search.rule object to configure how you want Sitecore Search to treat certain result items. You can blacklist, boost, bury, include, and pin items and categories. Except for the pin rule, you must nest a filter object within the rule object to specify which items the rule applies to.
For the data model of this object, see the Search and Recommendation API reference.
The rules you pass in an API request override the rules configured in Sitecore Search.
Boosting items into slots
To boost an item or category into slots, add a widget.items.search.rule.boost object. You must specify the product or category you want to boost and the slots you want them to appear in.
In this example,
-
You want to boost all items in the
productcategory. -
You want boosted items to appear in slots two and three of the search results.
The following code shows a sample request:
The following is the response to the request:
In the response content object, you can see product items in the second and third results items, that is, slots two and three.
Boosting items without slots
To boost an item or category without specifying a slot, use a widget.items.search.rule.boost object. You'll need to specify the product or category you want to boost and the weight by which you want to boost it.
In this example,
-
The visitor searches for the keyword content.
-
You want to boost all blogs by a weight of 5.
Blacklisting items
To blacklist a list of items or categories, add a search.rule.blacklist object. These items or categories never show up in the search results.
In this example, you want to blacklist all content of type other. The following code shows a sample request:
The following is the response to the request:
In the response content object, you can see that no item has a type of other.
Pinning items
To pin an item to a particular slot in the search results, use the search.rule.pin object and specify the slot you want to use and the ID of the item you want to pin.
In this example, you want to pin a blog about cloud computing to slot number two.
The following code shows a sample request:
The following is the response to the request:
In the response content object, you see the blog you want as the second item in the search results, in slot number two.