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 JavaScript engine used by Fusion is the Nashorn engine from Oracle. See The Nashorn Java API for details. 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.

Manually add dependencies

To install dependencies manually, jar files must be placed in the ./apps/libs folder. The jar file path must be included in .apps/jetty/api/webapps/api-extra-classpath.txt and apps/jetty/connectors-classic/webapps/connectors-extra-classpath.txt. For example, to create script objects that access and reference Java types from Javascript use the Java.type() function:
For more information, see Custom JavaScript Stages Variables and Parameters for Fusion 4.x.x.