public class Index
extends Object
A proxy to an Algolia index.
You cannot construct this class directly. Please use Client.getIndex(String) to obtain an instance.
WARNING: For performance reasons, arguments to asynchronous methods are not cloned. Therefore, you should not modify mutable arguments after they have been passed (unless explicitly noted).
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_SETTINGS_VERSION |
| Modifier and Type | Method and Description |
|---|---|
Request |
addObjectAsync(JSONObject object,
CompletionHandler completionHandler)
Add an object to this index (asynchronously).
|
Request |
addObjectAsync(JSONObject object,
String objectID,
CompletionHandler completionHandler)
Add an object to this index, assigning it the specified object ID (asynchronously).
|
Request |
addObjectsAsync(JSONArray objects,
CompletionHandler completionHandler)
Add several objects to this index (asynchronously).
|
Request |
browseAsync(Query query,
CompletionHandler completionHandler)
Browse all index content (initial call).
|
Request |
browseFromAsync(String cursor,
CompletionHandler completionHandler)
Browse the index from a cursor.
|
Request |
clearIndexAsync(CompletionHandler completionHandler)
Clear this index.
|
void |
clearSearchCache()
Remove all entries from cache
|
Request |
deleteByQueryAsync(Query query,
CompletionHandler completionHandler)
Delete all objects matching a query (helper).
|
Request |
deleteObjectAsync(String objectID,
CompletionHandler completionHandler)
Delete an object from this index (asynchronously).
|
Request |
deleteObjectsAsync(List<String> objectIDs,
CompletionHandler completionHandler)
Delete several objects from this index (asynchronously).
|
void |
disableSearchCache()
Disable and reset cache
|
void |
enableSearchCache()
Enable search cache with default parameters
|
void |
enableSearchCache(int timeoutInSeconds,
int maxRequests)
Enable search cache with custom parameters
|
Client |
getClient() |
String |
getIndexName() |
Request |
getObjectAsync(String objectID,
CompletionHandler completionHandler)
Get an object from this index (asynchronously).
|
Request |
getObjectAsync(String objectID,
List<String> attributesToRetrieve,
CompletionHandler completionHandler)
Get an object from this index, optionally restricting the retrieved content (asynchronously).
|
Request |
getObjectsAsync(List<String> objectIDs,
CompletionHandler completionHandler)
Get several objects from this index (asynchronously).
|
Request |
getObjectsAsync(List<String> objectIDs,
List<String> attributesToRetrieve,
CompletionHandler completionHandler)
Get several objects from this index (asynchronously), optionally restricting the retrieved content (asynchronously).
|
Request |
getSettingsAsync(CompletionHandler completionHandler)
Get this index’s settings (asynchronously).
|
Request |
multipleQueriesAsync(List<Query> queries,
Client.MultipleQueriesStrategy strategy,
CompletionHandler completionHandler)
Run multiple queries on this index with one API call.
|
Request |
partialUpdateObjectAsync(JSONObject partialObject,
String objectID,
boolean createIfNotExists,
CompletionHandler completionHandler)
Partially update an object (asynchronously).
|
Request |
partialUpdateObjectAsync(JSONObject partialObject,
String objectID,
CompletionHandler completionHandler)
Partially update an object (asynchronously).
|
Request |
partialUpdateObjectsAsync(JSONArray partialObjects,
boolean createIfNotExists,
CompletionHandler completionHandler)
Partially update several objects (asynchronously).
|
Request |
partialUpdateObjectsAsync(JSONArray partialObjects,
CompletionHandler completionHandler)
Partially update several objects (asynchronously).
|
Request |
saveObjectAsync(JSONObject object,
String objectID,
CompletionHandler completionHandler)
Update an object (asynchronously).
|
Request |
saveObjectsAsync(JSONArray objects,
CompletionHandler completionHandler)
Update several objects (asynchronously).
|
Request |
searchAsync(Query query,
CompletionHandler completionHandler)
Search inside this index (asynchronously).
|
Request |
searchDisjunctiveFacetingAsync(Query query,
List<String> disjunctiveFacets,
Map<String,List<String>> refinements,
CompletionHandler completionHandler)
Perform a search with disjunctive facets, generating as many queries as number of disjunctive facets (helper).
|
Request |
searchForFacetValues(String facetName,
String text,
CompletionHandler handler)
Search (asynchronously) for some text in a facet values.
|
Request |
searchForFacetValues(String facetName,
String facetText,
Query query,
CompletionHandler handler)
Search (asynchronously) for some text in a facet values, optionally restricting the returned values to those contained in objects matching other (regular) search criteria.
|
Request |
searchForFacetValuesAsync(String facetName,
String text,
CompletionHandler handler)
Search (asynchronously) for some text in a facet values.
|
Request |
searchForFacetValuesAsync(String facetName,
String facetText,
Query query,
CompletionHandler handler)
Search for some text in a facet values, optionally restricting the returned values to those contained in objects matching other (regular) search criteria.
|
JSONObject |
searchSync(Query query)
Search inside this index (synchronously).
|
Request |
setSettingsAsync(JSONObject settings,
CompletionHandler completionHandler)
Set this index’s settings (asynchronously).
|
String |
toString() |
Request |
waitTaskAsync(String taskID,
CompletionHandler completionHandler)
Wait until the publication of a task on the server (helper).
|
public static final int DEFAULT_SETTINGS_VERSION
public String toString()
toString in class Objectpublic String getIndexName()
public Client getClient()
public Request searchAsync(@Nullable Query query, @Nullable CompletionHandler completionHandler)
Search inside this index (asynchronously).
query - Search parameters. May be null to use an empty query.completionHandler - The listener that will be notified of the request’s outcome.public JSONObject searchSync(@Nullable
Query query)
throws AlgoliaException
Search inside this index (synchronously).
AlgoliaExceptionpublic Request multipleQueriesAsync(@NonNull List<Query> queries, Client.MultipleQueriesStrategy strategy, @NonNull CompletionHandler completionHandler)
Run multiple queries on this index with one API call. A variant of Client.multipleQueriesAsync(List, Client.MultipleQueriesStrategy, CompletionHandler) where the targeted index is always the receiver.
queries - The queries to run.strategy - The strategy to use.completionHandler - The listener that will be notified of the request’s outcome.public Request searchDisjunctiveFacetingAsync(@NonNull Query query, @NonNull List<String> disjunctiveFacets, @NonNull Map<String,List<String>> refinements, @NonNull CompletionHandler completionHandler)
Perform a search with disjunctive facets, generating as many queries as number of disjunctive facets (helper).
query - The query.disjunctiveFacets - List of disjunctive facets.refinements - The current refinements, mapping facet names to a list of values.completionHandler - The listener that will be notified of the request’s outcome.public Request searchForFacetValuesAsync(@NonNull String facetName, @NonNull String text, @NonNull CompletionHandler handler) throws AlgoliaException
Search (asynchronously) for some text in a facet values.
facetName - The name of the facet to search. It must have been declared in the index’s attributesForFaceting setting with the searchable() modifier.text - The text to search for in the facet’s values.handler - A Completion handler that will be notified of the request’s outcome.AlgoliaExceptionpublic Request searchForFacetValues(@NonNull String facetName, @NonNull String text, @NonNull CompletionHandler handler)
Search (asynchronously) for some text in a facet values.
facetName - The name of the facet to search. It must have been declared in the index’s attributesForFaceting setting with the searchable() modifier.text - The text to search for in the facet’s values.handler - A Completion handler that will be notified of the request’s outcome.public Request searchForFacetValuesAsync(@NonNull String facetName, @NonNull String facetText, @Nullable Query query, @NonNull CompletionHandler handler)
Search for some text in a facet values, optionally restricting the returned values to those contained in objects matching other (regular) search criteria.
facetName - The name of the facet to search. It must have been declared in the index’s attributesForFaceting setting with the searchable() modifier.facetText - The text to search for in the facet’s values.query - An optional query to take extra search parameters into account. There parameters apply to index objects like in a regular search query. Only facet values contained in the matched objects will be returnedhandler - A Completion handler that will be notified of the request’s outcome.public Request searchForFacetValues(@NonNull String facetName, @NonNull String facetText, @Nullable Query query, @NonNull CompletionHandler handler)
Search (asynchronously) for some text in a facet values, optionally restricting the returned values to those contained in objects matching other (regular) search criteria.
facetName - The name of the facet to search. It must have been declared in the index’s attributesForFaceting setting with the searchable() modifier.facetText - The text to search for in the facet’s values.query - An optional query to take extra search parameters into account. There parameters apply to index objects like in a regular search query. Only facet values contained in the matched objects will be returnedhandler - A Completion handler that will be notified of the request’s outcome.public Request addObjectAsync(@NonNull JSONObject object, CompletionHandler completionHandler)
Add an object to this index (asynchronously).
WARNING: For performance reasons, the arguments are not cloned. Since the method is executed in the background, you should not modify the object after it has been passed.
object - The object to add.completionHandler - The listener that will be notified of the request’s outcome.public Request addObjectAsync(@NonNull JSONObject object, @NonNull String objectID, CompletionHandler completionHandler)
Add an object to this index, assigning it the specified object ID (asynchronously). If an object already exists with the same object ID, the existing object will be overwritten.
WARNING: For performance reasons, the arguments are not cloned. Since the method is executed in the background, you should not modify the object after it has been passed.
object - The object to add.objectID - Identifier that you want to assign this object.completionHandler - The listener that will be notified of the request’s outcome.public Request addObjectsAsync(@NonNull JSONArray objects, CompletionHandler completionHandler)
Add several objects to this index (asynchronously).
objects - Objects to add.completionHandler - The listener that will be notified of the request’s outcome.public Request saveObjectAsync(@NonNull JSONObject object, @NonNull String objectID, CompletionHandler completionHandler)
Update an object (asynchronously).
object - New version of the object to update.objectID - Identifier of the object to update.completionHandler - The listener that will be notified of the request’s outcome.public Request saveObjectsAsync(@NonNull JSONArray objects, @NonNull CompletionHandler completionHandler)
Update several objects (asynchronously).
objects - Objects to update. Each object must contain an objectID attribute.completionHandler - The listener that will be notified of the request’s outcome.public Request partialUpdateObjectAsync(@NonNull JSONObject partialObject, @NonNull String objectID, CompletionHandler completionHandler)
Partially update an object (asynchronously).
Note: This method will create the object if it does not exist already. If you don’t wish to, you can use partialUpdateObjectAsync(JSONObject, String, boolean, CompletionHandler) and specify false for the createIfNotExists argument.
partialObject - New value/operations for the object.objectID - Identifier of object to be updated.completionHandler - The listener that will be notified of the request’s outcome.public Request partialUpdateObjectAsync(@NonNull JSONObject partialObject, @NonNull String objectID, boolean createIfNotExists, CompletionHandler completionHandler)
Partially update an object (asynchronously).
partialObject - New value/operations for the object.objectID - Identifier of object to be updated.createIfNotExists - Whether the object should be created if it does not exist already.completionHandler - The listener that will be notified of the request’s outcome.public Request partialUpdateObjectsAsync(@NonNull JSONArray partialObjects, CompletionHandler completionHandler)
Partially update several objects (asynchronously).
Note: This method will create the objects if they do not exist already. If you don’t wish to, you can use partialUpdateObjectsAsync(JSONArray, boolean, CompletionHandler) and specify false for the createIfNotExists argument.
partialObjects - New values/operations for the objects. Each object must contain an objectID attribute.completionHandler - The listener that will be notified of the request’s outcome.public Request partialUpdateObjectsAsync(@NonNull JSONArray partialObjects, boolean createIfNotExists, CompletionHandler completionHandler)
Partially update several objects (asynchronously).
partialObjects - New values/operations for the objects. Each object must contain an objectID attribute.createIfNotExists - Whether objects should be created if they do not exist already.completionHandler - The listener that will be notified of the request’s outcome.public Request getObjectAsync(@NonNull String objectID, @NonNull CompletionHandler completionHandler)
Get an object from this index (asynchronously).
objectID - Identifier of the object to retrieve.completionHandler - The listener that will be notified of the request’s outcome.public Request getObjectAsync(@NonNull String objectID, List<String> attributesToRetrieve, @NonNull CompletionHandler completionHandler)
Get an object from this index, optionally restricting the retrieved content (asynchronously).
objectID - Identifier of the object to retrieve.attributesToRetrieve - List of attributes to retrieve.completionHandler - The listener that will be notified of the request’s outcome.public Request getObjectsAsync(@NonNull List<String> objectIDs, @NonNull CompletionHandler completionHandler)
Get several objects from this index (asynchronously).
objectIDs - Identifiers of objects to retrieve.completionHandler - The listener that will be notified of the request’s outcome.public Request getObjectsAsync(@NonNull List<String> objectIDs, List<String> attributesToRetrieve, @NonNull CompletionHandler completionHandler)
Get several objects from this index (asynchronously), optionally restricting the retrieved content (asynchronously).
objectIDs - Identifiers of objects to retrieve.attributesToRetrieve - List of attributes to retrieve.completionHandler - The listener that will be notified of the request’s outcome.public Request waitTaskAsync(@NonNull String taskID, @NonNull CompletionHandler completionHandler)
Wait until the publication of a task on the server (helper). All server tasks are asynchronous. This method helps you check that a task is published.
taskID - Identifier of the task (as returned by the server).completionHandler - The listener that will be notified of the request’s outcome.public Request deleteObjectAsync(@NonNull String objectID, CompletionHandler completionHandler)
Delete an object from this index (asynchronously).
objectID - Identifier of the object to delete.completionHandler - The listener that will be notified of the request’s outcome.public Request deleteObjectsAsync(@NonNull List<String> objectIDs, CompletionHandler completionHandler)
Delete several objects from this index (asynchronously).
objectIDs - Identifiers of objects to delete.completionHandler - The listener that will be notified of the request’s outcome.public Request deleteByQueryAsync(@NonNull Query query, CompletionHandler completionHandler)
Delete all objects matching a query (helper).
query - The query that objects to delete must match.completionHandler - The listener that will be notified of the request’s outcome.public Request getSettingsAsync(@NonNull CompletionHandler completionHandler)
Get this index’s settings (asynchronously).
completionHandler - The listener that will be notified of the request’s outcome.public Request setSettingsAsync(@NonNull JSONObject settings, CompletionHandler completionHandler)
Set this index’s settings (asynchronously).
Please refer to our API documentation for the list of supported settings.
settings - New settings.completionHandler - The listener that will be notified of the request’s outcome.public Request browseAsync(@NonNull Query query, @NonNull CompletionHandler completionHandler)
Browse all index content (initial call). This method should be called once to initiate a browse. It will return the first page of results and a cursor, unless the end of the index has been reached. To retrieve subsequent pages, call browseFromAsync with that cursor.
query - The query parameters for the browse.completionHandler - The listener that will be notified of the request’s outcome.public Request browseFromAsync(@NonNull String cursor, @NonNull CompletionHandler completionHandler)
Browse the index from a cursor. This method should be called after an initial call to browseAsync(). It returns a cursor, unless the end of the index has been reached.
cursor - The cursor of the next page to retrieve.completionHandler - The listener that will be notified of the request’s outcome.public Request clearIndexAsync(CompletionHandler completionHandler)
Clear this index.
completionHandler - The listener that will be notified of the request’s outcome.public void enableSearchCache()
Enable search cache with default parameters
public void enableSearchCache(int timeoutInSeconds,
int maxRequests)
Enable search cache with custom parameters
timeoutInSeconds - duration during which an request is kept in cachemaxRequests - maximum amount of requests to keep before removing the least recently usedpublic void disableSearchCache()
Disable and reset cache
public void clearSearchCache()
Remove all entries from cache