Skip to main content
The following is a list of examples for reference when creating custom JavaScript Query stages.

Add a parameter to the query request

Add a parameter to the query response

This example contains a simple JavaScript function which copies information from the ctx (Context) object into the query response. Requirements:
  • The response parameter cannot be used in query pipeline stages prior to the Solr query stage. This example assumes use in a later stage.
  • The response.initialEntity.appendStringList() function only works if the query’s wt (writer type) parameter is set to json or xml, for example: wt=json.

Java object interactions

The default JavaScript engine used by Fusion is the Nashorn engine from Oracle. See The Nashorn Java API for details. In Fusion 5.9.6 and up, you also have the option to select OpenJDK Nashorn. While Nashorn is the default option, it is in the process of being deprecated and will eventually be removed, so it is recommended to use OpenJDK Nashorn when possible. You can select the JavaScript engine in the pipeline views or in the workbenches. Your JavaScript pipeline stages are interpreted by the selected engine. JavaScript engine selector The Nashorn engine exposes the full Java Classpath to JavaScript. This means that Java objects can be instantiated and called from JavaScript. Objects returned by a call to a Java function will not be JavaScript objects. For example, calling typeof(object) will not give meaningful results. Instead, you can use JavaScript to discover the Java type of an object. Once you know the Java type of an object, you can refer to the Fusion Pipeline Javadocs to learn more about the Java type and how to use Java Objects.
For more information, see JavaScript Query Stage Global Variables for Fusion 5.x.x.