Custom JavaScript Stages for Query Pipelines
The JavaScript Query stage allows you to write custom processing logic using JavaScript to manipulate search requests and responses. The first time that the pipeline is run, Fusion compiles the JavaScript program into Java bytecode using the JDK’s JavaScript engine.
The JavaScript Query stage allows you to run JavaScript functions over search requests and responses by manipulating variables called "request" and "response" which are Request objects and Response objects, respectively.
Users who can create or modify code obtain access to the broader Fusion environment. This access can be used to create intentional or unintentional damage to Fusion. |
The JavaScript Engine Used by Fusion
The JavaScript engine used by Fusion is the Nashorn engine from Oracle. See The Nashorn Java API for details.
JavaScript Query Stage Global Variables
JavaScript is a lightweight scripting language. The JavaScript in a JavaScript stage is standard ECMAScript. What a JavaScript program can do depends on the container in which it runs. For a JavaScript Query stage, the container is a Fusion query pipeline. The following global pipeline variables are available:
Name | Type | Description | ||||
---|---|---|---|---|---|---|
|
The Solr query information. |
|||||
|
The Solr response information. |
|||||
|
A map that stores miscellaneous data created by each stage of the pipeline.
The
The data can differ between stages:
|
|||||
|
String |
The name of the Fusion collection being indexed or queried. |
||||
|
The Solr server instance that manages the pipeline’s default Fusion collection. All indexing and query requests are done by calls to methods on this object. See solrClient for details. |
|||||
|
Used to create query pipeline requests and responses. |
|||||
|
Returns list of info as a string. |
See Custom JavaScript Query Stage Examples for more information. |
Syntax Variants
JavaScript stages can be written using legacy syntax or function syntax. The key difference between these syntax variants is how the "global variables" are used. While using legacy syntax, these variables are used as global variables. With function syntax, however, these variables are passed as function parameters.
Function Syntax
function(request,response) {
request.addParam("foo", "bar");
}
Function syntax is used for the examples in this document. |
Global variable logger
The logs are output to the query service logs for custom query stages. Access the Log Viewer and filter on this service to view the information.