@@ -40,18 +40,26 @@ All responses are deserialized into maps before returning one of these responses
40
40
41
41
## Examples
42
42
43
+ ### Creating a client
44
+
45
+ All API function that make requests require a client.
46
+
47
+ ``` elixir
48
+ client = Algolia .new ()
49
+ ```
50
+
43
51
### Searching
44
52
45
53
#### Searching an index
46
54
47
55
``` elixir
48
- " my_index " |> Algolia .search (" some query" )
56
+ Algolia .search (client, " my_index " , " some query" )
49
57
```
50
58
51
59
With options:
52
60
53
61
``` elixir
54
- " my_index " |> Algolia .search (" some query" , attributesToRetrieve: " firstname" , hitsPerPage: 20 )
62
+ Algolia .search (client, " my_index " , " some query" , attributesToRetrieve: " firstname" , hitsPerPage: 20 )
55
63
```
56
64
57
65
See all available search options [ ** here** ] ( https://www.algolia.com/doc/rest#full-text-search-parameters ) .
@@ -61,16 +69,16 @@ See all available search options [**here**](https://www.algolia.com/doc/rest#ful
61
69
Browsing is like search but skips most ranking and allows fetching more results at once.
62
70
63
71
``` elixir
64
- " my_index" |> Algolia . browse ( " some query" , filter: " color:red" )
72
+ Algolia . browse (client, " my_index" , query: " some query" , filter: " color:red" )
65
73
```
66
74
67
75
#### Multiple queries at once
68
76
69
77
``` elixir
70
- Algolia .multi ([
71
- %{index_name => " my_index1" , query: " search query" },
72
- %{index_name => " my_index2" , query: " another query" , hitsPerPage: 3 , },
73
- %{index_name => " my_index3" , query: " 3rd query" , tagFilters: " promotion" }])
78
+ Algolia .multi (client, [
79
+ %{index_name: " my_index1" , query: " search query" },
80
+ %{index_name: " my_index2" , query: " another query" , hitsPerPage: 3 },
81
+ %{index_name: " my_index3" , query: " 3rd query" , tagFilters: " promotion" }
74
82
])
75
83
```
76
84
@@ -80,7 +88,7 @@ You can specify a strategy to optimize your multiple queries:
80
88
- ` stop_if_enough_matches ` : Execute the sequence of queries until the number of hits is reached by the sum of hits.
81
89
82
90
``` elixir
83
- Algolia .multi ([query1, query2], strategy: :stop_if_enough_matches )
91
+ Algolia .multi (client, [query1, query2], strategy: :stop_if_enough_matches )
84
92
```
85
93
86
94
### Saving
@@ -91,123 +99,125 @@ Save a single object to index without specifying objectID. You must have `object
91
99
inside object, or use the ` id_attribute ` option (see below).
92
100
93
101
``` elixir
94
- " my_index " |> Algolia .save_object (%{objectID: " 1" })
102
+ Algolia .save_object (client, " my_index " , %{objectID: " 1" })
95
103
```
96
104
97
105
Save a single object with a given objectID:
98
106
99
107
``` elixir
100
- " my_index " |> Algolia .save_object (%{title: " hello" }, " 12345" )
108
+ Algolia .save_object (client, " my_index " , %{title: " hello" }, " 12345" )
101
109
```
102
110
103
111
Save multiple objects to an index:
104
112
105
113
``` elixir
106
- " my_index " |> Algolia .save_objects ([%{objectID: " 1" }, %{objectID: " 2" }])
114
+ Algolia .save_objects (client, " my_index " , [%{objectID: " 1" }, %{objectID: " 2" }])
107
115
```
108
116
109
117
### Updating
110
118
111
119
Partially update a single object:
112
120
113
121
``` elixir
114
- " my_index " |> Algolia .partial_update_object (%{title: " hello" }, " 12345" )
122
+ Algolia .partial_update_object (client, " my_index " , %{title: " hello" }, " 12345" )
115
123
```
116
124
117
125
Update multiple objects. You must have ` objectID ` in each object, or use the ` id_attribute ` option (see below).
118
126
119
127
``` elixir
120
- " my_index " |> Algolia .partial_update_objects ([%{objectID: " 1" }, %{objectID: " 2" }])
128
+ Algolia .partial_update_objects (client, " my_index " , [%{objectID: " 1" }, %{objectID: " 2" }])
121
129
```
122
130
123
131
Partial update by default creates a new object if an object does not exist at the
124
132
objectID. You can turn this off by passing ` false ` to the ` :upsert? ` option.
125
133
126
134
``` elixir
127
- " my_index " |> Algolia .partial_update_object (%{title: " hello" }, " 12345" , upsert?: false )
128
- " my_index " |> Algolia .partial_update_objects ([%{id: " 1" }, %{id: " 2" }], id_attribute: :id , upsert?: false )
135
+ Algolia .partial_update_object (client, " my_index " , %{title: " hello" }, " 12345" , upsert?: false )
136
+ Algolia .partial_update_objects (client, " my_index " , [%{id: " 1" }, %{id: " 2" }], id_attribute: :id , upsert?: false )
129
137
```
130
138
131
-
132
139
### ` id_attribute ` option
133
140
134
141
All write functions such as ` save_object ` and ` partial_update_object ` come with an ` id_attribute ` option that lets
135
142
you specify the ` objectID ` from an existing field in the object, so you do not have to generate it yourself.
136
143
137
144
``` elixir
138
- " my_index " |> Algolia .save_object (%{id: " 2" }, id_attribute: :id )
145
+ Algolia .save_object (client, " my_index " , %{id: " 2" }, id_attribute: :id )
139
146
```
140
147
141
148
It also works for batch operations, such as ` save_objects ` and ` partial_update_objects ` :
142
149
143
150
``` elixir
144
- " my_index " |> Algolia .save_objects ([%{id: " 1" }, %{id: " 2" }], id_attribute: :id )
151
+ Algolia .save_objects (client, " my_index " , [%{id: " 1" }, %{id: " 2" }], id_attribute: :id )
145
152
```
146
153
147
-
148
154
### Wait for task
149
155
150
156
All write operations can be waited on by simply piping the response into ` wait/1 ` :
151
157
152
158
``` elixir
153
- " my_index" |> Algolia .save_object (%{id: " 123" }) |> Algolia .wait ()
159
+ client
160
+ |> Algolia .save_object (" my_index" , %{id: " 123" })
161
+ |> Algolia .wait (client)
154
162
```
155
163
156
164
The client polls the server to check the status of the task.
157
165
You can specify a time (in milliseconds) between each tick of the poll; the default is 1000ms (1 second).
158
166
159
167
``` elixir
160
- " my_index" |> Algolia .save_object (%{id: " 123" }) |> Algolia .wait (2_000 )
168
+ client
169
+ |> Algolia .save_object (" my_index" , %{id: " 123" })
170
+ |> Algolia .wait (client, retry_delay: 2_000 )
161
171
```
162
172
163
- You can also explicitly pass a ` taskID ` to ` wait ` :
173
+ You can also explicitly pass a ` taskID ` to ` wait_task ` :
164
174
165
175
166
176
``` elixir
167
177
{:ok , %{" taskID" => task_id, " indexName" => index}}
168
- = " my_index " |> Algolia .save_object (%{id: " 123" })
178
+ = Algolia .save_object (client, " my_index " , %{id: " 123" })
169
179
170
- Algolia .wait ( index, task_id)
180
+ Algolia .wait_task (client, index, task_id)
171
181
```
172
182
173
183
Optionally including the poll interval:
174
184
175
185
``` elixir
176
- Algolia .wait (index, task_id, 2_000 )
186
+ Algolia .wait (client, index, task_id, retry_delay: 2_000 )
177
187
```
178
188
179
189
### Index related operations
180
190
181
191
#### Listing all indexes
182
192
183
193
``` elixir
184
- Algolia .list_indexes ()
194
+ Algolia .list_indexes (client )
185
195
```
186
196
187
197
#### Move an index
188
198
189
199
``` elixir
190
- Algolia .move_index (source_index, destination_index)
200
+ Algolia .move_index (client, source_index, destination_index)
191
201
```
192
202
193
203
#### Copy an index
194
204
195
205
``` elixir
196
- Algolia .copy_index (source_index, destination_index)
206
+ Algolia .copy_index (client, source_index, destination_index)
197
207
```
198
208
199
209
#### Clear an index
200
210
201
211
``` elixir
202
- Algolia .clear_index (index)
212
+ Algolia .clear_index (client, index)
203
213
```
204
214
205
215
### Settings
206
216
207
217
#### Get index settings
208
218
209
219
``` elixir
210
- Algolia .get_settings (index)
220
+ Algolia .get_settings (client, index)
211
221
```
212
222
213
223
Example response:
@@ -238,7 +248,7 @@ Example response:
238
248
#### Update index settings
239
249
240
250
``` elixir
241
- Algolia .set_settings (index, %{" hitsPerPage" => 20 })
251
+ Algolia .set_settings (client, index, %{" hitsPerPage" => 20 })
242
252
243
253
> {:ok , %{" updatedAt" => " 2013-08-21T13:20:18.960Z" ,
244
254
" taskID" => 10210332 .
@@ -250,7 +260,7 @@ Algolia.set_settings(index, %{"hitsPerPage" => 20})
250
260
#### Push events
251
261
252
262
``` elixir
253
- Algolia .push_events ([
263
+ Algolia .push_events (client, [
254
264
%{
255
265
" eventType" => " click" ,
256
266
" eventName" => " Product Clicked" ,
0 commit comments