JavaScript Index Stage Global Variables
JavaScript is a lightweight scripting language. In a JavaScript stage, Fusion uses the Nashorn engine, which implements ECMAScript version 5.1. What a JavaScript program can do depends on the container in which it runs. For a JavaScript Index stage, the container is a Fusion index pipeline. The following global pipeline variables are available:Name | Type | Description |
---|---|---|
doc | PipelineDocument | The contents of each document submitted to the pipeline. |
ctx | Context | A map that stores miscellaneous data created by each stage of the pipeline. Important Use the ctx variable instead of the deprecated _context global variable. The ctx variable is used to: ● Pass data from one stage to another ● Store data that needs to be passed from one custom stage to a later custom stage The data can differ between stages: ● If the previous stage changes the data ● Based on the configuration of each stage If the data is modified in one stage, it may cause a later stage to function irregularly. |
collection | String | The name of the Fusion collection being indexed or queried. |
solrServer | BufferingsolrServer | 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 |
solrServerFactory | solrClusterComponent | The SolrCluster server used for lookups by collection name which returns a Solr server instance for that collection. For example: var productsSolr = solrServerFactory.getSolrServer("products"); . |
Syntax Variants
JavaScript stages can be written using function syntax. With function syntax, global variables are passed as function parameters.Support for legacy syntax was removed in Fusion 5.8.
Function Syntax
Function syntax is used for moderately complex tasks.ImportantFunction syntax is used for the examples in this document.
Advanced Syntax
Advanced syntax is used for complex tasks and when multiple functions are needed.JavaScript Use
The JavaScript in a JavaScript Index stage must return either a single document or an array of documents. This can be accomplished by either:- a series of statements where the final statement evaluates to a document or array of documents
- a function that returns a document or an array of documents
Global variable logger
The logs are output to the indexing service logs for custom index stages. Access the Log Viewer and filter on this service to view the information.
JavaScript Query Stage Global Variables
JavaScript is a lightweight scripting language. In a JavaScript stage, Fusion uses the Nashorn engine, which implements ECMAScript version 5.1. 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 |
---|---|---|
request | Request for a Regular Query | The request variable contains Solr query information and is referred to as a regular request. A regular query request does not include Search DSL (domain specific language) parameters. |
request | DSL Request | The request variable is also used when the query contains parameters for a Search DSL (domain specific language) request. See Domain Specific Language for more information. |
response | Response for a Regular Query | The response variable contains Solr response information, and is used to return information from a regular request. Because a regular request does not include Search DSL (domain specific language) parameters, the response will not return Search DSL results. |
response | DSL Response | The response variable is also used to return information from a Search DSL (domain specific language) request. See Domain Specific Language for more information. |
ctx | Context | A map that stores miscellaneous data created by each stage of the pipeline. Important Use the ctx variable instead of the deprecated _context global variable. ctx variable is used to: ● Pass data from one stage to another ● Store data that needs to be passed from one custom stage to a later custom stage The data can differ between stages: ● If the previous stage changes the data ● Based on the configuration of each stage If the data is modified in one stage, it may cause a later stage to function irregularly. |
collection | String | The name of the Fusion collection being indexed or queried. |
solrServer | BufferingsolrServer | 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. |
solrServerFactory | solrClusterComponent | The SolrCluster server used for lookups by collection name which returns a Solr server instance for that collection, e.g. var productsSolr = solrServerFactory.getSolrServer("products"); . |
QueryRequestAndResponse | QueryRequestAndResponse | Used to create query pipeline requests and responses. |
JSONResponse | JSONResponse | Returns list of info as a string. |
See Custom JavaScript Query Stage Examples for more information.
Syntax Variants
JavaScript stages can be written using function syntax. With function syntax, global variables are passed as function parameters.Support for legacy syntax was removed in Fusion 5.8.
Function Syntax
ImportantFunction syntax is used for the examples in this document.