Skip to content

Commit 9f4d3c2

Browse files
committed
feat(specs): add recommend batch rules endpoint
1 parent ef684de commit 9f4d3c2

File tree

5 files changed

+65
-16
lines changed

5 files changed

+65
-16
lines changed

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

specs/recommend/common/schemas/RecommendRule.yml

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

specs/search/paths/rules/common/schemas.yml

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ rule:
3030
type: array
3131
description: Time periods when the rule is active.
3232
items:
33-
$ref: '#/timeRange'
33+
$ref: '../../../../common/schemas/Rule.yml#/timeRange'
3434
required:
3535
- objectID
3636

@@ -289,20 +289,6 @@ automaticFacetFilter:
289289
required:
290290
- facet
291291

292-
timeRange:
293-
type: object
294-
additionalProperties: false
295-
properties:
296-
from:
297-
type: integer
298-
description: When the rule should start to be active, in Unix epoch time.
299-
until:
300-
type: integer
301-
description: When the rule should stop to be active, in Unix epoch time.
302-
required:
303-
- from
304-
- until
305-
306292
updatedRuleResponse:
307293
type: object
308294
additionalProperties: false

0 commit comments

Comments
 (0)