Removing input parameters for extra searches

Managed by | Updated .

Background

There are some occasions where it is necessary to add metadata CGI parameters to a search that has extra searches enabled. These input parameters will be added to the extra search query automatically and can negatively impact the results returned in the extra search.

Implementation steps

The following code can be used to remove all metadata input parameters that an extra search inherits 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. Loop through the inputParameterMap and remove each key found that matches meta_.

Example

// Change "extra-search-name" to your extra search.
if ( transaction.extraSearchesQuestions["extra-search-name"] != null ) {
    def searchQuestion = transaction.extraSearchesQuestions["extra-search-name"]   
    //remove all meta CGI parameters set on the main search  
    searchQuestion.inputParameterMap.each{ k, v -> 
        if (k.startsWith("meta_")){
            searchQuestion.inputParameterMap.remove(k); 
        }
    }
}
Was this artcle helpful?

Tags
Type: Keywords:
Features: Frontend > Hook scripts Frontend > Extra searches

Comments