Skip to content

Commit 19eed1c

Browse files
authored
Merge pull request #97 from algoliareadmebot/master
Update README
2 parents ff67077 + 00ec3b5 commit 19eed1c

File tree

1 file changed

+50
-53
lines changed

1 file changed

+50
-53
lines changed

README.md

Lines changed: 50 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Indexing
5050

5151
1. [Add objects](#add-objects---add_objects)
5252
1. [Update objects](#update-objects---save_objects)
53-
1. [Partial update](#partial-update---partial_update_objects)
53+
1. [Partial update objects](#partial-update-objects---partial_update_objects)
5454
1. [Delete objects](#delete-objects---delete_objects)
5555

5656
Settings
@@ -555,29 +555,40 @@ res = index.get_objects(["myID1", "myID2"])
555555

556556
Each entry in an index has a unique identifier called `objectID`. There are two ways to add an entry to the index:
557557

558-
1. Using automatic `objectID` assignment. You will be able to access it in the answer.
559-
2. Supplying your own `objectID`.
558+
1. Supplying your own `objectID`.
559+
2. Using automatic `objectID` assignment. You will be able to access it in the answer.
560560

561561
You don't need to explicitly create an index, it will be automatically created the first time you add an object.
562562
Objects are schema less so you don't need any configuration to start indexing. If you wish to configure things, the settings section provides details about advanced settings.
563563

564-
Example with automatic `objectID` assignment:
564+
Example with automatic `objectID` assignments:
565565

566566
```python
567-
res = index.add_object({"firstname": "Jimmie",
568-
"lastname": "Barninger"})
569-
print "ObjectID=%s" % res["objectID"]
567+
res = index.add_objects([{"firstname": "Jimmie",
568+
"lastname": "Barninger"},
569+
{"firstname": "Warren",
570+
"lastname": "Speach"}])
571+
```
572+
573+
Example with manual `objectID` assignments:
574+
575+
```python
576+
res = index.add_objects([{"objectID": "1",
577+
"firstname": "Jimmie",
578+
"lastname": "Barninger"},
579+
{"objectID": "2",
580+
"firstname": "Warren",
581+
"lastname": "Speach"}])
570582
```
571583

572-
Example with manual `objectID` assignment:
584+
To add a single object, use the `[Add object](#add-object---add_object)` method:
573585

574586
```python
575587
res = index.add_object({"firstname": "Jimmie",
576588
"lastname": "Barninger"}, "myID")
577589
print "ObjectID=%s" % res["objectID"]
578590
```
579591

580-
581592
### Update objects - `save_objects`
582593

583594
You have three options when updating an existing object:
@@ -586,7 +597,18 @@ You have three options when updating an existing object:
586597
2. Replace only some attributes.
587598
3. Apply an operation to some attributes.
588599

589-
Example on how to replace all attributes of an existing object:
600+
Example on how to replace all attributes existing objects:
601+
602+
```python
603+
res = index.save_objects([{"firstname": "Jimmie",
604+
"lastname": "Barninger",
605+
"objectID": "myID1"},
606+
{"firstname": "Warren",
607+
"lastname": "Speach",
608+
"objectID": "myID2"}])
609+
```
610+
611+
To update a single object, you can use the `[Update object](#update-object---save_object) method:
590612

591613
```python
592614
index.save_object({"firstname": "Jimmie",
@@ -595,7 +617,8 @@ index.save_object({"firstname": "Jimmie",
595617
"objectID": "myID"})
596618
```
597619

598-
### Partial update - `partial_update_objects`
620+
621+
### Partial update objects - `partial_update_objects`
599622

600623
You have many ways to update an object's attributes:
601624

@@ -654,10 +677,25 @@ index.partial_update_object({"price": { "value": 42, "_operation": "Decrement"},
654677
Note: Here we are decrementing the value by `42`. To decrement just by one, put
655678
`value:1`.
656679

680+
To partial update multiple objects using one API call, you can use the `[Partial update objects](#partial-update-objects---partial_update_objects)` method:
681+
682+
```python
683+
res = index.partial_update_objects([{"firstname": "Jimmie",
684+
"objectID": "myID1"},
685+
{"firstname": "Warren",
686+
"objectID": "myID2"}])
687+
```
688+
657689

658690
### Delete objects - `delete_objects`
659691

660-
You can delete an object using its `objectID`:
692+
You can delete objects using their `objectID`:
693+
694+
```python
695+
res = index.delete_objects(["myID1", "myID2"])
696+
```
697+
698+
To delete a single object, you can use the `[Delete object](#delete-object---delete_object)` method:
661699

662700
```python
663701
index.delete_object("myID")
@@ -2230,47 +2268,6 @@ results = index.search_synonyms('street', ['synonym', 'oneWaySynonym'], 1, 10)
22302268
### Custom batch - `batch`
22312269

22322270
You may want to perform multiple operations with one API call to reduce latency.
2233-
We expose four methods to perform batch operations:
2234-
2235-
* Add objects - `add_objects`: Add an array of objects using automatic `objectID` assignment.
2236-
* Update objects - `save_objects`: Add or update an array of objects that contains an `objectID` attribute.
2237-
* Delete objects - `delete_objects`: Delete an array of objectIDs.
2238-
* Partial update - `partial_update_objects`: Partially update an array of objects that contain an `objectID` attribute (only specified attributes will be updated).
2239-
2240-
Example using automatic `objectID` assignment:
2241-
2242-
```python
2243-
res = index.add_objects([{"firstname": "Jimmie",
2244-
"lastname": "Barninger"},
2245-
{"firstname": "Warren",
2246-
"lastname": "Speach"}])
2247-
```
2248-
2249-
Example with user defined `objectID` (add or update):
2250-
2251-
```python
2252-
res = index.save_objects([{"firstname": "Jimmie",
2253-
"lastname": "Barninger",
2254-
"objectID": "myID1"},
2255-
{"firstname": "Warren",
2256-
"lastname": "Speach",
2257-
"objectID": "myID2"}])
2258-
```
2259-
2260-
Example that deletes a set of records:
2261-
2262-
```python
2263-
res = index.delete_objects(["myID1", "myID2"])
2264-
```
2265-
2266-
Example that updates only the `firstname` attribute:
2267-
2268-
```python
2269-
res = index.partial_update_objects([{"firstname": "Jimmie",
2270-
"objectID": "myID1"},
2271-
{"firstname": "Warren",
2272-
"objectID": "myID2"}])
2273-
```
22742271

22752272

22762273

0 commit comments

Comments
 (0)