Version 5.1
How To
    Learn More

      Custom JavaScript Stages Global Variables

      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 reference to the container which holds a map over the pipeline properties. Used to update or modify this information for downstream pipeline stages.



      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.


      The SolrCluster server used for lookups by collection name which returns a Solr server instance for a that collection, e.g.
      var productsSolr = solrServerFactory.getSolrServer("products");.


      Used to create query pipeline requests and responses.


      Returns list of info as a string.

      The now-deprecated global variable _context refers to the same object as ctx.

      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 and interpreted. While using legacy syntax, these variables are used as global variables. With function syntax, however, these variables are passed as function parameters.

      Legacy Syntax

      request.addParam("foo", "bar");

      Function Syntax

      function(request,response) {
         request.addParam("foo", "bar");
      Function syntax is used for the examples in this document.

      Global variable logger

      The global variable named logger writes messages to the log file of the server running the pipeline. This variable is truly global and does not need to be declared as part of the function parameter list.

      Since Fusion’s API service does the query pipeline processing, these log messages go into the log file: {fusion_path}/var/log/api/api.log. There are 5 methods available, which each take either a single argument (the string message to log) or two arguments (the string message and an exception to log). The five methods are, "debug", "info", "warn", and "error".