SearchFormHandler executes its search query when the handleSearch method is called. Typically, you associate the form handler’s search property with a submit button, as in this example:

<dsp:input bean="/myCatalog/" value="Go" type="submit"/>

After executing the query, SearchFormHandler makes the search results available in two different properties, which contain the same information but organize it differently:

For example, if you search for categories and products in the standard catalog schema, the searchResultsByItemType property will have a key called category whose value is a Collection of matching categories, and another key called product whose value is a Collection of matching products. The searchResults property will have a Collection in which some of the items are categories and some of the items are products.

Within each Collection, the items are not sorted, but reflect the order they were retrieved from the database. You can use the sorting capabilities of a servlet bean (such as ForEach) to control the order in which the items are displayed.

The following example uses ForEach with searchResultsByItemType to display only the products returned by the search, sorted by display name:

Your search returned the following products:

<dsp:droplet name="ForEach">
 <dsp:param value="CatalogSearch.searchResultsByItemType.product" name="array"/>
 <dsp:param value="+displayName" name="sortProperties"/>

 <dsp:oparam name="output">
   <li><dsp:valueof param="element.displayName">Unknown product</dsp:valueof>

 <dsp:oparam name="empty">
   <p>No matching products were found.
loading table of contents...