Skip to content

Commit 16ba906

Browse files
authored
feat(spec): add trending models (#213)
1 parent 009455f commit 16ba906

File tree

16 files changed

+354
-110
lines changed

16 files changed

+354
-110
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import type { SearchParamsObject } from './searchParamsObject';
2+
3+
export type BaseRecommendRequest = {
4+
/**
5+
* The Algolia index name.
6+
*/
7+
indexName: string;
8+
/**
9+
* The threshold to use when filtering recommendations by their score.
10+
*/
11+
threshold: number;
12+
/**
13+
* The max number of recommendations to retrieve. If it\'s set to 0, all the recommendations of the objectID may be returned.
14+
*/
15+
maxRecommendations?: number;
16+
queryParameters?: SearchParamsObject;
17+
fallbackParameters?: SearchParamsObject;
18+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { RecommendationModels } from './recommendationModels';
2+
3+
export type BaseRecommendationRequest = {
4+
model: RecommendationModels;
5+
/**
6+
* Unique identifier of the object.
7+
*/
8+
objectID: string;
9+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { TrendingModels } from './trendingModels';
2+
3+
export type BaseTrendingRequest = {
4+
model: TrendingModels;
5+
/**
6+
* The facet name to use for trending models.
7+
*/
8+
facetName?: string;
9+
/**
10+
* The facet value to use for trending models.
11+
*/
12+
facetValue?: string;
13+
};
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { RecommendationRequest } from './recommendationRequest';
1+
import type { RecommendationsRequest } from './recommendationsRequest';
22

33
/**
44
* The `getRecommendations` parameters.
@@ -7,5 +7,5 @@ export type GetRecommendationsParams = {
77
/**
88
* The `getRecommendations` requests.
99
*/
10-
requests: RecommendationRequest[];
10+
requests: RecommendationsRequest[];
1111
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/**
2+
* The recommendation model to use.
3+
*/
4+
5+
export type RecommendationModels = 'bought-together' | 'related-products';
Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,5 @@
1-
import type { SearchParams } from './searchParams';
1+
import type { BaseRecommendRequest } from './baseRecommendRequest';
2+
import type { BaseRecommendationRequest } from './baseRecommendationRequest';
23

3-
export type RecommendationRequest = {
4-
/**
5-
* The Algolia index name.
6-
*/
7-
indexName: string;
8-
/**
9-
* Unique identifier of the object.
10-
*/
11-
objectID: string;
12-
/**
13-
* The recommendation model to use.
14-
*/
15-
model: RecommendationRequestModel;
16-
/**
17-
* The threshold to use when filtering recommendations by their score.
18-
*/
19-
threshold: number;
20-
/**
21-
* The max number of recommendations to retrieve. If it\'s set to 0, all the recommendations of the objectID may be returned.
22-
*/
23-
maxRecommendations?: number;
24-
queryParameters?: SearchParams;
25-
fallbackParameters?: SearchParams;
26-
};
27-
28-
export type RecommendationRequestModel = 'bought-together' | 'related-products';
4+
export type RecommendationRequest = BaseRecommendationRequest &
5+
BaseRecommendRequest;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import type { RecommendationRequest } from './recommendationRequest';
2+
import type { TrendingRequest } from './trendingRequest';
3+
4+
export type RecommendationsRequest = RecommendationRequest | TrendingRequest;

clients/algoliasearch-client-javascript/packages/recommend/model/searchParams.ts renamed to clients/algoliasearch-client-javascript/packages/recommend/model/searchParamsObject.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ import type { BaseSearchParams } from './baseSearchParams';
22
import type { IndexSettingsAsSearchParams } from './indexSettingsAsSearchParams';
33
import type { RequiredSearchParams } from './requiredSearchParams';
44

5-
export type SearchParams = BaseSearchParams &
5+
export type SearchParamsObject = BaseSearchParams &
66
IndexSettingsAsSearchParams &
77
RequiredSearchParams;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/**
2+
* The trending model to use.
3+
*/
4+
5+
export type TrendingModels = 'trending-facets' | 'trending-items';
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import type { BaseRecommendRequest } from './baseRecommendRequest';
2+
import type { BaseTrendingRequest } from './baseTrendingRequest';
3+
4+
export type TrendingRequest = BaseRecommendRequest & BaseTrendingRequest;

specs/bundled/recommend.yml

Lines changed: 76 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,16 @@ components:
4242
message:
4343
type: string
4444
example: Invalid Application-Id or API-Key
45+
trendingModels:
46+
description: The trending model to use.
47+
type: string
48+
enum:
49+
- trending-facets
50+
- trending-items
4551
indexName:
4652
type: string
4753
example: products
4854
description: The Algolia index name.
49-
objectID:
50-
type: string
51-
description: Unique identifier of the object.
5255
page:
5356
type: integer
5457
description: Specify the page to retrieve.
@@ -556,11 +559,79 @@ components:
556559
set via the settings for a default value and can be overridden via
557560
rules.
558561
default: {}
559-
searchParams:
562+
searchParamsObject:
560563
allOf:
561564
- $ref: '#/components/schemas/baseSearchParams'
562565
- $ref: '#/components/schemas/requiredSearchParams'
563566
- $ref: '#/components/schemas/indexSettingsAsSearchParams'
567+
baseRecommendRequest:
568+
type: object
569+
additionalProperties: false
570+
properties:
571+
indexName:
572+
$ref: '#/components/schemas/indexName'
573+
threshold:
574+
type: integer
575+
minimum: 0
576+
maximum: 100
577+
description: The threshold to use when filtering recommendations by their score.
578+
maxRecommendations:
579+
type: integer
580+
default: 0
581+
description: >-
582+
The max number of recommendations to retrieve. If it's set to 0, all
583+
the recommendations of the objectID may be returned.
584+
queryParameters:
585+
$ref: '#/components/schemas/searchParamsObject'
586+
fallbackParameters:
587+
$ref: '#/components/schemas/searchParamsObject'
588+
required:
589+
- indexName
590+
- threshold
591+
trendingRequest:
592+
allOf:
593+
- type: object
594+
title: baseTrendingRequest
595+
additionalProperties: false
596+
properties:
597+
model:
598+
$ref: '#/components/schemas/trendingModels'
599+
facetName:
600+
type: string
601+
description: The facet name to use for trending models.
602+
facetValue:
603+
type: string
604+
description: The facet value to use for trending models.
605+
required:
606+
- model
607+
- $ref: '#/components/schemas/baseRecommendRequest'
608+
recommendationModels:
609+
description: The recommendation model to use.
610+
type: string
611+
enum:
612+
- related-products
613+
- bought-together
614+
objectID:
615+
type: string
616+
description: Unique identifier of the object.
617+
recommendationRequest:
618+
allOf:
619+
- type: object
620+
title: baseRecommendationRequest
621+
additionalProperties: false
622+
properties:
623+
model:
624+
$ref: '#/components/schemas/recommendationModels'
625+
objectID:
626+
$ref: '#/components/schemas/objectID'
627+
required:
628+
- model
629+
- objectID
630+
- $ref: '#/components/schemas/baseRecommendRequest'
631+
recommendationsRequest:
632+
oneOf:
633+
- $ref: '#/components/schemas/trendingRequest'
634+
- $ref: '#/components/schemas/recommendationRequest'
564635
abTestID:
565636
type: integer
566637
description: >-
@@ -1025,43 +1096,7 @@ paths:
10251096
type: array
10261097
description: The `getRecommendations` requests.
10271098
items:
1028-
title: recommendationRequest
1029-
type: object
1030-
additionalProperties: false
1031-
properties:
1032-
indexName:
1033-
$ref: '#/components/schemas/indexName'
1034-
objectID:
1035-
$ref: '#/components/schemas/objectID'
1036-
model:
1037-
description: The recommendation model to use.
1038-
type: string
1039-
enum:
1040-
- related-products
1041-
- bought-together
1042-
threshold:
1043-
type: integer
1044-
minimum: 0
1045-
maximum: 100
1046-
description: >-
1047-
The threshold to use when filtering recommendations by
1048-
their score.
1049-
maxRecommendations:
1050-
type: integer
1051-
default: 0
1052-
description: >-
1053-
The max number of recommendations to retrieve. If it's
1054-
set to 0, all the recommendations of the objectID may
1055-
be returned.
1056-
queryParameters:
1057-
$ref: '#/components/schemas/searchParams'
1058-
fallbackParameters:
1059-
$ref: '#/components/schemas/searchParams'
1060-
required:
1061-
- model
1062-
- indexName
1063-
- objectID
1064-
- threshold
1099+
$ref: '#/components/schemas/recommendationsRequest'
10651100
required:
10661101
- requests
10671102
responses:
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
recommendationsRequest:
2+
oneOf:
3+
- $ref: '#/trendingRequest'
4+
- $ref: '#/recommendationRequest'
5+
6+
trendingRequest:
7+
allOf:
8+
- type: object
9+
title: baseTrendingRequest
10+
additionalProperties: false
11+
properties:
12+
model:
13+
$ref: '#/trendingModels'
14+
facetName:
15+
type: string
16+
description: The facet name to use for trending models.
17+
facetValue:
18+
type: string
19+
description: The facet value to use for trending models.
20+
required:
21+
- model
22+
- $ref: '#/baseRecommendRequest'
23+
24+
recommendationRequest:
25+
allOf:
26+
- type: object
27+
title: baseRecommendationRequest
28+
additionalProperties: false
29+
properties:
30+
model:
31+
$ref: '#/recommendationModels'
32+
objectID:
33+
$ref: '../../../common/parameters.yml#/objectID'
34+
required:
35+
- model
36+
- objectID
37+
- $ref: '#/baseRecommendRequest'
38+
39+
baseRecommendRequest:
40+
type: object
41+
additionalProperties: false
42+
properties:
43+
indexName:
44+
$ref: '../../../common/parameters.yml#/indexName'
45+
threshold:
46+
type: integer
47+
minimum: 0
48+
maximum: 100
49+
description: The threshold to use when filtering recommendations by their score.
50+
maxRecommendations:
51+
type: integer
52+
default: 0
53+
description: The max number of recommendations to retrieve. If it's set to 0, all the recommendations of the objectID may be returned.
54+
queryParameters:
55+
$ref: '../../../common/schemas/SearchParams.yml#/searchParamsObject'
56+
fallbackParameters:
57+
$ref: '../../../common/schemas/SearchParams.yml#/searchParamsObject'
58+
required:
59+
- indexName
60+
- threshold
61+
62+
trendingModels:
63+
description: The trending model to use.
64+
type: string
65+
enum: [trending-facets, trending-items]
66+
67+
recommendationModels:
68+
description: The recommendation model to use.
69+
type: string
70+
enum: [related-products, bought-together]

specs/recommend/common/schemas/SearchParams.yml

Lines changed: 0 additions & 5 deletions
This file was deleted.

specs/recommend/paths/getRecommendations.yml

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,7 @@ post:
1616
type: array
1717
description: The `getRecommendations` requests.
1818
items:
19-
title: recommendationRequest
20-
type: object
21-
additionalProperties: false
22-
properties:
23-
indexName:
24-
$ref: '../../common/parameters.yml#/indexName'
25-
objectID:
26-
$ref: '../../common/parameters.yml#/objectID'
27-
model:
28-
description: The recommendation model to use.
29-
type: string
30-
enum: [related-products, bought-together]
31-
threshold:
32-
type: integer
33-
minimum: 0
34-
maximum: 100
35-
description: The threshold to use when filtering recommendations by their score.
36-
maxRecommendations:
37-
type: integer
38-
default: 0
39-
description: The max number of recommendations to retrieve. If it's set to 0, all the recommendations of the objectID may be returned.
40-
queryParameters:
41-
$ref: '../common/schemas/SearchParams.yml#/searchParams'
42-
fallbackParameters:
43-
$ref: '../common/schemas/SearchParams.yml#/searchParams'
44-
required:
45-
- model
46-
- indexName
47-
- objectID
48-
- threshold
19+
$ref: '../common/schemas/RecommendationsRequest.yml#/recommendationsRequest'
4920
required:
5021
- requests
5122
responses:

0 commit comments

Comments
 (0)