Skip to content
This repository was archived by the owner on Mar 21, 2024. It is now read-only.

Commit d82e976

Browse files
gmourierKerollmops
andauthored
Faceting Setting API - sortFacetValuesBy (#247)
* init spec * Add property description and open-api.yaml * Removes future possibility * Update the telemetry * Update the error of the sortFacetValuesBy setting --------- Co-authored-by: Clément Renault <[email protected]>
1 parent 8827a3a commit d82e976

File tree

3 files changed

+52
-6
lines changed

3 files changed

+52
-6
lines changed

open-api.yaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,12 @@ components:
606606
type: integer
607607
default: 100
608608
nullable: false
609+
sortFacetValuesBy:
610+
description: Defines how facet values are sorted. By default, all facets (`*`) are sorted by name, alphanumerically in ascending order (`alpha`). `count` sorts facet values by the number of documents containing a facet value in descending order.
611+
type: object
612+
example:
613+
"*": 'alpha'
614+
"genres": 'count'
609615
filterableAttributes:
610616
type: array
611617
description: |
@@ -2401,6 +2407,8 @@ paths:
24012407
maxTotalHits: 1000
24022408
faceting:
24032409
maxValuesPerFacet: 100
2410+
sortFacetValuesBy:
2411+
"*": "alpha"
24042412
'401':
24052413
$ref: '#/components/responses/401'
24062414
'404':
@@ -2500,6 +2508,8 @@ paths:
25002508
maxTotalHits: 1000
25012509
faceting:
25022510
maxValuesPerFacet: 100
2511+
sortFacetValuesBy:
2512+
"*": "alpha"
25032513
responses:
25042514
'202':
25052515
description: Accepted
@@ -3077,7 +3087,7 @@ paths:
30773087
operationId: indexes.settings.faceting.update
30783088
summary: Update faceting settings
30793089
description: |
3080-
Update the typo tolerance faceting of an index.
3090+
Update the faceting settings of an index.
30813091
30823092
> info
30833093
> If the provided index does not exist, it will be created.

text/0034-telemetry-policies.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ The collected data is sent to [Segment](https://segment.com/). Segment is a plat
158158
| `typo_tolerance.min_word_size_for_typos.two_typos`| The defined value for `minWordSizeForTypos.twoTypos` property | `9` | `Settings Updated`, `TypoTolerance Updated` |
159159
| `pagination.max_total_hits` | The defined value for `pagination.maxTotalHits` property | `1000` | `Settings Updated`, `Pagination Updated` |
160160
| `faceting.max_values_per_facet` | The defined value for `faceting.maxValuesPerFacet` property | `100` | `Settings Updated`, `Faceting Updated` |
161+
| `faceting.sort_facet_values_by_star_count` | Whether the user set all fields to be sort by count | `true` | `Settings Updated`, `Faceting Updated` |
162+
| `faceting.sort_facet_values_by_total` | The number of different values that were set | `10` | `Settings Updated`, `Faceting Updated` |
161163
| `distinct_attribute.set` | `true` if a field name is specified as a distrinct attribute, otherwise `false`. | `false` | `Settings Updated`, `DistinctAttribute Updated` |
162164
| `displayed_attributes.total` | Number of displayed attributes. | `3` | `SettingUpdated`, `DisplayedAttributes Updated` |
163165
| `displayed_attributes.with_wildcard` | `true` if `*` is specified as a displayed attribute, otherwise `false`. | `false` | `SettingUpdated`, `DisplayedAttributes Updated` |
@@ -467,6 +469,8 @@ This property allows us to gather essential information to better understand on
467469
| typo_tolerance.min_word_size_for_typos.two_typos | The defined value for `minWordSizeForTypos.twoTypos` property. | `9` |
468470
| pagination.max_total_hits | The defined value for `pagination.maxTotalHits` property | `1000` |
469471
| faceting.max_values_per_facet | The defined value for `faceting.maxValuesPerFacet` property | `100` |
472+
| faceting.sort_facet_values_by_star_count | Whether the user set all fields to be sort by count | `true` |
473+
| faceting.sort_facet_values_by_total | The number of different values that were set | `10` |
470474
| distinct_attribute.set | `true` if a field name is specified, otherwise `false`. | `false` |
471475
| displayed_attributes.total | Number of displayed attributes. | `3` |
472476
| displayed_attributes.with_wildcard | `true` if `*` is specified as a displayed attribute, otherwise `false`. | `false` |
@@ -540,6 +544,8 @@ This property allows us to gather essential information to better understand on
540544
|---------------|-------------|---------|
541545
| user_agent | Represents the user-agent encountered on this call. | `["Meilisearch Ruby (v2.1)", "Ruby (3.0)"]` |
542546
| faceting.max_values_per_facet | The defined value for `maxValuesPerFacet` property | `100` |
547+
| faceting.sort_facet_values_by_star_count | Whether the user set all fields to be sort by count | `true` |
548+
| faceting.sort_facet_values_by_total | The number of different values that were set | `10` |
543549

544550
## `DistinctAttribute Updated`
545551

text/157-faceting-setting-api.md

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ This settings will host the parameters to configure the faceting behavior for an
1717
| Field | Type | Required |
1818
|--------------------------------------------------|-----------------|----------|
1919
| [maxValuesPerFacet](#311-maxValuesPerFacet) | Integer | False |
20+
| [sortFacetValuesBy](#312-sortFacetValuesBy) | Object | False |
2021

2122
#### 3.1.1. `maxValuesPerFacet`
2223

@@ -34,6 +35,33 @@ Increasing this value can degrade performance as well as expose the data of an i
3435

3536
The facets that are returned are sorted in ascending lexicographical order.
3637

38+
#### 3.1.2 `sortFacetValuesBy`
39+
40+
- Type: Object
41+
- Required: False
42+
- Default:
43+
44+
```json
45+
{
46+
"*": "alpha"
47+
}
48+
```
49+
50+
Defines how facet values are sorted. By default, all facets (`*`) are sorted by name, alphanumerically in ascending order (`alpha`).
51+
52+
It is possible to sort them by the number of documents containing a facet value in descending order using `count`.
53+
54+
It is possible to specify a particular order for a facet.
55+
56+
```json
57+
{
58+
"*": "alpha",
59+
"genre": "count"
60+
}
61+
```
62+
63+
In this example, values from facets other than `genres` will be displayed sorted by their name in ascending alphanumeric order, while values from the `genres` facet will be sorted in descending order by the count of the number of documents containing each value.
64+
3765
## 3.2. API Endpoints Definition
3866

3967
### 3.2.1. Global Settings API Endpoints Definition
@@ -54,7 +82,10 @@ Allow fetching the current definition of the faceting setting for an index.
5482

5583
```json
5684
{
57-
"maxValuesPerFacet": 100
85+
"maxValuesPerFacet": 100,
86+
"sortFacetValuesBy": {
87+
"*": "alpha"
88+
}
5889
}
5990
```
6091

@@ -103,8 +134,8 @@ See [Summarized `task` Object for `202 Accepted`](0060-tasks-api.md#summarized-t
103134
- 🔴 Sending an empty payload returns a [missing_payload](0061-error-format-and-definitions.md#missing_payload) error.
104135
- 🔴 Sending an invalid JSON payload returns a [malformed_payload](0061-error-format-and-definitions.md#malformed_payload) error.
105136
- 🔴 Sending an invalid index uid format for the `:index_uid` path parameter returns an [invalid_index_uid](0061-error-format-and-definitions.md#invalid_index_uid) error.
106-
- 🔴 Sending a value different from `null` or with a different type than `Integer` for the `maxValuesPerFacet` field returns
107-
an [invalid_settings_faceting](0061-error-format-and-definitions.md#invalid_settings_faceting) error.
137+
- 🔴 Sending a value different from `null` or with a different type than `Integer` for the `maxValuesPerFacet` field returns an [invalid_settings_faceting](0061-error-format-and-definitions.md#invalid_settings_faceting) error.
138+
- 🔴 Sending a value different from `null` or an object with value with a different type than `"alpha"` or `"count"` for the `sortFacetValuesBy` field returns an [invalid_settings_faceting](0061-error-format-and-definitions.md#invalid_settings_faceting) error.
108139

109140
###### 3.2.2.2.2.1. Async Errors
110141

@@ -149,5 +180,4 @@ The auth layer can return the following errors if Meilisearch is secured (a mast
149180
n/a
150181

151182
## 3. Future Possibilities
152-
153-
- Introduces a field to define the sorting of facets. e.g `sort` by `count`/`alphanumeric`
183+
n/a

0 commit comments

Comments
 (0)