Creating a custom expression provider

An expression provider implements custom business logic for modifying the main search expression before it is sent to the search engine. Each expression provider can be separately registered to any search profile query section so that it can be reused for other search operations. That is, a search profile defines a list of search providers that are used for assembling the main expression for a search request.


  1. Create a class that:
    1. Extends from the class, and
    2. Implements the 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 as an input parameter. This SelectionCriteria object is a Java representation of the search expression, where each search criteria is stored as a control parameter object.
    Note: You must first call the following method to initialize its abstract class:

    Information that is stored in these objects is processed later by the SolrSearchExpressionProcessor and converted into a native Solr expression for sending to the Solr server.

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

    Helper methods are available to be used for:
    String term = getControlParameterValue(SearchServiceConstants.CTRL_PARAM_SEARCH_TERM);
       SearchServiceConstants.CTRL_PARAM_SEARCH_INTERNAL_OPTIONAL_QUERY, searchExpression);

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


The following download contains a code sample for creating a custom expression provider:

What to do next

During run time, it is possible to capture the expression that is stored in this SelectionCriteria object, and the final Solr expression that is sent to the Solr server.

For instructions on how to enable tracing, see Enabling tracing and logging for WebSphere Commerce search.

Enable tracing, run your scenario, and find Final Solr query in the trace.log file.