Creating a custom query preprocessor
A query preprocessor modifies the
native
SolrQuery
object right before it is sent to the Solr server for
processing.Procedure
-
Create a class that does the following actions:
- Extends from the AbstractSearchQueryPreprocessor class, and
- Implements the SearchQueryPreprocessor interface.
-
Implement the
invoke
method, which takes theSearchCriteria
object and avarargs
as input parameters. ThisSearchCriteria
object is a Java representation of the original search expression, where search criteria is stored as a control parameter object.Thevarargs
contains thequeryRequestObjects
object, which is initialized by:super.invoke(SearchCriteria, queryRequestObjects);
Two instance variables can be used:- iSearchCriteria
- Java representation of the original search expression.
- queryRequestObjects
- Java representation of native search query request objects.
-
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 preprocessors, see HCL Commerce Search configuration file (wc-search.xml).
Example
The following download contains a code sample for creating a custom query preprocessor: