Creating a custom query postprocessor
A query postprocessor creates and modifies a
search response immediately after the
QueryResponse
is returned from the Solr
server. Procedure
-
Create a class that does the following actions:
- Extends from the AbstractSearchQueryPostprocessor class, and
- Implements the SearchQueryPostprocessor interface.
-
Implement the
invoke
method, which takes theSearchCriteria
object and an object array as input parameters. ThisSearchCriteria
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 nativeQueryResponse
object, which is initialized by:super.invoke(SearchCriteria, queryResponseObjects);
Three instance variables can be used:- iSearchCriteria
- Java representation of the original search expression.
- iQueryResponse
- Java representation of native search query response objects.
- iSearchResponseObject
- The Java representation of the SearchResponse object that is used with the REST services.
-
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 HCL Commerce Search interface.
For more information about the default query postprocessors, see HCL Commerce Search configuration file (wc-search.xml).
Example
The 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.