From 748a1d0655b116263763484d3d0a1e8ac5c511b3 Mon Sep 17 00:00:00 2001 From: "d.neustadt" Date: Fri, 22 Apr 2022 13:01:16 +0200 Subject: [PATCH 1/5] added docs for count sorting --- .../integrations-api/general-concepts/search-criteria.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/guides/integrations-api/general-concepts/search-criteria.md b/guides/integrations-api/general-concepts/search-criteria.md index b22e417bc..6809a2815 100644 --- a/guides/integrations-api/general-concepts/search-criteria.md +++ b/guides/integrations-api/general-concepts/search-criteria.md @@ -318,14 +318,17 @@ The `sort` parameter allows to control the sorting of the result. Several sorts * The `field` parameter defines which field is to be used for sorting. * The `order` parameter defines the sort direction. * The parameter `naturalSorting` allows to use a [Natural Sorting Algorithm](https://en.wikipedia.org/wiki/Natural_sort_order) +* The parameter `type` allows to use divergent sorting behavior. Valid values are: + * `count`: Sort by the count of associations via the given field. SQL representation: `COUNT({field}) {order}` ```javascript { "limit": 5, "sort": [ { "field": "name", "order": "ASC", "naturalSorting": true }, - { "field": "active", "order": "DESC" } - ] + { "field": "active", "order": "DESC" }, + { "field": "products.id", "order": "DESC", "type": "count" } + ] } ``` From 5b76c372d39697c984641ca73e2e6a969f04c87d Mon Sep 17 00:00:00 2001 From: "d.neustadt" Date: Tue, 3 May 2022 14:15:14 +0200 Subject: [PATCH 2/5] added examples of count sorting with aggregation --- .../general-concepts/search-criteria.md | 63 ++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/guides/integrations-api/general-concepts/search-criteria.md b/guides/integrations-api/general-concepts/search-criteria.md index 6809a2815..0fbc83761 100644 --- a/guides/integrations-api/general-concepts/search-criteria.md +++ b/guides/integrations-api/general-concepts/search-criteria.md @@ -319,7 +319,7 @@ The `sort` parameter allows to control the sorting of the result. Several sorts * The `order` parameter defines the sort direction. * The parameter `naturalSorting` allows to use a [Natural Sorting Algorithm](https://en.wikipedia.org/wiki/Natural_sort_order) * The parameter `type` allows to use divergent sorting behavior. Valid values are: - * `count`: Sort by the count of associations via the given field. SQL representation: `COUNT({field}) {order}` + * `count`: Sort by the count of associations via the given field. SQL representation: `ORDER BY COUNT({field}) {order}` ```javascript { @@ -332,6 +332,67 @@ The `sort` parameter allows to control the sorting of the result. Several sorts } ``` +### `count` sorting behavior + +For demonstration purposes see the following request payload that additionally includes a `count` aggregation. + +```json +{ + "limit": 3, + "includes": { + "product": ["id"] + }, + "sort": [ + { "field": "categories.id", "order": "DESC", "type": "count" } + ], + "aggregations": [ + { + "name": "product-id", + "type": "terms", + "field": "id", + "limit": 3, + "sort": { "field": "_count", "order": "DESC" }, + "aggregation": { + "name": "category-count", + "type": "count", + "field": "product.categories.id" + } + } + ] +} +``` + +In the response the order of the `product` elements is now equal to the order of the aggregated buckets: + +```json +{ + "total": 3, + "aggregations": { + "product-id": { + "buckets": [ + { + "key": "f977f6a845a54b0381cbaf322f53b63e", + "count": 5 + }, + { + "key": "8d0ee52433df44b78a6f7827180049d9", + "count": 4 + }, + { + "key": "003a9df163474b28bc8a000243549547", + "count": 3 + } + ] + } + }, + "elements": [ + { "id": "f977f6a845a54b0381cbaf322f53b63e" }, + { "id": "8d0ee52433df44b78a6f7827180049d9" }, + { "id": "003a9df163474b28bc8a000243549547" } + ] +} +``` + ## `aggregations` With the `aggregations` parameter, meta data can be determined for a search query. There are different types of aggregations which are listed in the reference documentation. A simple example is the determination of the average price from a product search query. From c57345e23605032eb166d561b82f2327adc23fd7 Mon Sep 17 00:00:00 2001 From: "d.neustadt" Date: Tue, 3 May 2022 14:17:04 +0200 Subject: [PATCH 3/5] use javascript as language for code blocks --- guides/integrations-api/general-concepts/search-criteria.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/guides/integrations-api/general-concepts/search-criteria.md b/guides/integrations-api/general-concepts/search-criteria.md index 0fbc83761..6f2c01781 100644 --- a/guides/integrations-api/general-concepts/search-criteria.md +++ b/guides/integrations-api/general-concepts/search-criteria.md @@ -336,7 +336,7 @@ The `sort` parameter allows to control the sorting of the result. Several sorts For demonstration purposes see the following request payload that additionally includes a `count` aggregation. -```json +```javascript { "limit": 3, "includes": { @@ -364,7 +364,7 @@ For demonstration purposes see the following request payload that additionally i In the response the order of the `product` elements is now equal to the order of the aggregated buckets: -```json +```javascript { "total": 3, "aggregations": { From ce109fc9f3c727b26dcf37983b3ad114d8ce53e5 Mon Sep 17 00:00:00 2001 From: "d.neustadt" Date: Mon, 20 Jun 2022 09:00:20 +0200 Subject: [PATCH 4/5] added version info --- guides/integrations-api/general-concepts/search-criteria.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/guides/integrations-api/general-concepts/search-criteria.md b/guides/integrations-api/general-concepts/search-criteria.md index 6f2c01781..a46e128dc 100644 --- a/guides/integrations-api/general-concepts/search-criteria.md +++ b/guides/integrations-api/general-concepts/search-criteria.md @@ -336,6 +336,10 @@ The `sort` parameter allows to control the sorting of the result. Several sorts For demonstration purposes see the following request payload that additionally includes a `count` aggregation. +{% hint style="info" %} +This `count` type was introduced with Shopware 6.4.12.0 and is not available in prior versions. +{% endhint %} + ```javascript { "limit": 3, From 8433e115db12bfaad8b06d51dd0226d2db744e9d Mon Sep 17 00:00:00 2001 From: "d.neustadt" Date: Thu, 23 Jun 2022 07:02:42 +0200 Subject: [PATCH 5/5] remove trailing space --- guides/integrations-api/general-concepts/search-criteria.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/integrations-api/general-concepts/search-criteria.md b/guides/integrations-api/general-concepts/search-criteria.md index a46e128dc..7d284dbec 100644 --- a/guides/integrations-api/general-concepts/search-criteria.md +++ b/guides/integrations-api/general-concepts/search-criteria.md @@ -366,7 +366,7 @@ This `count` type was introduced with Shopware 6.4.12.0 and is not available in } ``` -In the response the order of the `product` elements is now equal to the order of the aggregated buckets: +In the response the order of the `product` elements is now equal to the order of the aggregated buckets: ```javascript {