Skip to content

feat(specs): add recommend batch rules endpoint #3782

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public class AlgoliaSwiftGenerator extends Swift5ClientCodegen {
"supportedlanguage",
"tagfilters",
"taskstatus",
"timerange",
"typotolerance",
"typotoleranceenum",
"value"
Expand Down
12 changes: 9 additions & 3 deletions playground/javascript/node/recommend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const searchQuery = process.env.SEARCH_QUERY || 'test_query';
// Init client with appId and apiKey
const client = recommendClient(appId, apiKey);

async function testRecommend() {
async function testGetRecommendations() {
try {
const res = await client.getRecommendations({
requests: [
Expand All @@ -23,14 +23,20 @@ async function testRecommend() {
],
});

console.log(`[OK]`, res);
console.log('[OK] GetRecommendations', res);
} catch (e) {
if (e instanceof ApiError) {
return console.log(`[${e.status}] ${e.message}`, e.stackTrace);
}

console.log('[ERROR]', e);
console.log('[ERROR] GetRecommendations', e);
}
}



async function testRecommend() {
await testGetRecommendations();
}

testRecommend();
14 changes: 14 additions & 0 deletions specs/common/schemas/Rule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,17 @@ context:
For example, if `context: mobile`, the rule is only triggered when the search request has a matching `ruleContexts: mobile`.
A rule context must only contain alphanumeric characters.
example: mobile

timeRange:
type: object
additionalProperties: false
properties:
from:
type: integer
description: When the rule should start to be active, in Unix epoch time.
until:
type: integer
description: When the rule should stop to be active, in Unix epoch time.
required:
- from
- until
5 changes: 5 additions & 0 deletions specs/recommend/common/responses/RecommendUpdatedAt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
description: OK
content:
application/json:
schema:
$ref: './common.yml#/recommendUpdatedAtResponse'
26 changes: 26 additions & 0 deletions specs/recommend/common/responses/common.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
taskID:
type: integer
format: int64
example: 1514562690001
description: |
Unique identifier of a task.

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`.

updatedAt:
type: string
example: 2023-07-04T12:49:15Z
description: Date and time when the object was updated, in RFC 3339 format.

recommendUpdatedAtResponse:
type: object
description: Response, taskID, and update timestamp.
additionalProperties: false
required:
- taskID
- updatedAt
properties:
taskID:
$ref: '#/taskID'
updatedAt:
$ref: '#/updatedAt'
9 changes: 7 additions & 2 deletions specs/recommend/common/schemas/RecommendRule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ RecommendRule:
description: Rule metadata.
properties:
lastUpdate:
$ref: '../../../common/responses/common.yml#/updatedAt'
$ref: '../responses/common.yml#/updatedAt'
objectID:
$ref: '../../../common/parameters.yml#/ruleID'
condition:
Expand All @@ -19,11 +19,16 @@ RecommendRule:
description:
type: string
description: Description of the rule's purpose. This can be helpful for display in the Algolia dashboard.
example: 'Display a promotional banner'
example: 'Boost on-sale items'
enabled:
type: boolean
default: true
description: Indicates whether to enable the rule. If it isn't enabled, it isn't applied at query time.
validity:
type: array
description: Time periods when the rule is active.
items:
$ref: '../../../common/schemas/Rule.yml#/timeRange'

Condition:
type: object
Expand Down
38 changes: 38 additions & 0 deletions specs/recommend/paths/batchRecommendRules.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
post:
tags:
- rules
operationId: batchRecommendRules
x-acl:
- editSettings
summary: Create or update a batch of Recommend Rules
description: |
Create or update a batch of Recommend Rules

Each Recommend Rule is created or updated, depending on whether a Recommend Rule with the same `objectID` already exists.
You may also specify `true` for `clearExistingRules`, in which case the batch will atomically replace all the existing Recommend Rules.

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:
- Conditions `pattern` and `anchoring` are unavailable.
- Condition `filters` triggers if the source item matches the specified filters.
- Condition `filters` accepts numeric filters.
- Consequence `params` only covers filtering parameters.
- Consequence `automaticFacetFilters` doesn't require a facet value placeholder (it tries to match the data source item's attributes instead).
parameters:
- $ref: '../../common/parameters.yml#/IndexName'
- $ref: '../common/parameters.yml#/Models'
requestBody:
content:
application/json:
schema:
title: rules
type: array
description: Recommend rules.
additionalProperties: false
items:
$ref: '../common/schemas/RecommendRule.yml#/RecommendRule'

responses:
'200':
$ref: '../common/responses/RecommendUpdatedAt.yml'
'400':
$ref: '../../common/responses/BadRequest.yml'
3 changes: 3 additions & 0 deletions specs/recommend/spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ paths:

/1/indexes/{indexName}/{model}/recommend/rules/search:
$ref: 'paths/searchRecommendRules.yml'

/1/indexes/{indexName}/{model}/recommend/rules/batch:
$ref: 'paths/batchRecommendRules.yml'

# ###############
# ### Helpers ###
Expand Down
30 changes: 16 additions & 14 deletions templates/javascript/clients/algoliasearch/builds/models.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import type {
AroundRadiusAll,
AutomaticFacetFilter,
AutomaticFacetFilters,
BaseSearchParams,
BaseIndexSettings,
BaseSearchParams,
BaseSearchParamsWithoutQuery,
BaseSearchResponse,
BooleanString,
Expand Down Expand Up @@ -43,8 +43,8 @@ import type {
HighlightResultOption,
IgnorePlurals,
IndexSettingsAsSearchParams,
MatchLevel,
MatchedGeoLocation,
MatchLevel,
Mode,
NumericFilters,
OptionalFilters,
Expand All @@ -56,14 +56,14 @@ import type {
QueryType,
Range,
RankingInfo,
ReRankingApplyFilter,
Redirect,
RedirectRuleIndexMetadata,
RedirectRuleIndexData,
RedirectRuleIndexMetadata,
RedirectURL,
RemoveStopWords,
RemoveWordsIfNoResults,
RenderingContent,
ReRankingApplyFilter,
SearchPagination,
SearchParams,
SearchParamsObject,
Expand All @@ -75,6 +75,7 @@ import type {
SupportedLanguage,
TagFilters,
TaskStatus,
TimeRange,
TypoTolerance,
TypoToleranceEnum,
Value,
Expand All @@ -91,16 +92,19 @@ export * from '@algolia/client-analytics';
export * from '@algolia/client-abtesting';

export {
AbTestingRegion,
AdvancedSyntaxFeatures,
AlternativesAsExact,
AnalyticsRegion,
Anchoring,
apiClientVersion,
AroundPrecision,
AroundRadius,
AroundRadiusAll,
AutomaticFacetFilter,
AutomaticFacetFilters,
BaseSearchParams,
BaseIndexSettings,
BaseSearchParams,
BaseSearchParamsWithoutQuery,
BaseSearchResponse,
BooleanString,
Expand Down Expand Up @@ -129,8 +133,8 @@ export {
HighlightResultOption,
IgnorePlurals,
IndexSettingsAsSearchParams,
MatchLevel,
MatchedGeoLocation,
MatchLevel,
Mode,
NumericFilters,
OptionalFilters,
Expand All @@ -142,32 +146,30 @@ export {
QueryType,
Range,
RankingInfo,
ReRankingApplyFilter,
Redirect,
RedirectRuleIndexMetadata,
RedirectRuleIndexData,
RedirectRuleIndexMetadata,
RedirectURL,
Region,
RemoveStopWords,
RemoveWordsIfNoResults,
RenderingContent,
ReRankingApplyFilter,
SearchPagination,
SearchParams,
SearchParamsObject,
SearchParamsQuery,
SemanticSearch,
SearchPagination,
SnippetResult,
SnippetResultOption,
SortRemainingBy,
SupportedLanguage,
TagFilters,
TaskStatus,
TimeRange,
TypoTolerance,
TypoToleranceEnum,
Value,
AnalyticsRegion,
AbTestingRegion,
Region,
apiClientVersion,
};

/**
Expand All @@ -190,4 +192,4 @@ export type InitClientRegion<TRegion> = Partial<{
* Available regions of the initialized client.
*/
region: TRegion;
}>;
}>;
14 changes: 14 additions & 0 deletions tests/CTS/requests/recommend/batchRecommendRules.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"testName": "batch recommend rules",
"parameters": {
"indexName": "indexName",
"model": "related-products"
},
"request": {
"path": "/1/indexes/indexName/related-products/recommend/rules/batch",
"method": "POST",
"body": {}
}
}
]
Loading