Skip to content

Commit 7ff91cf

Browse files
Update code samples [skip ci]
1 parent 3844bb6 commit 7ff91cf

File tree

215 files changed

+1821
-1811
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

215 files changed

+1821
-1811
lines changed

snippets/samples/code_samples_add_movies_json_1.mdx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
<CodeGroup>
22

3-
```bash cURL
4-
curl \
5-
-X POST 'MEILISEARCH_URL/indexes/movies/documents'\
6-
-H 'Content-Type: application/json' \
7-
--data-binary @movies.json
8-
```
9-
103
```javascript JS
114
const movies = require('./movies.json')
125
client.index('movies').addDocuments(movies).then((res) => console.log(res))
@@ -103,6 +96,20 @@ fn main() { block_on(async move {
10396
})}
10497
```
10598

99+
```swift Swift
100+
let path = Bundle.main.url(forResource: "movies", withExtension: "json")!
101+
let documents: Data = try Data(contentsOf: path)
102+
103+
client.index("movies").addDocuments(documents: documents) { (result) in
104+
switch result {
105+
case .success(let task):
106+
print(task)
107+
case .failure(let error):
108+
print(error)
109+
}
110+
}
111+
```
112+
106113
```dart Dart
107114
// import 'dart:io';
108115
// import 'dart:convert';

snippets/samples/code_samples_add_or_replace_documents_1.mdx

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
11
<CodeGroup>
22

3-
```bash cURL
4-
curl \
5-
-X POST 'MEILISEARCH_URL/indexes/movies/documents' \
6-
-H 'Content-Type: application/json' \
7-
--data-binary '[
8-
{
9-
"id": 287947,
10-
"title": "Shazam",
11-
"poster": "https://image.tmdb.org/t/p/w1280/xnopI5Xtky18MPhK40cZAGAOVeV.jpg",
12-
"overview": "A boy is given the ability to become an adult superhero in times of need with a single magic word.",
13-
"release_date": "2019-03-23"
14-
}
15-
]'
16-
```
17-
183
```javascript JS
194
client.index('movies').addDocuments([{
205
id: 287947,
@@ -114,6 +99,30 @@ let task: TaskInfo = client
11499
.unwrap();
115100
```
116101

102+
```swift Swift
103+
let documentJsonString = """
104+
[
105+
{
106+
"reference_number": 287947,
107+
"title": "Shazam",
108+
"poster": "https://image.tmdb.org/t/p/w1280/xnopI5Xtky18MPhK40cZAGAOVeV.jpg",
109+
"overview": "A boy is given the ability to become an adult superhero in times of need with a single magic word.",
110+
"release_date": "2019-03-23"
111+
}
112+
]
113+
"""
114+
let documents: Data = documentJsonString.data(using: .utf8)!
115+
116+
client.index("movies").addDocuments(documents: documents) { (result) in
117+
switch result {
118+
case .success(let task):
119+
print(task)
120+
case .failure(let error):
121+
print(error)
122+
}
123+
}
124+
```
125+
117126
```dart Dart
118127
await client.index('movies').addDocuments([
119128
{

snippets/samples/code_samples_add_or_update_documents_1.mdx

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
11
<CodeGroup>
22

3-
```bash cURL
4-
curl \
5-
-X PUT 'MEILISEARCH_URL/indexes/movies/documents' \
6-
-H 'Content-Type: application/json' \
7-
--data-binary '[
8-
{
9-
"id": 287947,
10-
"title": "Shazam ⚡️",
11-
"genres": "comedy"
12-
}
13-
]'
14-
```
15-
163
```javascript JS
174
client.index('movies').updateDocuments([{
185
id: 287947,
@@ -97,6 +84,28 @@ let task: TaskInfo = client
9784
.unwrap();
9885
```
9986

87+
```swift Swift
88+
let documentJsonString = """
89+
[
90+
{
91+
"reference_number": 287947,
92+
"title": "Shazam ⚡️",
93+
"genres": "comedy"
94+
}
95+
]
96+
"""
97+
let documents: Data = documentJsonString.data(using: .utf8)!
98+
99+
client.index("movies").updateDocuments(documents: documents) { (result) in
100+
switch result {
101+
case .success(let task):
102+
print(task)
103+
case .failure(let error):
104+
print(error)
105+
}
106+
}
107+
```
108+
100109
```dart Dart
101110
await client.index('movies').updateDocuments([
102111
{

snippets/samples/code_samples_async_guide_filter_by_date_1.mdx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ let tasks = query
4848
.unwrap();
4949
```
5050

51+
```swift Swift
52+
client.getTasks(params: TasksQuery(afterEnqueuedAt: dateFormatter.date(from: "2020-10-11T11:49:53.000Z"))) { result in
53+
switch result {
54+
case .success(let taskResult):
55+
print(taskResult)
56+
case .failure(let error):
57+
print(error)
58+
}
59+
}
60+
```
61+
5162
```dart Dart
5263
await client.getTasks(
5364
params: TasksQuery(

snippets/samples/code_samples_async_guide_filter_by_ids_1.mdx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ let tasks = query
4040
.unwrap();
4141
```
4242

43+
```swift Swift
44+
client.getTasks(params: TasksQuery(uids: [5, 10, 13])) { result in
45+
switch result {
46+
case .success(let taskResult):
47+
print(taskResult)
48+
case .failure(let error):
49+
print(error)
50+
}
51+
}
52+
```
53+
4354
```dart Dart
4455
await client.getTasks(
4556
params: TasksQuery(

snippets/samples/code_samples_async_guide_filter_by_index_uids_1.mdx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ let tasks = query
4040
.unwrap();
4141
```
4242

43+
```swift Swift
44+
client.getTasks(params: TasksQuery(indexUids: ["movies"])) { result in
45+
switch result {
46+
case .success(let taskResult):
47+
print(taskResult)
48+
case .failure(let error):
49+
print(error)
50+
}
51+
}
52+
```
53+
4354
```dart Dart
4455
await client.getTasks(params: TasksQuery(indexUids: ['movies']));
4556
```

snippets/samples/code_samples_async_guide_filter_by_statuses_1.mdx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
<CodeGroup>
22

3-
```bash cURL
4-
curl \
5-
-X GET 'MEILISEARCH_URL/tasks?statuses=failed'
6-
```
7-
83
```javascript JS
94
client.tasks.getTasks({ statuses: ['failed', 'canceled'] })
105
```
@@ -48,6 +43,17 @@ let tasks = query
4843
.unwrap();
4944
```
5045

46+
```swift Swift
47+
client.getTasks(params: TasksQuery(statuses: [.failed, .canceled])) { result in
48+
switch result {
49+
case .success(let taskResult):
50+
print(taskResult)
51+
case .failure(let error):
52+
print(error)
53+
}
54+
}
55+
```
56+
5157
```dart Dart
5258
await client.getTasks(
5359
params: TasksQuery(

snippets/samples/code_samples_async_guide_filter_by_statuses_2.mdx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
<CodeGroup>
22

3-
```bash cURL
4-
curl \
5-
-X GET 'MEILISEARCH_URL/tasks?statuses=failed,canceled'
6-
```
7-
83
```rust Rust
94
let mut query = TasksQuery::new(&client);
105
let tasks = query

snippets/samples/code_samples_async_guide_filter_by_types_1.mdx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ let tasks = query
4343
.unwrap();
4444
```
4545

46+
```swift Swift
47+
client.getTasks(params: TasksQuery(types: [.dumpCreation, .indexSwap])) { result in
48+
switch result {
49+
case .success(let taskResult):
50+
print(taskResult)
51+
case .failure(let error):
52+
print(error)
53+
}
54+
}
55+
```
56+
4657
```dart Dart
4758
await client.getTasks(
4859
params: TasksQuery(

snippets/samples/code_samples_async_guide_multiple_filters_1.mdx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
<CodeGroup>
22

3-
```bash cURL
4-
curl \
5-
-X GET 'MEILISEARCH_URL/tasks?indexUids=movies&types=documentAdditionOrUpdate,documentDeletion&statuses=processing'
6-
```
7-
83
```javascript JS
94
client.tasks.getTasks({
105
indexUids: ['movies'],
@@ -76,6 +71,17 @@ let tasks = query
7671
.unwrap();
7772
```
7873

74+
```swift Swift
75+
client.getTasks(params: TasksQuery(indexUids: "movies", types: ["documentAdditionOrUpdate", "documentDeletion"], statuses: ["processing"])) { result in
76+
switch result {
77+
case .success(let taskResult):
78+
print(taskResult)
79+
case .failure(let error):
80+
print(error)
81+
}
82+
}
83+
```
84+
7985
```dart Dart
8086
await client.getTasks(
8187
params: TasksQuery(

0 commit comments

Comments
 (0)