Creating a custom result filter

A result filter modifies the logical object (noun) before the search result is returned to the storefront. The filter has full access to the CatalogNavigationView noun. Therefore, more data can be inserted, updated, or removed from any parts of the noun and its noun parts, such as CatalogEntryView or CatalogGroupView. Each result filter can be separately registered to any search profile result section so that it can be reused for other search operations.

Note: Result filters must not contain any search engine-specific code.

Procedure

  1. Create a class that:
    1. Extends from the com.ibm.commerce.catalog.facade.server.services.search.metadata.AbstractSearchResultFilterclass, and
    2. Implements the com.ibm.commerce.foundation.server.services.search.metadata.SearchResultFilter interface.
  2. Implement the filter method which takes the SelectionCriteria object and the DataObject as input parameters. The SelectionCriteria object is a Java representation of the original search expression, where each search criteria is stored as a control parameter object. The DataObject is the logical object (noun) that represents the search result and is used by the storefront.
    Note: You must first call the following method to initialize its abstract class:
    super.filter(selectionCriteria, dataObject);
    
    It can be retrieved by typecasting into the CatalogNavigationViewType:
    
    CatalogNavigationViewType catalogNavigationView = (CatalogNavigationViewType) dataObject;
    
  3. Helper methods are available from its abstract class which can be used for retrieving from the control parameters:
    
    String term = getControlParameterValue(SearchServiceConstants.CTRL_PARAM_SEARCH_TERM);
    

    For a list of supported control parameters, see WebSphere Commerce search interface.

    For more information about the default result filters, see WebSphere Commerce search configuration file (wc-search.xml) (WC EAR).

Example

The following download contains a code sample for creating a custom result filter: