Technote

(troubleshooting)
Advanced Catalog Search Customization
Problem(Abstract)
The advanced version of the catalog search feature provides a more comprehensive search facility that limits the search results to a specific set of criteria defined by the customer.

However, searching for product 'PROD123' in the catentry name, short description, partnumber, and manufacturer partnumber may not return the expected results.
Cause The current logic for the advanced search uses an implicit AND operator between each of the search parameters:catentry name, short description, part number, and manufacturer partnumber. This will only return results if the search term is found in all of the above parameters. Resolving the problem APAR JR25583 provides the sample code for extending CatEntrySearchListDataBean. The APAR is included in Fix Pack 6.0.0.3 or newer fix pack which can be obtained from the Fixes by version page. The sample code shows a simple example of how to customize the advanced catalog search and is provided as is for reference in customization.

The following steps, along with the sample code, demonstrates how to customize the advanced catalog search to look for the search term in the product name, short description, keyword, part number, and manufacturer partnumber.

1. Create a New Package
Create a new package called com.ibm.commerce.search.beans.samples in the WebSphereCommerceExtensionsLogic folder for the NewCatEntrySearchListDataBean class.

Add the sample code to this package.

2. Define the Search Term Scope
The sample code begins by defining a constant for the new search term scope:

private static final Integer SEARCH_IN_PRODUCTNAME_AND_SHORT_DESCRIPTION_AND_KEYWORD_AND_PARTNUMBER = new Integer(5);

constants 1 - 4 have already been reserved for the following:

1 - SEARCH_IN_PRODUCTNAME_AND_SHORT_DESCRIPTION
2 - SEARCH_IN_PRODUCTNAME
3 - SEARCH_IN_PRODUCTNAME_AND_DESCRIPTIONS
4 - SEARCH_IN_KEYWORD

3. Customize to Meet Business Requirements
The sample class implements two methods: populate() and setPredefinedAttributes()

The populate method initializes and populates information required by the search bean. This method is not usually customized.

The setPredefinedAttributes method is used for defining the paramerters and search criterias for the searchTerm. This method contains the core of the customization.

The method begins by first doing a check to see that there is a search term:

if(isEmpty(searchTerm))

isEmpty method returns TRUE if there IS a search term.

Search parameters and criterias are then added:

q.addSelectOperand(buildBooleanPredicate(searchTerm, searchTermOperator, searchType, searchTermCaseSensitive, q.CATENTDESC_NAME_Attr));
The parameters searchTerm, searchTermOperator, searchType, searchTermCaseSensitive are found and passed in from the AdvancedSearchView jsp.

searchTerm is an input variable that refers to the "Search For" text field in the jsp. The value of this variable is used as the search term for the search.

searchTermOperator is a hidden variable. The value of this variable determines the search operator 'LIKE' or 'EQUAL' for a search on the search term value. The default setting for this is 'LIKE'.

searchType is an input variable that refers to the "Search For" drop down list. The value of this variable determines the search criteria type of 'ALL', 'ANY' or 'EXACT' phrase.

searchTermCaseSensitive is a hidden variable. The value of this variable determines if a search for the search term is case sensitive or not. The default setting for this is 'no'.

CATENTDESC_NAME_Attr indicates that search will be made on the NAME column of the CATENTDESC database table.

A search on other columns and tables in the database can be added by inserting the above snippet and modifying the last parameter. So other examples are:

CATENTDESC_SHORTDESCRIPTION_Attr

- References the value used for the SHORTDESCRIPTION column of the CATENTDESC database table. CATENTDESC_KEYWORD_Attr

- References the value used for the KEYWORD column of the CATENTDESC database table. CATENTRY_PARTNUMBER_Attr

- References the value used for the PARTNUMBER column of the CATENTRY database table. CATENTRY_MFPARTNUMBER_Attr

- References the value used for the MFPARTNUMBER column of the CATENTRY database table.
Refer to the RuleQuery API in InfoCenter for more listings of available tables and columns.

To customize the search query, use the following operators after two or more search predicates have been added:

q.addSelectOperator(q.OR_Operator);
q.addSelectOperator(q.AND_Operator);
3a. Examples of Creating Search Queries:
To search for the term 'LAMP' where the term can be in the product name or short description:

q.addSelectOperand(buildBooleanPredicate(searchTerm, searchTermOperator, searchType, searchTermCaseSensitive, q.CATENTDESC_NAME_Attr));
q.addSelectOperand(buildBooleanPredicate(searchTerm, searchTermOperator, searchType, searchTermCaseSensitive, q.CATENTDESC_SHORTDESCRIPTION_Attr));
q.addSelectOperator(q.AND_Operator);
To search for the term 'LAMP' where the term must be in the ((product name AND short description) OR keyword) AND (partnumber OR manufacturer partnumber)):

q.addSelectOperand(buildBooleanPredicate(searchTerm, searchTermOperator, searchType, searchTermCaseSensitive, q.CATENTDESC_NAME_Attr));
q.addSelectOperand(buildBooleanPredicate(searchTerm, searchTermOperator, searchType, searchTermCaseSensitive, q.CATENTDESC_SHORTDESCRIPTION_Attr));
q.addSelectOperator(q.AND_Operator);
q.addSelectOperand(buildBooleanPredicate(searchTerm, searchTermOperator, searchType, searchTermCaseSensitive, q.CATENTDESC_KEYWORD_Attr));
q.addSelectOperator(q.OR_Operator);
q.addSelectOperand(buildBooleanPredicate(searchTerm, searchTermOperator, searchType, searchTermCaseSensitive, q.CATENTRY_PARTNUMBER_Attr));
q.addSelectOperand(buildBooleanPredicate(searchTerm, searchTermOperator, searchType, searchTermCaseSensitive, q.CATENTRY_MFPARTNUMBER_Attr));
q.addSelectOperator(q.OR_Operator);
q.addSelectOperator(q.AND_Operator);

To aid in testing out other combinations, enable the WC_SEARCH component and search for 'Query =' in the trace log after a search has been submitted. Complete the remainder of the steps before trying this.

Once customization has been completed, set the isAllNull flag to indicate that search parameters have been modified:

isAllNull = false;
3b. Customizing the Filter Term
Customization of the filter term works in a similar manner to the search term.

Check to see that there is a search term:

if(isEmpty(filterTerm))
Filter parameters and criterias are added:

q.addFilterOperand(buildFilterTermBooleanPredicate(filterTerm, filterTermOperator, filterType, filterTermCaseSensitive, q.CATENTDESC_NAME_Attr));
The parameters filterTerm, filterTermOperator, filterType, filterTermCaseSensitive are found and passed in from the AdvancedSearchView jsp.

The filter query is created by combining filter predicates with filter operators. The following example will filter out search results where the filter term is found in the product name and short description and partnumber:

q.addFilterOperand(buildFilterTermBooleanPredicate(filterTerm, filterTermOperator, filterType, filterTermCaseSensitive, q.CATENTDESC_NAME_Attr));
q.addFilterOperand(buildFilterTermBooleanPredicate(filterTerm, filterTermOperator, filterType, filterTermCaseSensitive, q.CATENTDESC_SHORTDESCRIPTION_Attr));
q.addFilterOperand(buildFilterTermBooleanPredicate(filterTerm, filterTermOperator, filterType, filterTermCaseSensitive, q.CATENTRY_PARTNUMBER_Attr));
q.addFilterOperator(q.AND_Operator);
4. Reference New Bean in JSP
Modified the CatalogSearchResultDisplay.jsp to reference the new bean NewCatEntrySearchListDataBean for all occurances of the old bean CatEntrySearchListDataBean. The should be two references to the old bean in the out of the box jsp. The update should look similar to the following:

<wcbase:useBean id="catEntSearchListBean1"
classname="com.ibm.commerce.search.beans.samples.NewCatEntrySearchListDa
taBean"/>
Modify the CachedHeaderDisplay.jsp to include the search term scope parameter so that the basic search executed from the header bar defaults to a search term scope of interest. This is also required if the new search bean does not have code to handle null values for searchTermScope, as in the sample code provided. The update should look similar to the following:

<form name="CatalogSearchForm"
action="CatalogSearchResultView" method="post" id="CatalogSearchForm">
<input type="hidden" name="searchTermScope" value="5"
id="WC_CachedHeaderDisplay_FormInput_searchTermScope_In_CatalogSearchForm
_1"/>
5. Add New Search Term Scope to JSP
Modified the AdvancedCatalogSearchForm.jsp to add the new search term scope.
The search term scope should match the constant value specified in the custom code.
In the example below, the search term scope text is referenced from the properties file.

<select
id="WC_AdvancedCatalogSearchForm_FormInput_searchTermScope_In_AdvancedSe
archForm_1" class="select" name="searchTermScope">
<c:choose>
<c:when test="${!empty
WCParam.searchTermScope && WCParam.searchTermScope=='5'}">
<option value="5" selected>
</c:when>
<c:otherwise>
<option value="5">
</c:otherwise>
</c:choose>
<fmt:message key="PRODUCT_NAME_DESC_SKU"
bundle="${storeText}"/>
</option>
<c:choose>
<c:when test="${!empty
WCParam.searchTermScope && WCParam.searchTermScope=='1'}">
<option value="1" selected>
</c:when>
<c:otherwise>
<option value="1">
</c:otherwise>
</c:choose>
<fmt:message key="PRODUCT_NAME_DESC"
bundle="${storeText}"/>
</option>
<c:choose>
<c:when test="${!empty
WCParam.searchTermScope && WCParam.searchTermScope=='2'}">
<option value="2" selected>
</c:when>
<c:otherwise>
<option value="2">
</c:otherwise>
</c:choose>
<fmt:message key="PRODUCT_NAME_ONLY"
bundle="${storeText}"/>
</option>
</select>
6. Update Resource Bundle for Search Term Scope Name
Add the constant PRODUCT_NAME_DESC_SKU that was used in the AdvancedCatalogSearchForm.jsp to the storetext_en_US.properties file:

PRODUCT_NAME_DESC_SKU = product name and description and sku
 

Document Information

Current web document: http://www.ibm.com/support/docview.wss?uid=swg21268194