Adding numeric metadata constraints via a hook script

Background

This article discusses how to add a numerical metadata constraint via a hook script. Numerical metadata constraints are set using special CGI parameters, and these are pre-processed populating other parts of the data model (before the pre_process hook script runs) so special steps are required to set the values in the hook script.

Pre-process hook script

The pre-process hook script is used to set the numerical constraint, but adding the parameters to both the inputParameterMap and the additionalParameters elements within the data model.

hook_pre_process.groovy
// Add a numeric metadata constraint.  Restrict results to items when the price metadata field
// contains a value greater than or equal to 50
//
// This is equivalent to adding a CGI parameter &ge_price=50 to the query string.

transaction.question.inputParameterMap["ge_price"] = 50
transaction.question.additionalParameters["ge_price"] = 50