algolia / algoliasearch-client-python

⚡️ A fully-featured and blazing-fast Python API client to interact with Algolia.
https://www.algolia.com/doc/api-client/getting-started/install/python/?language=python
MIT License
196 stars 67 forks source link

feat(rules): Client side information consequence in rules #518

Open VladislavFitz opened 3 years ago

VladislavFitz commented 3 years ago

Summary

With the release of the merchandising UI, the need to control UI aspects using the QR is growing and the rules API needs to expose fields to store information to perform specific client side tasks in a structured way.

The new consequence consequence.renderingContent contains a json object where each top level attribute is restricted to known use cases. The currently identified use cases are:

Each top level excepted the userData one have a schema which is enforced and strict and customers can add metadata using the userData object:

{
    "condition": {
        "anchoring": "is",
        "pattern": "samsung"
    },
    "consequence": {
        "renderingContent": {
            "redirect": {
                "url": "https://algolia.com/samsung"       // required by the API
            },
            "facetMerchandising": {
                "order": [ "brand", "price"]                       // required by the API
            },
            "userData": {
                "callback": "displayBrand(samsung)"     // optional field defined by user
            }
        }
    }
}

This information will be returned in a structured way in the path rules.consequence of the search response:

{
  "hits": [...],
  [...],
  "query": "samsung",
  "rules": {
    "consequence": {
      "renderingContent": [    // Array containing the content of matching rules
        {
          "facetMerchandising": {
            "order": [
              "brand",
              "price"
            ]
          },
          "redirect": {
            "url": "https://algolia.com/samsung"
          },
          "userData": {
            "callback": "displayBrand(samsung)"
          }
        }
      ]
    }
  },
  "userData": [  // Legacy userData
    {
      "myUserData": {}
    }
  ]
}

Internal specs issue: #152