Using filtering, rules, and content types to create a complex request for recommendations

You can specify exactly what you want to show as recommendations by using the recommendations.content, recommendations.filter and recommendations.rule objects.

For the complete data model, see the Search and Recommendation API reference.

For example, you want to get recommendations in the following scenario:

  • You want only the title and image attribute values for each content item. To do this, pass title and image as values of the recommendations.content.fields object.

  • You want to filter recommendations by geographical region. Specifically, you want recommendations relevant to a visitor who is at 37.8136 degrees South and 144.9631 degrees West. To do this, use the recommendations.filter object, specify geoDistance as the filter type and define a radius (the distance) within which to look for recommendations.

  • You want to boost items that have a type attribute value of news into the first slot. To do this, use the recommendations.rule object, specify boost as the rule type, and set the slots to 1.

Here's a sample request:

RequestResponse
{
  "context": {
    "locale": "en-us",
    "page": {
      "uri": "/sample-page"
    },
    "user": {
      "uuid": "123e4567-e89b-12d3-a456-426614174000"
    }
  },
  "source": "12345",
  "widget": {
    "items": [
      {
        "entity": "content",
        "rfk_id": "rfkid_1",
        "recommendations": {
          "content": {
            "fields": [
              "title", "image"
            ]
          },
          "filter": {
            "type": "geoDistance",
            "name": "location",
            "distance": "50km",
            "lat": 37.8136,
            "lon": -144.9631 
          },
          "limit": 5,
          "rule": {
            "boost": [
              {
                "filter": {
                  "type": "eq",
                  "name": "type",
                  "value": "news" 
                },
                "slots": [
                  1 
                ],
                "weight": 1
              }
            ]
          }
        }
      }
    ]
  }
}

Do you have some feedback for us?

If you have suggestions for improving this article,