Looking for the old docs site? You can still view it for a limited time here.

Use the API to Create Custom Rules

You can create a custom rule type by POSTing to the /query-rewrite/schema endpoint. A custom rule type has:

  • an id field, which must be unique across all apps in Fusion (global namespace)

  • a pipeline_id that is invoked during rule processing

  • a display_type that gives a human-friendly name to the custom rule type

  • a JSON schema that defines a set of parameters to pass to the pipeline during rule processing

For example, the following custom rule type with ID some_custom_rule calls the custom_pipeline during rule processing and passes the values for custom_param1 and custom_param2:

curl -XPOST -H "Content-type:application/json" \
"http://localhost:8765/api/v1/apps/best-buy/query-rewrite/schema" -d '{
  "id":"some_custom_rule",
  "pipeline_id":"custom_pipeline",
  "response_pipeline_id":"do_more_custom_stuff_here",
  "display_type":"Custom Rule",
  "schema": {
    "type" : "object",
    "properties" : {
      "custom_param1" : {
        "type" : "string",
        "title" : "Custom Param One",
        "description" : "Some param from the rule creator"
      },
      "custom_param2" : {
        "type": "string",
        "title": "Custom Param 2",
        "description": "Some other param the rule creator needs to provide"
      }
    }
  }
}'

The rules editor UI will render this custom rule type with input fields for custom_param1 and custom_param2.

Here’s an example of how to create an instance of the custom rule type:

curl -XPOST -H "Content-type:application/json" \
http://localhost:8765/api/v1/apps/best-buy/query-rewrite/instances -d '{
  "id":"some_custom_rule1",
  "type":"some_custom_rule",
  "custom_type":"some_custom_rule",
  "name":"My Custom Rule 1",
  "description":"Call another pipeline to do custom things",
  "search_terms":["fusion"],
  "custom_param1":"This is the user-supplied value of custom_param1",
  "custom_param2":"This is the user-supplied value of custom_param2",
  "pipeline_id":"custom_pipeline",
  "display_type":"Custom Rule"
}'

When the user queries for "fusion", the custom rule will match (using search_terms) and the rules processing stage will call custom_pipeline, passing parameters custom_param1 and custom_param2 in the request.

Presumably, the custom_pipeline uses these parameters to perform some custom logic. When the invoked pipeline (such as custom_pipeline) returns, the rules processing stage running in the main pipeline extracts the parameters returned from the invoked pipeline and adds them to the main request. If the invoked pipeline has a rules processing stage, it will not re-invoke itself if any matching rules in the invoked pipeline would result in an infinite loop.