Skip to main content
This stage manipulates a query using a script from the blob store. The script must have the blob type file:js-query. See also: Custom JavaScript Stages For Query Pipelines.

Uploading a JavaScript blob

In Fusion 5.9, JavaScript blobs must be uploaded using the Blob Store API, like this:
Open the blob manager to verify that the new blob is present: Uploaded JavaScript blob in the blob manager

Referencing a JavaScript blob

Use any of the following formats for the ref/Script Reference configuration field:
The examples above use query-pipeline-js-stage.js as the blob ID.

Edit JavaScript

For Fusion 5.4.x and later, select Edit in the Script Reference field to edit JavaScript directly in the Fusion UI.

JavaScript examples

When reusing a script in both Managed JavaScript index stages and Managed JavaScript query stages, you need to upload it twice: once as a file:js-index blob and once as a file:js-query blob.

Set up a reusable library

This is an example of a reusable JavaScript library that provides various utility functions for string processing, date handling, and type conversion. To reuse Javascript functions, create a stage like this one that defines them, then place it before any of the stages that use it.

Call reusable JavaScript functions

This example demonstrates how to call reusable JavaScript functions from a library like the one in the example above. A JavaScript stage that calls these functions must be placed after the one that loads the library into the context. This example also adds debug logging to the context so that it can be appended to the response and viewed in Query Workbench.

Bury documents in search results

This example enables a productsToBury parameter that allows you to specify a list of product IDs to “bury” or demote in search results.

Manipulate the response object

This example demonstrates how to add a new field to the response that contains the lowercase version of an existing field. It uses the AbstractResponse class to manipulate response documents, which works for both XML and JSON responses for versatility.

Boost the products in a list

This example demonstrates how to boost specific products in search results based on a comma-separated list of product IDs. It uses the bq parameter to apply boosts, which allows for precise ranking control in search results. The boost values are linearly distributed between a maximum and minimum value, allowing for a smooth decrease in boost as the list progresses. This is useful for merchandising control, promotional campaigns, or A/B testing different product arrangements.

Boost products using Solr’s Query Elevation Component (QEC)

This example demonstrates how to elevate specific products in search results using the Query Elevation Component (QEC) in Solr. It converts a comma-separated list of product IDs into the elevateIds parameter format required by Solr’s QEC, allowing specific documents to be promoted to the top of search results. This is useful for merchandising control, promotional campaigns, or editorial control over search result ranking.

Query pipeline stage condition examples

Stages can be triggered conditionally when a script in the Condition field evaluates to true. Some examples are shown below. Run this stage only for mobile clients:
Run this stage when debugging is enabled:
Run this stage when the query includes a specific term:
Run this stage when multiple conditions are met:
The first condition checks that the request parameter “fusion-user-name” is present and has the value “SuperUser”. The second condition checks that the request parameter “isFusionPluginQuery” is not present.

Configuration

When entering configuration values in the UI, use unescaped characters, such as \t for the tab character. When entering configuration values in the API, use escaped characters, such as \\t for the tab character.