@@ -40,18 +40,26 @@ All responses are deserialized into maps before returning one of these responses
4040
4141## Examples
4242
43+ ### Creating a client
44+
45+ All API function that make requests require a client.
46+
47+ ``` elixir
48+ client = Algolia .new ()
49+ ```
50+
4351### Searching
4452
4553#### Searching an index
4654
4755``` elixir
48- " my_index " |> Algolia .search (" some query" )
56+ Algolia .search (client, " my_index " , " some query" )
4957```
5058
5159With options:
5260
5361``` elixir
54- " my_index " |> Algolia .search (" some query" , attributesToRetrieve: " firstname" , hitsPerPage: 20 )
62+ Algolia .search (client, " my_index " , " some query" , attributesToRetrieve: " firstname" , hitsPerPage: 20 )
5563```
5664
5765See 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
6169Browsing is like search but skips most ranking and allows fetching more results at once.
6270
6371``` elixir
64- " my_index" |> Algolia . browse ( " some query" , filter: " color:red" )
72+ Algolia . browse (client, " my_index" , query: " some query" , filter: " color:red" )
6573```
6674
6775#### Multiple queries at once
6876
6977``` 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" }
7482])
7583```
7684
@@ -80,7 +88,7 @@ You can specify a strategy to optimize your multiple queries:
8088- ` stop_if_enough_matches ` : Execute the sequence of queries until the number of hits is reached by the sum of hits.
8189
8290``` elixir
83- Algolia .multi ([query1, query2], strategy: :stop_if_enough_matches )
91+ Algolia .multi (client, [query1, query2], strategy: :stop_if_enough_matches )
8492```
8593
8694### Saving
@@ -91,123 +99,125 @@ Save a single object to index without specifying objectID. You must have `object
9199inside object, or use the ` id_attribute ` option (see below).
92100
93101``` elixir
94- " my_index " |> Algolia .save_object (%{objectID: " 1" })
102+ Algolia .save_object (client, " my_index " , %{objectID: " 1" })
95103```
96104
97105Save a single object with a given objectID:
98106
99107``` elixir
100- " my_index " |> Algolia .save_object (%{title: " hello" }, " 12345" )
108+ Algolia .save_object (client, " my_index " , %{title: " hello" }, " 12345" )
101109```
102110
103111Save multiple objects to an index:
104112
105113``` elixir
106- " my_index " |> Algolia .save_objects ([%{objectID: " 1" }, %{objectID: " 2" }])
114+ Algolia .save_objects (client, " my_index " , [%{objectID: " 1" }, %{objectID: " 2" }])
107115```
108116
109117### Updating
110118
111119Partially update a single object:
112120
113121``` elixir
114- " my_index " |> Algolia .partial_update_object (%{title: " hello" }, " 12345" )
122+ Algolia .partial_update_object (client, " my_index " , %{title: " hello" }, " 12345" )
115123```
116124
117125Update multiple objects. You must have ` objectID ` in each object, or use the ` id_attribute ` option (see below).
118126
119127``` elixir
120- " my_index " |> Algolia .partial_update_objects ([%{objectID: " 1" }, %{objectID: " 2" }])
128+ Algolia .partial_update_objects (client, " my_index " , [%{objectID: " 1" }, %{objectID: " 2" }])
121129```
122130
123131Partial update by default creates a new object if an object does not exist at the
124132objectID. You can turn this off by passing ` false ` to the ` :upsert? ` option.
125133
126134``` 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 )
129137```
130138
131-
132139### ` id_attribute ` option
133140
134141All write functions such as ` save_object ` and ` partial_update_object ` come with an ` id_attribute ` option that lets
135142you specify the ` objectID ` from an existing field in the object, so you do not have to generate it yourself.
136143
137144``` elixir
138- " my_index " |> Algolia .save_object (%{id: " 2" }, id_attribute: :id )
145+ Algolia .save_object (client, " my_index " , %{id: " 2" }, id_attribute: :id )
139146```
140147
141148It also works for batch operations, such as ` save_objects ` and ` partial_update_objects ` :
142149
143150``` 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 )
145152```
146153
147-
148154### Wait for task
149155
150156All write operations can be waited on by simply piping the response into ` wait/1 ` :
151157
152158``` 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)
154162```
155163
156164The client polls the server to check the status of the task.
157165You can specify a time (in milliseconds) between each tick of the poll; the default is 1000ms (1 second).
158166
159167``` 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 )
161171```
162172
163- You can also explicitly pass a ` taskID ` to ` wait ` :
173+ You can also explicitly pass a ` taskID ` to ` wait_task ` :
164174
165175
166176``` elixir
167177{:ok , %{" taskID" => task_id, " indexName" => index}}
168- = " my_index " |> Algolia .save_object (%{id: " 123" })
178+ = Algolia .save_object (client, " my_index " , %{id: " 123" })
169179
170- Algolia .wait ( index, task_id)
180+ Algolia .wait_task (client, index, task_id)
171181```
172182
173183Optionally including the poll interval:
174184
175185``` elixir
176- Algolia .wait (index, task_id, 2_000 )
186+ Algolia .wait (client, index, task_id, retry_delay: 2_000 )
177187```
178188
179189### Index related operations
180190
181191#### Listing all indexes
182192
183193``` elixir
184- Algolia .list_indexes ()
194+ Algolia .list_indexes (client )
185195```
186196
187197#### Move an index
188198
189199``` elixir
190- Algolia .move_index (source_index, destination_index)
200+ Algolia .move_index (client, source_index, destination_index)
191201```
192202
193203#### Copy an index
194204
195205``` elixir
196- Algolia .copy_index (source_index, destination_index)
206+ Algolia .copy_index (client, source_index, destination_index)
197207```
198208
199209#### Clear an index
200210
201211``` elixir
202- Algolia .clear_index (index)
212+ Algolia .clear_index (client, index)
203213```
204214
205215### Settings
206216
207217#### Get index settings
208218
209219``` elixir
210- Algolia .get_settings (index)
220+ Algolia .get_settings (client, index)
211221```
212222
213223Example response:
@@ -238,7 +248,7 @@ Example response:
238248#### Update index settings
239249
240250``` elixir
241- Algolia .set_settings (index, %{" hitsPerPage" => 20 })
251+ Algolia .set_settings (client, index, %{" hitsPerPage" => 20 })
242252
243253> {:ok , %{" updatedAt" => " 2013-08-21T13:20:18.960Z" ,
244254 " taskID" => 10210332 .
@@ -250,7 +260,7 @@ Algolia.set_settings(index, %{"hitsPerPage" => 20})
250260#### Push events
251261
252262``` elixir
253- Algolia .push_events ([
263+ Algolia .push_events (client, [
254264 %{
255265 " eventType" => " click" ,
256266 " eventName" => " Product Clicked" ,
0 commit comments