After executing a query, the SearchFormHandler
makes the search results available in two properties, which organize the same information differently:
searchResults
contains all items returned by the query, undifferentiated by item type.searchResultsByItemType
is a HashMap with one key/value pair for each item type returned by the query. The key is the item type name—the value specified in the form handler’sitemTypes
property—and the value is a collection of items of that type that were returned by the query.
For example, if you search for cuisine and recipe items in the food repository, the searchResults
property contains items of type cuisine
and recipe
. The searchResultsByItem
type property has a cuisine
key whose value is a collection of cuisine items, and a recipe
key called whose value is a collection of recipe items.
Within each collection, the items are in the order of their retrieval from the database. To sort the display order of items, use a servlet bean such as ForEach.
The following example uses ForEach to iterate over the searchResultsByItemType
property, and display only the recipes returned by the search sorted by their display name:
<p>Your search returned the following products:</p> <dsp:droplet name="ForEach"> <dsp:param name="array" bean="CatalogSearch.searchResultsByItemType.recipe"/> <dsp:param name="sortProperties" value="+displayName"/> <dsp:oparam name="output"> <li><dsp:valueof param="element.displayName">Unknown recipe</dsp:valueof> </dsp:oparam> <dsp:oparam name="empty"> <p>No matching recipes were found. </dsp:oparam> </dsp:droplet>