If your site includes a search form created with the atg.search.query.formhandlers.QueryFormHandler
class, you can constrain the set of items accessed through facet selections to ones that also satisfy the search query. For example, suppose a site visitor at a clothing store begins by searching for “belt,” and then chooses the “brown” selection value for the color facet. The site would now display only brown belts, not all brown items in the store.
To enable this behavior in your pages, dynamic navigation allows you to use a special SRCH
facet whose selection value is the search term entered by the site visitor. In this example, the facet trail String would look something like this:
SRCH:belt:12:cat356782
Constructing the Facet Trail String
When a site visitor submits a query through the QueryFormHandler
, the search text is stored in the question
property of the form handler. Typically you will want to clear any existing facet trail (so the search is not constrained by current facet selections), and then create a new facet trail that starts with the SRCH
facet (so that subsequent facet selections are constrained by the search results).
The following example illustrates this approach. When the visitor submits a query, the removeAllFacets
query parameter is set to true
, and the addFacet
query parameter is set to SRCH:
plus the search text (e.g., SRCH:belt
). These query parameters can then be used as inputs to the CommerceFacetTrailDroplet
servlet bean, to clear the facet trail and create a new facet trail that starts with the SRCH
facet. For example:
<dsp:getvalueof var="searchTerm"
bean="/atg/commerce/search/ProductCatalogQueryFormHandler.question"/>
<dsp:droplet name="/atg/dynamo/droplet/Redirect">
<dsp:param name="url" value=
"../facetPage.jsp?removeAllFacets=true&addFacet=SRCH:${searchTerm}"/>
</dsp:droplet>
Specifying the Refinement Configuration
When a search query is issued through the CommerceFacetSearchDroplet
servlet bean, it invokes the CommerceFacetSearchService
, which determines the refinement configuration to use and specifies it in the query. The QueryFormHandler
, however, does not invoke the CommerceFacetSearchService
, so another mechanism for determining the search configuration is needed for queries issued through the form handler.
One approach involves having ATG Search determine the refinement configuration to use based on the items that are returned. You can do this by adding the following settings to the requestAttributes
Map:
requestAttributes+=\
refineConfig=$map,\
refineConfigMapProp=ancestorCategories.$repositoryId
Setting the refineConfig
attribute to $map
instructs ATG Search to determine the refinement configuration to use by finding a metadata property value common to all of results; the refineConfigMapProp
attribute specifies which metadata property to use. So these settings specify that ATG Search should use the refinement configuration for the lowest-level ancestor category that is common to all of the returned items.
The main drawback to this approach is that if there is no ancestor category common to all of the results, the refinement configuration cannot be determined. In this case, ATG Search does not return any facets.
Rendering the Facets
When a search query is issued through the CommerceFacetSearchDroplet
servlet bean, the CommerceFacetSearchService
receives back a Search Results
object. It converts this Results
object to a FacetSearchResponse
object, which the CommerceFacetSearchDroplet
outputs.
When the QueryFormHandler
issues a query, however, it does not invoke the CommerceFacetSearchService
, so the form handler handles this conversion itself, and stores the FacetSearchResponse
object in its facetSearchResponse
property. The page developer can use servlet beans such as ForEach
to iterate through this object and display the resulting facets and selections, just as when the object is returned by CommerceFacetSearchDroplet
. For example:
<c:set var="formHandlerPath" value="/atg/commerce/search/ProductCatalogQueryFormHandler"/> <dsp:droplet name="ForEach"> <dsp:param name="array" param="${formHandlerPath}.facetSearchResponse.availableFacets"/> <dsp:oparam name="output"> . . .
For a more complete example of rendering facets, see FacetSearchDroplet.