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

Commit 0117120

Browse files
irevoiregmourier
andauthored
CSV Content-Type — Add support for the boolean type in CSV (#228)
* add support for the boolean type in csv * fix a typo * Update text/0028-indexing-csv.md --------- Co-authored-by: Guillaume Mourier <[email protected]>
1 parent c7b21ee commit 0117120

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

text/0028-indexing-csv.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ While there's [RFC 4180](https://tools.ietf.org/html/rfc4180) as a try to add a
3838

3939
- CSV data format needs to contain a first line representing the list of attributes with the optionally chosen type separated from the attribute name by `:` character. The type is case insensitive.
4040

41-
> An attribute can be specificed with two types: `string` or `number`. A missing type will be interpreted as a `string` by default.
41+
> An attribute can be specificed with three types: `string`, `boolean` or `number`. A missing type will be interpreted as a `string` by default.
4242
>
43-
> Valid headline example: "id:number","title:string","author","price:number"
43+
> Valid headline example: "id:number","title:string","author","price:number","cute:boolean"
4444
4545
- The following CSV lines will represent a document for Meilisearch.
4646
- A `,` character must separate each cell.
@@ -57,14 +57,15 @@ While there's [RFC 4180](https://tools.ietf.org/html/rfc4180) as a try to add a
5757
##### `null` value
5858

5959
- If a field is of type `string`, then an empty cell is considered as a `null` value (e.g. `,,`), anything else is turned into a string value (e.g. `, ,` is a single whitespace string)
60-
- If a field is of type `number`, when the trimmed field is empty, it's considered as a `null` value (e.g. `,,` `, ,`); otherwise Meilisearch try to parse the number.
60+
- If a field is of type `number`, when the trimmed field is empty, it's considered as a `null` value (e.g. `,,` `, ,`); otherwise, Meilisearch tries to parse the number.
61+
- If a field is of type `boolean`, when the trimmed field is empty, it's considered as a `null` value (e.g. `,,` `, ,`); otherwise, Meilisearch tries to parse the boolean as either `true` or `false`.
6162

6263
##### Example with a comma inside a cell
6364

6465
Given the CSV payload
6566
```
66-
"id:number","label","price:number","colors","description"
67-
"1","t-shirt","4.99","red","Thus, you will rock at summer time."
67+
"id:number","label","price:number","colors","description","contains_a_dog_picture:boolean"
68+
"1","t-shirt","4.99","red","Thus, you will rock at summer time.","false"
6869
```
6970
the search result should be displayed as
7071
```json
@@ -75,7 +76,8 @@ the search result should be displayed as
7576
"label": "t-shirt",
7677
"price": 4.99,
7778
"colors": "red",
78-
"description": "Hey, you will rock at summer time."
79+
"description": "Thus, you will rock at summer time.",
80+
"contains_a_dog_picture": false
7981
}
8082
],
8183
...
@@ -172,6 +174,7 @@ curl \
172174
- 🔴 Sending an invalid CSV format will lead to a 400 bad_request - **malformed_payload** error code.
173175
- 🔴 Sending a CSV header that does not conform to the specification will lead to a 400 bad_request - **malformed_payload** error code.
174176
- 🔴 Sending an invalid csv delimiter: not exactly one ASCII char. This will lead to a 400 bad_request - **invalid_document_csv_delimiter** error code.
177+
- 🔴 Sending a CSV cell with the type `number` or `boolean` that can't be parsed will lead to a 400 bad_request - **malformed_payload** error code.
175178

176179
##### Errors Definition
177180

0 commit comments

Comments
 (0)