diff --git a/specs/composition/common/params/Composition.yml b/specs/composition/common/params/Composition.yml index 9ee7fee32b4..06f2b0ab491 100644 --- a/specs/composition/common/params/Composition.yml +++ b/specs/composition/common/params/Composition.yml @@ -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)' diff --git a/specs/composition/common/schemas/components/Composition.yml b/specs/composition/common/schemas/components/Composition.yml index 8b0814c5934..2e48394b086 100644 --- a/specs/composition/common/schemas/components/Composition.yml +++ b/specs/composition/common/schemas/components/Composition.yml @@ -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 \ No newline at end of file + - 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' diff --git a/specs/composition/common/schemas/requestBodies/RunParams.yml b/specs/composition/common/schemas/requestBodies/RunParams.yml index 42e01f56730..de773917171 100644 --- a/specs/composition/common/schemas/requestBodies/RunParams.yml +++ b/specs/composition/common/schemas/requestBodies/RunParams.yml @@ -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' diff --git a/tests/CTS/requests/composition/putComposition.json b/tests/CTS/requests/composition/putComposition.json index 056f6eb1f55..d691cfe571e 100644 --- a/tests/CTS/requests/composition/putComposition.json +++ b/tests/CTS/requests/composition/putComposition.json @@ -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" + } + } + } + } + } + } + } } ] diff --git a/tests/CTS/requests/composition/search.json b/tests/CTS/requests/composition/search.json index a74b47f4067..d5b43d0cf74 100644 --- a/tests/CTS/requests/composition/search.json +++ b/tests/CTS/requests/composition/search.json @@ -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)" + } + } + } } ]