Because facet selections are cumulative, it is necessary to keep track of each facet selection a customer has made so far. This is done through a facet trail, which is stored as an object of class atg.repository.search.refinement.FacetTrail.

A facet trail is similar to a navigational breadcrumb trail, where each entry consists of a facet and a selection value or range for that facet. For example, a facet trail might be rendered on the page like this:

The first time the page is displayed, you can set the facet trail explicitly, or leave it empty. When the user makes a facet selection, you append entries to or delete entries from the facet trail, and include the updated facet trail in the new search query.

You can update the facet trail using the CommerceFacetTrailDroplet. This servlet bean takes as input a String representation of the current FacetTrail object plus instructions for modifying the facet trail based on selections chosen by the customer. (Typically these inputs are passed through HTTP request query parameters.) From these inputs, the CommerceFacetTrailDroplet constructs a new FacetTrail object.

For example, suppose a site visitor navigates by first selecting the Televisions category, and then selecting the LCD Televisions subcategory. (This assumes that a property whose values are categories is defined as a facet; see the Oracle ATG Web Commerce Merchandising documentation.) Next, she chooses the $1000 to $2000 selection range for the price facet, and then chooses Acme as the selection value for the manufacturer facet. The facet trail String would now look something like this:

1:cat444323:1:cat333222:2:1000-2000:32:Acme

In this example, cat444323 is the repository ID of the Televisions category, and cat333222 is the repository ID of the LCD Televisions category. The example also assumes the following facets have been defined in Oracle ATG Web Commerce Merchandising:

1 = category
2 = price
32 = manufacturer

The number identifying the facet is the repository ID of the corresponding refinementElement in the refinement repository, which is also used as the ID of the refinementElement XML attribute in the refinement configuration.

Your pages should display the current facets and selections, along with links for removing the selections. (Typically a link for removing a facet is an image of an X, or the word “remove.”) Suppose the site visitor now clicks the link to remove the Televisions facet. When a category selection value is removed from the facet trail, all of that category’s subcategories are also removed, so in this case the LCD Televisions category is removed as well. (In addition, any category-specific facets and selection values that no longer apply are also removed. For example, if the Televisions category has a Screen Size facet associated with it, removing the Televisions facet from the trail also removes the Screen Size facet and selections.)

The new facet trail String is therefore:

2:1000-2000:32:Acme

The displayed search results now consist of all products priced between $1000 and $2000 whose manufacturer is Acme. So if Acme also manufactures stereo systems, the ones in this price range will now be displayed.

Last Range Indicator

The constraint generated for a facet’s last selection range is slightly different from the constraints for the other ranges. For example, suppose you have a price facet with three selection ranges: $1000 to $2000, $2000 to $3000, and $3000 to $4000. The first range includes items whose price is great than or equal to $1000 and less than $2000. The second range includes items whose price is great than or equal to $2000 and less than $3000. But the last range includes items whose price is great than or equal to $3000 and less than or equal to $4000.

If a site visitor chooses the last selection range for a facet, the facet trail must indicate this, so that the correct constraint can be constructed. The last range is indicated by appending |LAST to the entry for the range in the trail. In this example, if the site visitor selects the $3000 to $4000 range, the facet trail String would look something like this:

1:cat444323:2:3000-4000

Note that although |LAST is included in the facet trail String (and therefore may appear in URLs), it is not part of the label for the selection range, and therefore does not appear on the page itself. Also, you do not need to code your JSPs in any special way to deal with this selection range.

For more information about the CommerceFacetTrailDroplet, see Appendix A, Commerce Search Servlet Beans.