Creating a custom expression provider
Procedure
-
Create a class that:
- Extends from the com.ibm.commerce.foundation.server.services.search.expression.solr.AbstractSolrSearchExpressionProvider class, and
- Implements the com.ibm.commerce.foundation.server.services.search.expression.SearchExpressionProvider interface.
- Implement the constructor method, which takes a component identifier as a string input parameter. Typically, component-specific logic is initialized here.
-
Implement the
invoke
method which takes theSelectionCriteria
object as an input parameter. ThisSelectionCriteria
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:super.invoke(selectionCriteria);
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:- Retrieving
String term = getControlParameterValue(SearchServiceConstants.CTRL_PARAM_SEARCH_TERM);
- Storing
addControlParameterValue( 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).
Example
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.