In addition to the keyword and text search of the simple search functionality, the advanced search functionality allows the customer to search for products using by part number, manufacturer, and weight range, which are defined as product properties.
AdvProductSearch.properties Nucleus Configuration File
The advanced search functionality uses the SearchFormHandler
but requires a slightly more complex properties file than the simple search Nucleus component. Advanced searches return only products because the additional search criteria are based on products only.
The following example shows the properties of the AdvProductSearch
component:
$class=atg.commerce.catalog.SearchFormHandler $scope=session doKeywordSearch=true keywordsPropertyNames=keywords doTextSearch=true textSearchPropertyNames=description,displayName doAdvancedSearch=true advancedSearchPropertyNames=weightRange,manufacturer,childSKUs minScore=1 catalogTools=CatalogTools itemTypes^=CatalogTools.productItemTypes
As with the simple search, the SearchFormHandler
is session scoped. Keyword and text searching are configured identically for both simple and advanced searches and they both use the same catalog. For the enumerated types used in the search (manufacturer
and weightRange
), the possible values are inserted into <dsp:select>
input tags on the form. These values are not coded into the form, but instead are retrieved from the catalog via the propertyValuesByType
property of the SearchFormHandler
.
The propertyValuesByType
property is a Map with property names for keys and arrays of all possible values for the given property. By default, no enumerated property information is available from the propertyValuesByType
property of the SearchFormHandler
. Instead, you must explicitly set the names of required enumerated properties in the search component’s advancedSearchPropertyNames
property. In this case, the values are weightRange
, manufacturer
, and childSKUs
.
The search form’s categories in the advanced search, manufacturer
and weightRange
, are populated with valid choices for each item. These choices (<select> components
) are loaded from the repository rather than coded into the page so that the page need not be changed when changes are made to the repository.
To display the list of all repository items of type category
we used the RepositoryValues
servlet bean. It takes an input parameter itemDescriptorName
that in this case is set to category
because that is the type of repository item that we want to list. The servlet bean outputs an array of repository items that can be rendered using the ForEach
component.
For the manufacturer
and weightRange
query values, the product item descriptor is specified and product’s manufacturer
and weightRange
properties are passed via the propertyName
parameter. The definitions of these two properties in the productCatalog.xml
file differ. The manufacturer property is an item-type
property, a link to another item-descriptor, while the weightRange
property is an enumerated data-type
. The RepositoryValues
servlet bean is able to provide appropriate values for either type of property.
Note: The “. . .” marker in the following code sample indicate a place where code has been removed to clarify the sample.
<item-descriptor name="product"> <table name="b2c_product" type="auxiliary" id-column-name="product_id"> <property name="manufacturer" item-type="manufacturer" column-name="manufacturer"/> </item-descriptor> <item-descriptor name="manufacturer"> . . . </item-descriptor>
AdvancedSearch.jsp
:
<dsp:setvalue bean="/atg/userprofiling/Profile.currentLocation" value="catalog_search"/> <dsp:importbean bean="/atg/userprofiling/Profile"/> <dsp:importbean bean="/atg/dynamo/droplet/ForEach"/> <dsp:importbean bean="/atg/dynamo/droplet/For"/> <dsp:importbean bean="/atg/dynamo/droplet/Switch"/> <dsp:importbean bean="/atg/dynamo/droplet/Compare"/> <dsp:importbean bean="/atg/commerce/catalog/AdvProductSearch"/> <dsp:importbean bean="/atg/commerce/catalog/RepositoryValues"/> <HTML> <HEAD> <TITLE>Pioneer Cycling Store</TITLE> <dsp:link rel="STYLESHEET" href="../common/Style.css" type="text/css" title="Prototype Stylesheet"/> </HEAD> <BODY> <dsp:include page="../common/StoreBrand.jsp" flush="true"></dsp:include> <span class=storelittle> <!-- Display Navigation information (list of all parent --> <!-- categories as links users can jump to) --> <dsp:include page="../catalog/common/breadcrumbs.jsp" flush="true"> <dsp:param name="displaybreadcrumbs" value="true"/> <dsp:param name="no_new_crumb" value="true"/></dsp:include> </span> <p> <span class=storebig>Shop by Searching</span><br> <p> <dsp:form action="AdvancedSearch.jsp" method="POST"> <table cellpadding=0 cellspacing=0 border=0> <tr><td colspan=3 class=box-top-store>Advanced Search</td></tr> <tr valign=top><td class=box> <!-- For each property specified in AdvProductSearch.advancedSearchPropertyNames, retrieve all possible property values. This allows the customer to pick one to search on for advanced searching. --> <!-- Category --> Search in <dsp:select bean="AdvProductSearch.hierarchicalCategoryId"> <dsp:option value=""/>-- Entire Store -- <dsp:droplet name="RepositoryValues"> <dsp:param name="itemDescriptorName" value="category"/> <dsp:oparam name="output"> <dsp:droplet name="ForEach"> <dsp:param name="array" param="values"/> <dsp:param name="sortProperties" value="+displayName"/> <dsp:oparam name="output"> <dsp:getvalueof id="option85" param="element.repositoryId" idtype="java.lang.String"> <dsp:option value="<%=option85%>"/> </dsp:getvalueof> <dsp:valueof param="element.displayName"/> </dsp:oparam> </dsp:droplet> </dsp:oparam> </dsp:droplet> </dsp:select> <p> <!-- Text Search --> Text Search for <dsp:input bean="AdvProductSearch.searchInput" size="30" type="text"/> <BR><br> <!-- Part Number --> Search for Part Number (sku id)<br> <dsp:input bean="AdvProductSearch.propertyValues.childSKUs" size="15" type="text"/> </br> <td class=box> </td> <td class=box> Match these attributes <p> <!-- Manufacturer --> Manufacturer <dsp:select bean="AdvProductSearch.propertyValues.manufacturer"> <dsp:option value=""/>-- Any -- <dsp:droplet name="RepositoryValues"> <dsp:param name="itemDescriptorName" value="product"/> <dsp:param name="propertyName" value="manufacturer"/> <dsp:oparam name="output"> <dsp:droplet name="ForEach"> <dsp:param name="array" param="values"/> <dsp:param name="sortProperties" value="+id"/> <dsp:oparam name="output"> <dsp:getvalueof id="option140" param="element.id" idtype="java.lang.String"> <dsp:option value="<%=option140%>"/> </dsp:getvalueof><dsp:valueof param="element.id"/> </dsp:oparam> </dsp:droplet> </dsp:oparam> </dsp:droplet> </dsp:select> <p> Weight Range <dsp:select bean="AdvProductSearch.propertyValues.weightRange"> <dsp:option value=""/>-- Any -- <dsp:droplet name="RepositoryValues"> <dsp:param name="itemDescriptorName" value="product"/> <dsp:param name="propertyName" value="weightRange"/> <dsp:oparam name="output"> <dsp:droplet name="ForEach"> <dsp:param name="array" param="values"/> <dsp:oparam name="output"> <dsp:getvalueof id="option174" param="element" idtype="java.lang.String"> <dsp:option value="<%=option174%>"/> </dsp:getvalueof><dsp:valueof param="element"/> </dsp:oparam> </dsp:droplet> </dsp:oparam> </dsp:droplet> </dsp:select> <p> <nobr> <dsp:input bean="AdvProductSearch.currentResultPageNum" type="hidden" value="1"/> <input name="repositoryKey" type="hidden" value='<dsp:valueof bean="/OriginatingRequest.requestLocale.locale"/>'> <dsp:input bean="AdvProductSearch.search" type="hidden" value="Search"/> <dsp:input bean="AdvProductSearch.search" type="submit" value=" Search "/> <p> <dsp:a href="SimpleSearch.jsp">Search with the simple form instead</dsp:a></b> </td></tr> </table> </dsp:form> <p> <dsp:droplet name="Compare"> <dsp:param bean="AdvProductSearch.resultSetSize" name="obj1"/> <dsp:param bean="AdvProductSearch.maxResultsPerPage" name="obj2"/> <dsp:oparam name="greaterthan"> Now viewing results <dsp:valueof bean="AdvProductSearch.startIndex"/> to <dsp:valueof bean="AdvProductSearch.endIndex"/> out of <dsp:valueof bean="AdvProductSearch.resultSetSize"/> </dsp:oparam> </dsp:droplet> <!-- Display Results --> <dsp:getvalueof id="pval0" bean="AdvProductSearch.searchResultsByItemType" idtype="java.util.Map"> <dsp:include page="SearchResultsFragment.jsp" flush="true"> <dsp:param name="ResultArray" value="<%=pval0%>"/></dsp:include></dsp:getvalueof> <dsp:droplet name="Switch"> <dsp:param bean="AdvProductSearch.resultSetSize" name="value"/> <dsp:oparam name="0"> </dsp:oparam> <dsp:oparam name="default"> <dsp:droplet name="For"> <dsp:param bean="AdvProductSearch.resultPageCount" name="howMany"/> <dsp:oparam name="output"> <dsp:droplet name="Switch"> <dsp:param bean="AdvProductSearch.currentResultPageNum" name="value"/> <dsp:getvalueof id="nameval2" param="count" idtype="java.lang.Integer"> <dsp:oparam name="<%=nameval2.toString()%>"> <dsp:valueof param="count"/> </dsp:oparam> </dsp:getvalueof> <dsp:oparam name="default"> <dsp:a href="AdvancedSearch.jsp" bean="AdvProductSearch.currentResultPageNum" paramvalue="count"> <dsp:valueof param="count"/> </dsp:a> </dsp:oparam> </dsp:droplet> </dsp:oparam> </dsp:droplet> </dsp:oparam> </dsp:droplet> <p> <dsp:include page="../common/StoreFooter.jsp" flush="true"></dsp:include> </BODY> </HTML>