Disable extra searches via a hook script
Managed by | Updated .
Background
There are some occasions where it is necessary to conditionally run an extra search. This article shows how to implement this using a hook script.
Implementation steps
The following process can be used to disable extra searches via the extra searches hook script.
1. Create a hook_extra_searches.groovy script on the collection that is being queried. This can be done using the file manager for the collection.
2. Conditionally remove the extra search question from the data model based on some application logic.
Example
For this example the extra searches are displayed unless there is a custom CGI parameter (showonly) set. When set, the value of showonly is used to determine which extra searches run. The extra searches in this example are named 'type1', 'type2' and 'type3'.
// If the showonly CGI param is set to display a single type of results disable the other extra searches.
if (transaction.question.inputParameterMap["showonly"] != null) {
if (transaction.question.inputParameterMap["showonly"] == "type1") {
if ( transaction.extraSearchesQuestions["type2"] != null ) {
transaction.extraSearchesQuestions.remove("type2")
}
if ( transaction.extraSearchesQuestions["type3"] != null ) {
transaction.extraSearchesQuestions.remove("type3")
}
}
else if (transaction.question.inputParameterMap["showonly"] == "type2") {
if ( transaction.extraSearchesQuestions["type1"] != null ) {
transaction.extraSearchesQuestions.remove("type1")
}
if ( transaction.extraSearchesQuestions["type3"] != null ) {
transaction.extraSearchesQuestions.remove("type3")
}
}
else if (transaction.question.inputParameterMap["showonly"] == "type3") {
if ( transaction.extraSearchesQuestions["type1"] != null ) {
transaction.extraSearchesQuestions.remove("type1")
}
if ( transaction.extraSearchesQuestions["type2"] != null ) {
transaction.extraSearchesQuestions.remove("type2")
}
}
}
- Removing input parameters for extra searches
- Supporting dynamic date range searches
- Modifying geo-spatial parameters in the data model (origin, maxdist)
- Writing hook script code for specific search types
- Supporting empty queries
- Incompatible query processor options in Content and Accessibility Auditor