API Reference / API Methods / Recommend / Get frequently bought together

Get Frequently Bought Together

Required API Key: any key with the search ACL
Method signature
$recommendClient->getFrequentlyBoughtTogether(array requests)

About this method

You are currently reading the JavaScript API client v4 documentation. Check our migration guide to learn how to upgrade from v3 to v4. You can still access the v3 documentation.

You are currently reading the Ruby API client v2 documentation. Check our migration guide to learn how to upgrade from v1 to v2. You can still access the v1 documentation.

Retrieve frequently bought together items for a set of objectIDs.

You can’t use fallbackParameters with Frequently Bought Together as it’s impossible to emulate based on search parameters alone. If there isn’t enough data for Frequently Bought Together, it’s better to show a different type of recommendations, for example, Related Products.

Examples

1
2
3
4
5
6
$recommendations = $recommendClient->getFrequentlyBoughtTogether([
  [
    'indexName' => 'your_index_name',
    'objectID' => 'your_object_id',
  ],
]);

Parameters

requests
type: list of request object
Required

A list of request objects to execute.

requests ➔ request object

indexName
type: string
Required

The name of the target index.

objectID
type: string
Required

The objectID of the item to get recommendations for.

maxRecommendations
type: number

How many recommendations to retrieve.

threshold
type: number
default: 0

Threshold for the recommendations confidence score (between 0 and 100). Only recommendations with a greater score are returned.

queryParameters
type: Omit<SearchParameters, 'page' | 'hitsPerPage' | 'offset' | 'length'>

List of search parameters to send.

Response

In this section we document the JSON response returned by the API. Each language will encapsulate this response inside objects specific to the language and/or the implementation. So the actual type in your language might differ from what is documented.

JSON format

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
{
  "results": [
    {
      "hits": [
        {
          "_highlightResult": {
            "category": {
              "matchLevel": "none",
              "matchedWords": [],
              "value": "Men - T-Shirts"
            },
            "image_link": {
              "matchLevel": "none",
              "matchedWords": [],
              "value": "https://example.org/image/D05927-8161-111-F01.jpg"
            },
            "name": {
              "matchLevel": "none",
              "matchedWords": [],
              "value": "Jirgi Half-Zip T-Shirt"
            }
          },
          "_score": 32.72,
          "category": "Men - T-Shirts",
          "image_link": "https://example.org/image/D05927-8161-111-F01.jpg",
          "name": "Jirgi Half-Zip T-Shirt",
          "objectID": "D05927-8161-111",
          "position": 105,
          "url": "men/t-shirts/d05927-8161-111"
        }
      ],
      "processingTimeMS": 1,
    }
  ]
}
results
list of result

List of results in the order they were submitted, one per query.

{
  "results": [
    {
      "hits": [
        {
          ...,
          _score: 32.72
        }
      ],
    },
  ]
}

results ➔ result

The results object contains the same hits object as the one of the search method. Each result also includes the following additional field:

_score
number

The confidence score of the recommended item, the closer it’s to 100, the more relevant.

Did you find this page helpful?