Adding numeric metadata constraints via a hook script
Managed by | Updated .
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"]
Was this artcle helpful?
Similar
- Replace diacritic (accented) characters
- Set non CGI query processor options in hook script
- Disable extra searches via a hook script
- Removing input parameters for extra searches
- Modifying the highlight regular expression used by <@s.Boldicize>
- Modifying geo-spatial parameters in the data model (origin, maxdist)
Latest In this section
- Replace diacritic (accented) characters
- Accessing data model variables that start with a single lower case letter
- Adding numeric metadata constraints via a hook script
- Modifying geo-spatial parameters in the data model (origin, maxdist)
- Storing custom data within the data model
- Writing hook script code for specific search types