Skip to content

Commit dc28c02

Browse files
raed667millotpshortcuts
authored
feat(specs): add recommend batch rules endpoint (#3782)
Co-authored-by: Pierre Millot <[email protected]> Co-authored-by: Clément Vannicatte <[email protected]>
1 parent 1d95849 commit dc28c02

File tree

10 files changed

+133
-19
lines changed

10 files changed

+133
-19
lines changed

generators/src/main/java/com/algolia/codegen/AlgoliaSwiftGenerator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ public class AlgoliaSwiftGenerator extends Swift5ClientCodegen {
106106
"supportedlanguage",
107107
"tagfilters",
108108
"taskstatus",
109+
"timerange",
109110
"typotolerance",
110111
"typotoleranceenum",
111112
"value"

playground/javascript/node/recommend.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const searchQuery = process.env.SEARCH_QUERY || 'test_query';
1010
// Init client with appId and apiKey
1111
const client = recommendClient(appId, apiKey);
1212

13-
async function testRecommend() {
13+
async function testGetRecommendations() {
1414
try {
1515
const res = await client.getRecommendations({
1616
requests: [
@@ -23,14 +23,20 @@ async function testRecommend() {
2323
],
2424
});
2525

26-
console.log(`[OK]`, res);
26+
console.log('[OK] GetRecommendations', res);
2727
} catch (e) {
2828
if (e instanceof ApiError) {
2929
return console.log(`[${e.status}] ${e.message}`, e.stackTrace);
3030
}
3131

32-
console.log('[ERROR]', e);
32+
console.log('[ERROR] GetRecommendations', e);
3333
}
3434
}
3535

36+
37+
38+
async function testRecommend() {
39+
await testGetRecommendations();
40+
}
41+
3642
testRecommend();

specs/common/schemas/Rule.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,17 @@ context:
66
For example, if `context: mobile`, the rule is only triggered when the search request has a matching `ruleContexts: mobile`.
77
A rule context must only contain alphanumeric characters.
88
example: mobile
9+
10+
timeRange:
11+
type: object
12+
additionalProperties: false
13+
properties:
14+
from:
15+
type: integer
16+
description: When the rule should start to be active, in Unix epoch time.
17+
until:
18+
type: integer
19+
description: When the rule should stop to be active, in Unix epoch time.
20+
required:
21+
- from
22+
- until
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
description: OK
2+
content:
3+
application/json:
4+
schema:
5+
$ref: './common.yml#/recommendUpdatedAtResponse'
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
taskID:
2+
type: integer
3+
format: int64
4+
example: 1514562690001
5+
description: |
6+
Unique identifier of a task.
7+
8+
A successful API response means that a task was added to a queue. It might not run immediately. You can check the task's progress with the [`task` operation](#tag/Indices/operation/getTask) and this `taskID`.
9+
10+
updatedAt:
11+
type: string
12+
example: 2023-07-04T12:49:15Z
13+
description: Date and time when the object was updated, in RFC 3339 format.
14+
15+
recommendUpdatedAtResponse:
16+
type: object
17+
description: Response, taskID, and update timestamp.
18+
additionalProperties: false
19+
required:
20+
- taskID
21+
- updatedAt
22+
properties:
23+
taskID:
24+
$ref: '#/taskID'
25+
updatedAt:
26+
$ref: '#/updatedAt'

specs/recommend/common/schemas/RecommendRule.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ RecommendRule:
99
description: Rule metadata.
1010
properties:
1111
lastUpdate:
12-
$ref: '../../../common/responses/common.yml#/updatedAt'
12+
$ref: '../responses/common.yml#/updatedAt'
1313
objectID:
1414
$ref: '../../../common/parameters.yml#/ruleID'
1515
condition:
@@ -19,11 +19,16 @@ RecommendRule:
1919
description:
2020
type: string
2121
description: Description of the rule's purpose. This can be helpful for display in the Algolia dashboard.
22-
example: 'Display a promotional banner'
22+
example: 'Boost on-sale items'
2323
enabled:
2424
type: boolean
2525
default: true
2626
description: Indicates whether to enable the rule. If it isn't enabled, it isn't applied at query time.
27+
validity:
28+
type: array
29+
description: Time periods when the rule is active.
30+
items:
31+
$ref: '../../../common/schemas/Rule.yml#/timeRange'
2732

2833
Condition:
2934
type: object
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
post:
2+
tags:
3+
- rules
4+
operationId: batchRecommendRules
5+
x-acl:
6+
- editSettings
7+
summary: Create or update a batch of Recommend Rules
8+
description: |
9+
Create or update a batch of Recommend Rules
10+
11+
Each Recommend Rule is created or updated, depending on whether a Recommend Rule with the same `objectID` already exists.
12+
You may also specify `true` for `clearExistingRules`, in which case the batch will atomically replace all the existing Recommend Rules.
13+
14+
Recommend Rules are similar to Search Rules, except that the conditions and consequences apply to a [source item](/doc/guides/algolia-recommend/overview/#recommend-models) instead of a query. The main differences are the following:
15+
- Conditions `pattern` and `anchoring` are unavailable.
16+
- Condition `filters` triggers if the source item matches the specified filters.
17+
- Condition `filters` accepts numeric filters.
18+
- Consequence `params` only covers filtering parameters.
19+
- Consequence `automaticFacetFilters` doesn't require a facet value placeholder (it tries to match the data source item's attributes instead).
20+
parameters:
21+
- $ref: '../../common/parameters.yml#/IndexName'
22+
- $ref: '../common/parameters.yml#/Models'
23+
requestBody:
24+
content:
25+
application/json:
26+
schema:
27+
title: rules
28+
type: array
29+
description: Recommend rules.
30+
additionalProperties: false
31+
items:
32+
$ref: '../common/schemas/RecommendRule.yml#/RecommendRule'
33+
34+
responses:
35+
'200':
36+
$ref: '../common/responses/RecommendUpdatedAt.yml'
37+
'400':
38+
$ref: '../../common/responses/BadRequest.yml'

specs/recommend/spec.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ paths:
131131

132132
/1/indexes/{indexName}/{model}/recommend/rules/search:
133133
$ref: 'paths/searchRecommendRules.yml'
134+
135+
/1/indexes/{indexName}/{model}/recommend/rules/batch:
136+
$ref: 'paths/batchRecommendRules.yml'
134137

135138
# ###############
136139
# ### Helpers ###

templates/javascript/clients/algoliasearch/builds/models.mustache

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import type {
1313
AroundRadiusAll,
1414
AutomaticFacetFilter,
1515
AutomaticFacetFilters,
16-
BaseSearchParams,
1716
BaseIndexSettings,
17+
BaseSearchParams,
1818
BaseSearchParamsWithoutQuery,
1919
BaseSearchResponse,
2020
BooleanString,
@@ -43,8 +43,8 @@ import type {
4343
HighlightResultOption,
4444
IgnorePlurals,
4545
IndexSettingsAsSearchParams,
46-
MatchLevel,
4746
MatchedGeoLocation,
47+
MatchLevel,
4848
Mode,
4949
NumericFilters,
5050
OptionalFilters,
@@ -56,14 +56,14 @@ import type {
5656
QueryType,
5757
Range,
5858
RankingInfo,
59-
ReRankingApplyFilter,
6059
Redirect,
61-
RedirectRuleIndexMetadata,
6260
RedirectRuleIndexData,
61+
RedirectRuleIndexMetadata,
6362
RedirectURL,
6463
RemoveStopWords,
6564
RemoveWordsIfNoResults,
6665
RenderingContent,
66+
ReRankingApplyFilter,
6767
SearchPagination,
6868
SearchParams,
6969
SearchParamsObject,
@@ -75,6 +75,7 @@ import type {
7575
SupportedLanguage,
7676
TagFilters,
7777
TaskStatus,
78+
TimeRange,
7879
TypoTolerance,
7980
TypoToleranceEnum,
8081
Value,
@@ -91,16 +92,19 @@ export * from '@algolia/client-analytics';
9192
export * from '@algolia/client-abtesting';
9293

9394
export {
95+
AbTestingRegion,
9496
AdvancedSyntaxFeatures,
9597
AlternativesAsExact,
98+
AnalyticsRegion,
9699
Anchoring,
100+
apiClientVersion,
97101
AroundPrecision,
98102
AroundRadius,
99103
AroundRadiusAll,
100104
AutomaticFacetFilter,
101105
AutomaticFacetFilters,
102-
BaseSearchParams,
103106
BaseIndexSettings,
107+
BaseSearchParams,
104108
BaseSearchParamsWithoutQuery,
105109
BaseSearchResponse,
106110
BooleanString,
@@ -129,8 +133,8 @@ export {
129133
HighlightResultOption,
130134
IgnorePlurals,
131135
IndexSettingsAsSearchParams,
132-
MatchLevel,
133136
MatchedGeoLocation,
137+
MatchLevel,
134138
Mode,
135139
NumericFilters,
136140
OptionalFilters,
@@ -142,32 +146,30 @@ export {
142146
QueryType,
143147
Range,
144148
RankingInfo,
145-
ReRankingApplyFilter,
146149
Redirect,
147-
RedirectRuleIndexMetadata,
148150
RedirectRuleIndexData,
151+
RedirectRuleIndexMetadata,
149152
RedirectURL,
153+
Region,
150154
RemoveStopWords,
151155
RemoveWordsIfNoResults,
152156
RenderingContent,
157+
ReRankingApplyFilter,
158+
SearchPagination,
153159
SearchParams,
154160
SearchParamsObject,
155161
SearchParamsQuery,
156162
SemanticSearch,
157-
SearchPagination,
158163
SnippetResult,
159164
SnippetResultOption,
160165
SortRemainingBy,
161166
SupportedLanguage,
162167
TagFilters,
163168
TaskStatus,
169+
TimeRange,
164170
TypoTolerance,
165171
TypoToleranceEnum,
166172
Value,
167-
AnalyticsRegion,
168-
AbTestingRegion,
169-
Region,
170-
apiClientVersion,
171173
};
172174

173175
/**
@@ -190,4 +192,4 @@ export type InitClientRegion<TRegion> = Partial<{
190192
* Available regions of the initialized client.
191193
*/
192194
region: TRegion;
193-
}>;
195+
}>;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[
2+
{
3+
"testName": "batch recommend rules",
4+
"parameters": {
5+
"indexName": "indexName",
6+
"model": "related-products"
7+
},
8+
"request": {
9+
"path": "/1/indexes/indexName/related-products/recommend/rules/batch",
10+
"method": "POST",
11+
"body": {}
12+
}
13+
}
14+
]

0 commit comments

Comments
 (0)