Skip to content
This repository was archived by the owner on Jan 31, 2022. It is now read-only.

Commit 267956d

Browse files
algoliareadmebotPLNech
authored andcommitted
docs(README): automatic update (#153)
Update README Android [This list might not be relevant] Add documentation for restrictSources (#134) * Add documentation for restrictSources adding typescript setup to menu (#131) Adapt to the Swift-3-compatible 4.x version fix singular method in indexing section fix too many quotes Move the add_objects, save_objects, delete_objects & partial_update_objects methods out of the Advanced section. (#127) wording improvement for generate key method [ci skip]
1 parent a3ee3d5 commit 267956d

File tree

1 file changed

+46
-60
lines changed

1 file changed

+46
-60
lines changed

README.md

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

5151
1. [Add objects](#add-objects---addobjectsasync)
5252
1. [Update objects](#update-objects---saveobjectsasync)
53-
1. [Partial update](#partial-update---partialupdateobjectsasync)
53+
1. [Partial update objects](#partial-update-objects---partialupdateobjectsasync)
5454
1. [Delete objects](#delete-objects---deleteobjectsasync)
5555

5656
Settings
@@ -577,30 +577,31 @@ index.enableSearchCache(300, 20);
577577

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

580-
1. Using automatic `objectID` assignment. You will be able to access it in the answer.
581-
2. Supplying your own `objectID`.
580+
1. Supplying your own `objectID`.
581+
2. Using automatic `objectID` assignment. You will be able to access it in the answer.
582582

583583
You don't need to explicitly create an index, it will be automatically created the first time you add an object.
584584
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.
585585

586-
Example with automatic `objectID` assignment:
586+
Example with automatic `objectID` assignments:
587587

588588
```java
589-
JSONObject object = new JSONObject()
590-
.put("firstname", "Jimmie")
591-
.put("lastname", "Barninger");
592-
index.addObjectAsync(object, new CompletionHandler() {
593-
@Override
594-
public void requestCompleted(JSONObject content, AlgoliaException error) {
595-
// Retrieve the auto-assigned object ID:
596-
if (content != null) {
597-
String objectID = content.optString("objectID");
598-
}
599-
}
600-
});
589+
List<JSONObject> array = new ArrayList<JSONObject>();
590+
array.add(new JSONObject().put("firstname", "Jimmie").put("lastname", "Barninger"));
591+
array.add(new JSONObject().put("firstname", "Warren").put("lastname", "Speach"));
592+
index.addObjectsAsync(new JSONArray(array), null);
593+
```
594+
595+
Example with manual `objectID` assignments:
596+
597+
```java
598+
List<JSONObject> array = new ArrayList<JSONObject>();
599+
array.add(new JSONObject().put("objectID", "1").put("firstname", "Jimmie").put("lastname", "Barninger"));
600+
array.add(new JSONObject().put("objectID", "2").put("firstname", "Warren").put("lastname", "Speach"));
601+
index.addObjectsAsync(new JSONArray(array), null);
601602
```
602603

603-
Example with manual `objectID` assignment:
604+
To add a single object, use the `[Add object](#add-object---addobjectasync)` method:
604605

605606
```java
606607
JSONObject object = new JSONObject()
@@ -609,7 +610,6 @@ JSONObject object = new JSONObject()
609610
index.addObjectAsync(object, "myID", null);
610611
```
611612

612-
613613
### Update objects - `saveObjectsAsync`
614614

615615
You have three options when updating an existing object:
@@ -618,7 +618,16 @@ You have three options when updating an existing object:
618618
2. Replace only some attributes.
619619
3. Apply an operation to some attributes.
620620

621-
Example on how to replace all attributes of an existing object:
621+
Example on how to replace all attributes existing objects:
622+
623+
```java
624+
List<JSONObject> array = new ArrayList<JSONObject>();
625+
array.add(new JSONObject().put("firstname", "Jimmie").put("lastname", "Barninger").put("objectID", "SFO"));
626+
array.add(new JSONObject().put("firstname", "Warren").put("lastname", "Speach").put("objectID", "LA"));
627+
index.saveObjectsAsync(new JSONArray(array), null);
628+
```
629+
630+
To update a single object, you can use the `[Update object](#update-object---saveobjectasync) method:
622631

623632
```java
624633
JSONObject object = new JSONObject()
@@ -628,7 +637,8 @@ JSONObject object = new JSONObject()
628637
index.saveObjectAsync(object, "myID", null);
629638
```
630639

631-
### Partial update - `partialUpdateObjectsAsync`
640+
641+
### Partial update objects - `partialUpdateObjectsAsync`
632642

633643
You have many ways to update an object's attributes:
634644
@@ -681,10 +691,25 @@ index.partialUpdateObjectAsync(new JSONObject("{\"price\": {\"value\": 42, \"_op
681691
Note: Here we are decrementing the value by `42`. To decrement just by one, put
682692
`value:1`.
683693
694+
To partial update multiple objects using one API call, you can use the `[Partial update objects](#partial-update-objects---partialupdateobjectsasync)` method:
695+
696+
```java
697+
List<JSONObject> array = new ArrayList<JSONObject>();
698+
array.add(new JSONObject().put("firstname", "Jimmie").put("objectID", "SFO"));
699+
array.add(new JSONObject().put("firstname", "Warren").put("objectID", "LA"));
700+
index.partialUpdateObjectsAsync(new JSONArray(array), null);
701+
```
702+
684703
685704
### Delete objects - `deleteObjectsAsync`
686705
687-
You can delete an object using its `objectID`:
706+
You can delete objects using their `objectID`:
707+
708+
```java
709+
index.deleteObjectsAsync(Arrays.asList("myID1", "myID2"), null);
710+
```
711+
712+
To delete a single object, you can use the `[Delete object](#delete-object---deleteobjectasync)` method:
688713
689714
```java
690715
index.deleteObjectAsync("myID", null);
@@ -1978,45 +2003,6 @@ client.listIndexesAsync(new CompletionHandler() {
19782003
### Custom batch - `batchAsync`
19792004

19802005
You may want to perform multiple operations with one API call to reduce latency.
1981-
We expose four methods to perform batch operations:
1982-
1983-
* Add objects - `addObjectsAsync`: Add an array of objects using automatic `objectID` assignment.
1984-
* Update objects - `saveObjectsAsync`: Add or update an array of objects that contains an `objectID` attribute.
1985-
* Delete objects - `deleteObjectsAsync`: Delete an array of objectIDs.
1986-
* Partial update - `partialUpdateObjectsAsync`: Partially update an array of objects that contain an `objectID` attribute (only specified attributes will be updated).
1987-
1988-
Example using automatic `objectID` assignment:
1989-
1990-
```java
1991-
List<JSONObject> array = new ArrayList<JSONObject>();
1992-
array.add(new JSONObject().put("firstname", "Jimmie").put("lastname", "Barninger"));
1993-
array.add(new JSONObject().put("firstname", "Warren").put("lastname", "Speach"));
1994-
index.addObjectsAsync(new JSONArray(array), null);
1995-
```
1996-
1997-
Example with user defined `objectID` (add or update):
1998-
1999-
```java
2000-
List<JSONObject> array = new ArrayList<JSONObject>();
2001-
array.add(new JSONObject().put("firstname", "Jimmie").put("lastname", "Barninger").put("objectID", "SFO"));
2002-
array.add(new JSONObject().put("firstname", "Warren").put("lastname", "Speach").put("objectID", "LA"));
2003-
index.saveObjectsAsync(new JSONArray(array), null);
2004-
```
2005-
2006-
Example that deletes a set of records:
2007-
2008-
```java
2009-
index.deleteObjectsAsync(Arrays.asList("myID1", "myID2"), null);
2010-
```
2011-
2012-
Example that updates only the `firstname` attribute:
2013-
2014-
```java
2015-
List<JSONObject> array = new ArrayList<JSONObject>();
2016-
array.add(new JSONObject().put("firstname", "Jimmie").put("objectID", "SFO"));
2017-
array.add(new JSONObject().put("firstname", "Warren").put("objectID", "LA"));
2018-
index.partialUpdateObjectsAsync(new JSONArray(array), null);
2019-
```
20202006

20212007

20222008

0 commit comments

Comments
 (0)