Get recommendations
search
ACL
$recommendClient->getRecommendations(array requests)
We released a new version of the PHP API client in public beta. Read the beta documentation for more information.
We released a new version of the JavaScript API client in public beta. Read the beta documentation for more information.
We released a new version of the Java API client in public beta. Read the beta documentation for more information.
You’re currently reading the JavaScript API client v4 documentation. Check the migration guide to learn how to upgrade from v3 to v4. You can still access the v3 documentation.
You’re currently reading the Ruby API client v2 documentation. Check the migration guide to learn how to upgrade from v1 to v2. You can still access the v1 documentation.
About this method
Get recommendations from any Algolia recommendation model.
To get recommendations for specific models,
use the specific methods instead—for example,
getRelatedProducts
,
getTrendingItems
,
or getFrequentlyBoughtTogether
.
Examples
Read the Algolia CLI documentation for more information.
1
2
3
4
5
6
7
$recommendations = $recommendClient->getRecommendations([
[
'indexName' => 'your_index_name',
'objectID' => 'your_object_id',
'model' => 'bought-together',
],
]);
Parameters
Parameter | Description |
---|---|
requests
|
type: array of request object
Required
List of request objects. |
requests âž” request object
The parameters for the request body depend on the requested model. The following parameters are common to all models.
Parameter | Description |
---|---|
indexName
|
type: string
Required
Name of the index. |
model
|
type: "related-products" | "bought-together" | "trending-items" | "trending-facets"
Required
Name of the recommendation model to use. |
threshold
|
type: number
Required
Threshold for the recommendations confidence score (between 0 and 100). Only recommendations with a greater score are returned. |
maxRecommendations
|
type: integer
Number of recommendations to retrieve.
Depending on the available recommendations and the other request parameters,
the actual number of recommendations may be lower than that.
If you don’t set |
requests âž” request object with bought-together
{ indexName: "YourIndexName", model: "bought-together", threshold: 0, maxRecommendations: 10, objectID: "an objectID", queryParameters: { query parameters }, }
Get recommendations from the ‘bought-together’ model given an object ID.
Parameter | Description |
---|---|
objectID
|
type: string
Required
Object ID for which to get recommendations. |
queryParameters
|
type: object
Optional
Search parameters for filtering the recommendations. |
requests âž” request object with related-products
{ indexName: "YourIndexName", model: "related-products", threshold: 0, maxRecommendations: 10, objectID: "an objectID", queryParameters: { query parameters }, fallbackParameters: { query parameters } }
Get recommendations from the ‘related-products’ model given an object ID.
Parameter | Description |
---|---|
objectID
|
type: string
Required
Object ID for which to get recommendations. |
queryParameters
|
type: object
Optional
Search parameters for filtering the recommendations. |
fallbackParameters
|
type: object
Optional
Search parameters to use as fallback when there are no recommendations. |
requests âž” request object with trending-items
{ indexName: "YourIndexName", model: "trending-items", threshold: 0, maxRecommendations: 10, facetName: "a facet attribute name", facetValue: "a facet value", queryParameters: { query parameters }, fallbackParameters: { query parameters } }
Fetch trending items, either globally or only those matching a specific facet. The following parameters are specific to model ‘trending-items’. If no facet is provided, the query fetches globally trending items.
Parameter | Description |
---|---|
facetName
|
type: string
Optional
Facet attribute for which to get recommendations. This parameter must be used together with facetValue. |
facetValue
|
type: string
Optional
Facet value for which to get recommendations for. This parameter must be used along with facetName. |
queryParameters
|
type: object
Optional
Search parameters for filtering the recommendations. |
fallbackParameters
|
type: object
Optional
Search parameters to use as fallback when there are no recommendations. |
requests âž” request object with trending-facets
{ indexName: "YourIndexName", model: "trending-facets", threshold: 0, maxRecommendations: 10, facetName: "a facet attribute name", }
Fetch trending facet values given a specific facet attribute. The following parameters are specific to model ‘trending-facets’.
Parameter | Description |
---|---|
facetName
|
type: string
Required
Facet attribute for which to get recommendations. |
Response
This section shows the JSON response returned by the API.
Each API client encapsulates this response inside objects specific to the programming language,
so that the actual response might be different.
You can view the response by using the getLogs
method.
Don’t rely on the order of attributes in the response, as JSON doesn’t guarantee the ordering of keys in objects.
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,
}
]
}
Field | Description |
---|---|
results
|
array 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 in the search
method
augmented by a _score
attribute.
Field | Description |
---|---|
_score
|
number
Confidence score of the recommended item. The closer it is to 100, the more relevant. |