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 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="outputStart">
  <ul>
</ dsp:oparam>

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

<dsp:oparam name="outputEnd">
  </ul>
</dsp:oparam>

 <dsp:oparam name="empty">
   <p>No matching products were found.
 </dsp:oparam>
</dsp:droplet>

The following example is longer and includes more of the available options:

<%@ taglib uri="http://www.atg.com/dsp.tld" prefix="dsp" %>
<dsp:page>

<%--
---------------------------------------------------------------
This JSP bean displays the contents of a search
that potentially returns both category and product repository items.
The one paramater, ResultArray, accepts a HashMap that contains
elements with the keys "category" and "product".  The values of these
keys are collections of category or product repository items found in
the search.
--------------------------------------------------------------
--%>

<dsp:importbean bean="/atg/dynamo/droplet/Switch"/>
<dsp:importbean bean="/atg/dynamo/droplet/IsEmpty"/>
<dsp:importbean bean="/atg/dynamo/droplet/ForEach"/>
<dsp:importbean bean="/atg/dynamo/droplet/RQLQueryForEach"/>

<dsp:droplet name="ForEach">
  <dsp:param param="ResultArray" name="array"/>

<%--Each item in this array is a Collection of Categories or
          Products...--%>
  <dsp:param value="ResultCollection" name="elementName"/>

  <dsp:oparam name="output">
    <dsp:droplet name="Switch">

<%--The key tells us if this is a Collection of Products
              or Categories:--%>
      <dsp:param param="key" name="value"/>

<%--For the list of CATEGORIES: --%>
      <dsp:oparam name="category">

        <blockquote>

        <dsp:droplet name="Switch">
          <dsp:param param="ResultCollection" name="value"/>
          <dsp:oparam name="default">
            <p>

<%--For each Category in the Collection: --%>
            <dsp:droplet name="ForEach">
              <dsp:param param="ResultCollection" name="array"/>
              <dsp:param value="+displayName" name="sortProperties"/>
              <dsp:param value="Category" name="elementName"/>
              <dsp:oparam name="outputStart">
                <b>We found these categories matching your search</b>
                <p>
              </dsp:oparam>
              <dsp:oparam name="output">


<%-- Display a link to the Category: --%>
                <dsp:getvalueof id="a78" param="Category.template.url"
                                        idtype="java.lang.String">
<dsp:a href="<%=a78%>">
                  <dsp:param param="Category.repositoryId" name="id"/>
                  <dsp:param value="jump" name="navAction"/>
                  <dsp:param param="Category" name="Item"/>
                  <dsp:valueof param="Category.displayName">No
                       name</dsp:valueof></dsp:a></dsp:getvalueof>
                <br>
              </dsp:oparam>
              <dsp:oparam name="empty">
                <b>There are no categories matching your search</b>
                <p>
              </dsp:oparam>
            </dsp:droplet>
          </dsp:oparam>

<%--If NO Categories returned by the search: --%>
          <dsp:oparam name="unset">
            No category items in the catalog could be found that match your query
          </dsp:oparam>
        </dsp:droplet>
<%--ForEach Category--%>

        </blockquote>
        <P>
      </dsp:oparam>

<%--For the list of PRODUCTS: --%>
      <dsp:oparam name="product">
        <blockquote><p>

        <dsp:droplet name="Switch">
          <dsp:param param="ResultCollection" name="value"/>

          <dsp:oparam name="default">


<%--For each Product in the Collection: --%>
            <dsp:droplet name="ForEach">
              <dsp:param param="ResultCollection" name="array"/>
              <dsp:param value="+displayName" name="sortProperties"/>
              <dsp:param value="Product" name="elementName"/>
              <dsp:oparam name="outputStart">
                <p>
                <b>We found these products matching your search</b>
                <p>
              </dsp:oparam>
              <dsp:oparam name="output">

<%-- Display a link to the Product: --%>
                <dsp:getvalueof id="a173" param="Product.template.url"
                            idtype="java.lang.String">
<dsp:a href="<%=a173%>">
                  <dsp:param param="Product.repositoryId" name="id"/>
                  <dsp:param value="jump" name="navAction"/>
                  <dsp:param param="Product" name="Item"/>
                  <dsp:valueof param="Product.displayName">No name</dsp:valueof>
                   &nbsp;-&nbsp;<dsp:valueof param="Product.description"/>
                </dsp:a></dsp:getvalueof>

                <br>
              </dsp:oparam>
              <dsp:oparam name="empty">
                <b>There are no products matching your search</b>
                <p>
              </dsp:oparam>

            </dsp:droplet>
<%--ForEach Product--%>

          </dsp:oparam>


<%--If NO Products returned by the search:--%>
          <dsp:oparam name="unset">
           No product items in the catalog could be found that match your query<p>
          </dsp:oparam>

        </dsp:droplet>
        </blockquote><P>
      </dsp:oparam>
    </dsp:droplet>

  </dsp:oparam>

</dsp:droplet>
<%--ForEach Item returned by Search --%>

</dsp:droplet>

</dsp:page>

Copyright © 1997, 2014 Oracle and/or its affiliates. All rights reserved. Legal Notices