Skip to content
Open
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
18 changes: 18 additions & 0 deletions specs/composition/common/params/Composition.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,21 @@ enableABTest:
default: true
x-categories:
- Advanced

# #######################
# ### Category SortBy ###
# #######################

sortBy:
type: string
description: |
Indicates which sorting strategy to apply for the request.
The value must match one of the labels defined in the "sortingStrategy" mapping. For example, "Price (asc)", see Upsert Composition.
At runtime, this label is used to look up the corresponding index or replica configured in "sortingStrategy", and the query is executed using that index instead of main's.

In addition to "sortingStrategy", this parameter is also used to apply a matching Composition Rule that contains a condition defined to trigger on "sortBy", see Composition Rules.

If no value is provided or an invalid value, no sorting strategy is applied.
default: ''
example:
'Price (asc)'
21 changes: 20 additions & 1 deletion specs/composition/common/schemas/components/Composition.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,26 @@ composition:
example: 'my lovely crafted composition that is used for X purpose'
behavior:
$ref: './CompositionBehavior.yml#/compositionBehavior'
sortingStrategy:
$ref: '#/sortingStrategy'

required:
- objectID
- behavior
- name
- name

sortingStrategy:
type: object
description: |
A mapping of sorting labels to the indices (or replicas) that implement those sorting rules. The sorting indices MUST be related to the associated main targeted index in the composition.
Each key is the label your frontend sends at runtime (for example, "Price (asc)"), and each value is the name of the index that should be queried when that label is selected.

When a request includes a "sortBy" parameter, the platform looks up the corresponding index in this mapping and uses it to execute the query. The main targeted index is replaced
with the sorting strategy index it is mapped to.

Up to 20 sorting strategies can be defined.
additionalProperties:
type: string
example:
'Price (asc)': 'products-low-to-high'
'Price (desc)': 'products-high-to-low'
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@ params:
$ref: '../../params/Search.yml#/page'
query:
$ref: '../../params/Search.yml#/query'
relevancyStrictness:
$ref: '../../params/Search.yml#/relevancyStrictness'
queryLanguages:
$ref: '../../params/Search.yml#/queryLanguages'
relevancyStrictness:
$ref: '../../params/Search.yml#/relevancyStrictness'
ruleContexts:
$ref: '../../params/Composition.yml#/ruleContexts'
sortBy:
$ref: '../../params/Composition.yml#/sortBy'
userToken:
$ref: '../../params/Search.yml#/userToken'
48 changes: 48 additions & 0 deletions tests/CTS/requests/composition/putComposition.json
Original file line number Diff line number Diff line change
Expand Up @@ -361,5 +361,53 @@
}
}
}
},

{
"parameters": {
"compositionID": "my-compo",
"composition": {
"objectID": "my-compo",
"name": "my composition",
"sortingStrategy": {
"Price-asc": "products-low-to-high",
"Price-desc": "products-high-to-low"
},
"behavior": {
"injection": {
"main": {
"source": {
"search": {
"index": "products"
}
}
}
}
}
}
},
"request": {
"path": "/1/compositions/my-compo",
"method": "PUT",
"body": {
"objectID": "my-compo",
"name": "my composition",
"sortingStrategy": {
"Price-asc": "products-low-to-high",
"Price-desc": "products-high-to-low"
},
"behavior": {
"injection": {
"main": {
"source": {
"search": {
"index": "products"
}
}
}
}
}
}
}
}
]
22 changes: 22 additions & 0 deletions tests/CTS/requests/composition/search.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,27 @@
}
}
}
},

{
"parameters": {
"compositionID": "foo",
"requestBody": {
"params": {
"query": "batman",
"sortBy": "Price (asc)"
}
}
},
"request": {
"path": "/1/compositions/foo/run",
"method": "POST",
"body": {
"params": {
"query": "batman",
"sortBy": "Price (asc)"
}
}
}
}
]