When a faceted search query is issued, Oracle ATG Web Commerce Search returns the facets as part of the QueryRequest.Response object. The FacetSearchTools component converts the raw facet data and stores the converted data in the FacetSearchTools.facets property as an array of objects of class atg.repository.search.refinement.FacetHolder. Each FacetHolder object represents a single facet and its values.

The facet is stored in the FacetHolder.facet property as an object of class atg.repository.search.refinement.Facet. (See Working with the FacetTrail Object.) The facet values are stored in the FacetHolder.facetValueNodes property as an array of atg.repository.search.refinement.FacetValueNode objects.

The following example illustrates rendering the facets and facet values. It accesses the FacetSearchTools object and iterates through the facets in its facets property. For each facet, it displays the available selections and indicates the number of results for each selection value or range.

Each value or range is rendered as a hyperlink. When a user clicks one of these links, the JSP:

  • Adds the facet and selection value to the facet trail.

  • Retrieves the current search request object (which has been saved in the SearchSession object), updates it, and resubmits the request. (See Modifying and Resubmitting the Request for more information.)

  • Re-renders the page with the facets and selections returned in the new search response. (This fragment does not include the code for rendering the search results themselves.)

<dsp:getvalueof bean="QueryFormHandler.searchResponse" var="queryResponse"
   scope="request"/>
<dsp:getvalueof bean="FacetSearchTools.facets" var="facetHolders"
   scope="request"/>
<dsp:getvalueof param="trail" var="trailString"/>

<!-- iterate through the returned facets -->
<c:forEach items="${facetHolders}" var="facetHolder">
  <tr>
    <!-- display the name of the facet -->
    <td><c:out value="${facetHolder.facet.label}"/></td>

    <!-- iterate through the values of the current facet -->
    <td><c:forEach items="${facetHolder.facetValueNodes}" var="facetValueNode">

      <!-- use the CommerceFacetTrailDroplet to construct the facet trail   -->
      <dsp:droplet name="CommerceFacetTrailDroplet">

      <!-- pass in facet trail from previous request -->
      <dsp:setvalue param="trail" value="${trailString}"/>

      <!-- add the facet selection to the trail; also include the SRCH facet -->
      <!-- if there is search text and the SRCH facet hasn't been added yet  -->
      <c:if test="${ empty trailString and ! empty queryResponse.question }">
        <dsp:setvalue param="addFacet"
          value="SRCH:${queryResponse.question}:${facetValueNode.facetValue}"/>
      </c:if>
      <c:if test="${ ! empty trailString or empty queryResponse.question }">
        <dsp:setvalue param="addFacet" value="${facetValueNode.facetValue}"/>
      </c:if>

        <dsp:oparam name="output">

        <!-- expose the facetTrail string as a jstl variable -->
        <dsp:getvalueof param="facetTrail" var="facetTrail"/>

        <!-- display facet value as link that issues a new search when -->
        <!-- clicked and re-renders this page                          -->
        <dsp:a href="simpleFacet.jsp">

          <!-- re-use the previously saved search request     -->
          <dsp:property bean="QueryFormHandler.searchRequest.requestChainToken
              value="${queryResponse.requestChainToken}"
              name="qfh_rct" priority="30"/>

          <!—- save this request so it can be re-used       -->
          <dsp:property bean="QueryFormHandler.searchRequest.saveRequest"
              value="true" name="fh_sr" priority="30"/>

          <!—- specify that this is a faceted search request    -->
          <dsp:property bean="QueryFormHandler.searchRequest.facetSearchRequest"
              value="true" name="qfh_fsr" priority="31"/>

          <!-- set the facetTrail property on the FacetSearchTools component -->
          <dsp:property bean="FacetSearchTools.facetTrail"
              value="${facetTrail.trailString}" name="qfh_ft" priority="27"/>

          <!-- set the facet trail as a query parameter -->
          <dsp:param name="trail" param="facetTrail.trailString"/>

          <!-— submit the request by invoking the handleSearch method -->
          <!—- on the QueryFormHandler when the link is clicked       -->
          <dsp:property bean="QueryFormHandler.search" value="submit"
              name="qfh_s_s"/>

          <!-- display each facet value and the number of results -->
          <c:out value="${facetValueNode.facetValue.value}"/>
            ( <c:out value="${facetValueNode.facetValue.matchingDocsCount}"/> )
          <br>
        </dsp:a>

. . .