Creating a custom query postprocessor

A query postprocessor modifies the physical DataObject, SolrEntityContainerImpl, immediately after the QueryResponse is returned from the Solr server.

Procedure

  1. Create a class that:
    1. Extends from the AbstractSolrSearchQueryPostprocessor class, and
    2. Implements the SearchQueryPostprocessor interface.
  2. Implement the constructor method, which takes a component identifier as a string input parameter. Typically, component-specific logic is initialized here.
  3. Implement the invoke method which takes the SelectionCriteria object and an object array as input parameters. This SelectionCriteria object is a Java representation of the original search expression, where search criteria is stored as a control parameter object.
    The object array contains the native QueryResponse object which is initialized by:
    super.invoke(selectionCriteria, queryResponseObjects);
    
    There are three instance variables that can be used:
    iSelectionCriteria
    Java representation of the original search expression.
    iQueryResponse
    Java representation of native search query response objects.
    Feature Pack 6Feature Pack 5iResponseObject
    Feature Pack 6Feature Pack 5Solr implementation of the physical entity container for the Data Service Layer (DSL).
    Feature Pack 7 or lateriSearchResponseObject
    Feature Pack 7 or laterThe Java representation of the SearchResponse object that is used with the REST services.
  4. 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 query postprocessors, see WebSphere Commerce search configuration file (wc-search.xml) (WC EAR).

Example

Feature Pack 7 or laterThe following download contains a code sample for how a custom postprocessor is configured in the wc-search.xml file, and how it is used to add more data into the final response object.