null
value and are dropped.
let
, const
, or template strings, Fusion does not enable ES6 by default, so ES6 support is not guaranteed.
What a JavaScript program can do depends on the container in which it runs.
For a JavaScript Index stage, the container is a Managed 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. 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 Managed Fusion collection being indexed or queried. |
solrServer | BufferingsolrServer | The Solr server instance that manages the pipeline’s default Managed 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"); . |
logger
Java.type()
function:
if
or include ;
at the end of the line.
doc.hasField("title_s") === true
doc.hasField("title_s") === false
doc.hasField("title_s")
if doc.hasField("title_s") === false;
null
or an empty array, it will not be indexed or updated into Managed Fusion.
var
keywordvar
keyword, the JavaScript interpreter processes the value sequentially.
In this example, the values for var i = 0
are logged in order as 0
, 1
, 2
, 3
, 4
, etc.
var
keywordvar
keyword, the JavaScript interpreter moves the declaration of variable and functions to the top of the declared (global) scope. Because Managed Fusion pipeline stages execute in a multi-threaded environment, these global (shared) variables make the stages not thread-safe.
For more detailed information, see Hoisting.
i
may not proceed sequentially from 0 to 4 as the loop is processed. Instead, values may be logged based on the execution state of the other pipeline requests. For example, 0
, 1
, 3
, 1
, 2
, etc., which logs the values as "cat", "the cat", "the cat in the hat is back", "the cat", "the cat in the hat"
.
However, if only one thread is incrementing the i
variable, the values proceed sequentially (0
, 1
, 2
, 3
, 4
, etc.)
If the queries
array varies in length from document to document, the loop may generate an ArrayIndexOutOfBounds
exception for a Java array or an undefined
error for a JavaScript array.
Threads may not log all four queries.
"use strict"
directive"use strict"
directive tells the JavaScript engine to require non-global declarations of all functions and variables.
The following example demonstrates how to create a copy of a PipelineDocument
and return both the original and the copy to the pipeline for processing.