com.algolia.search.saas
Class Index

java.lang.Object
  extended by com.algolia.search.saas.Index

public class Index
extends Object

Contains all the functions related to one index You should use APIClient.initIndex(indexName) to retrieve this object


Constructor Summary
protected Index(APIClient client, String indexName)
          Index initialization (You should not call this yourself)
 
Method Summary
 org.json.JSONObject addObject(org.json.JSONObject obj)
          Add an object in this index
 org.json.JSONObject addObject(org.json.JSONObject obj, String objectID)
          Add an object in this index with a uniq identifier
 org.json.JSONObject addObjects(org.json.JSONArray inputArray)
          Add several objects
 org.json.JSONObject addObjects(List<org.json.JSONObject> objects)
          Add several objects
 org.json.JSONObject addUserKey(List<String> acls)
          Create a new user key
 org.json.JSONObject addUserKey(List<String> acls, int validity, int maxQueriesPerIPPerHour, int maxHitsPerQuery)
          Create a new user key
 org.json.JSONObject batch(org.json.JSONArray actions)
          Custom batch
 org.json.JSONObject batch(List<org.json.JSONObject> actions)
          Custom batch
 org.json.JSONObject browse(int page)
          Browse all index content
 org.json.JSONObject browse(int page, int hitsPerPage)
          Browse all index content
 org.json.JSONObject clearIndex()
          Delete the index content without removing settings and index specific API keys.
 void deleteByQuery(Query query)
          Delete all objects matching a query
 org.json.JSONObject deleteObject(String objectID)
          Delete an object from the index
 org.json.JSONObject deleteObjects(List<String> objects)
          Delete several objects
 org.json.JSONObject deleteUserKey(String key)
          Delete an existing user key
 String getIndexName()
           
 org.json.JSONObject getObject(String objectID)
          Get an object from this index.
 org.json.JSONObject getObject(String objectID, List<String> attributesToRetrieve)
          Get an object from this index
 org.json.JSONObject getObjects(List<String> objectIDs)
          Get several objects from this index
 org.json.JSONObject getSettings()
          Get settings of this index
 org.json.JSONObject getUserKeyACL(String key)
          Get ACL of a user key
 org.json.JSONObject listUserKeys()
          List all existing user keys with their associated ACLs
 org.json.JSONObject partialUpdateObject(org.json.JSONObject partialObject, String objectID)
          Update partially an object (only update attributes passed in argument)
 org.json.JSONObject partialUpdateObjects(org.json.JSONArray inputArray)
          Partially Override the content of several objects
 org.json.JSONObject partialUpdateObjects(List<org.json.JSONObject> objects)
          Partially Override the content of several objects
 org.json.JSONObject saveObject(org.json.JSONObject object, String objectID)
          Override the content of object
 org.json.JSONObject saveObjects(org.json.JSONArray inputArray)
          Override the content of several objects
 org.json.JSONObject saveObjects(List<org.json.JSONObject> objects)
          Override the content of several objects
 org.json.JSONObject search(Query params)
          Search inside the index
 org.json.JSONObject searchDisjunctiveFaceting(Query query, List<String> disjunctiveFacets)
           
 org.json.JSONObject searchDisjunctiveFaceting(Query query, List<String> disjunctiveFacets, Map<String,List<String>> refinements)
          Perform a search with disjunctive facets generating as many queries as number of disjunctive facets
 org.json.JSONObject setSettings(org.json.JSONObject settings)
          Set settings for this index
 org.json.JSONObject updateUserKey(String key, List<String> acls)
          Update a user key
 org.json.JSONObject updateUserKey(String key, List<String> acls, int validity, int maxQueriesPerIPPerHour, int maxHitsPerQuery)
          Update a user key
 void waitTask(String taskID)
          Wait the publication of a task on the server.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Index

protected Index(APIClient client,
                String indexName)
Index initialization (You should not call this yourself)

Method Detail

getIndexName

public String getIndexName()
Returns:
the underlying index name

addObject

public org.json.JSONObject addObject(org.json.JSONObject obj)
                              throws AlgoliaException
Add an object in this index

Parameters:
obj - the object to add
Throws:
AlgoliaException

addObject

public org.json.JSONObject addObject(org.json.JSONObject obj,
                                     String objectID)
                              throws AlgoliaException
Add an object in this index with a uniq identifier

Parameters:
obj - the object to add
objectID - the objectID associated to this object (if this objectID already exist the old object will be overriden)
Throws:
AlgoliaException

batch

public org.json.JSONObject batch(org.json.JSONArray actions)
                          throws AlgoliaException
Custom batch

Parameters:
actions - the array of actions
Throws:
AlgoliaException

batch

public org.json.JSONObject batch(List<org.json.JSONObject> actions)
                          throws AlgoliaException
Custom batch

Parameters:
actions - the array of actions
Throws:
AlgoliaException

addObjects

public org.json.JSONObject addObjects(List<org.json.JSONObject> objects)
                               throws AlgoliaException
Add several objects

Parameters:
objects - the array of objects to add
Throws:
AlgoliaException

addObjects

public org.json.JSONObject addObjects(org.json.JSONArray inputArray)
                               throws AlgoliaException
Add several objects

Parameters:
objects - the array of objects to add
Throws:
AlgoliaException

getObject

public org.json.JSONObject getObject(String objectID)
                              throws AlgoliaException
Get an object from this index. Return null if the object doens't exist.

Parameters:
objectID - the unique identifier of the object to retrieve
Throws:
AlgoliaException

getObject

public org.json.JSONObject getObject(String objectID,
                                     List<String> attributesToRetrieve)
                              throws AlgoliaException
Get an object from this index

Parameters:
objectID - the unique identifier of the object to retrieve
attributesToRetrieve, - contains the list of attributes to retrieve.
Throws:
AlgoliaException

getObjects

public org.json.JSONObject getObjects(List<String> objectIDs)
                               throws AlgoliaException
Get several objects from this index

Parameters:
objectIDs - the array of unique identifier of objects to retrieve
Throws:
AlgoliaException

partialUpdateObject

public org.json.JSONObject partialUpdateObject(org.json.JSONObject partialObject,
                                               String objectID)
                                        throws AlgoliaException
Update partially an object (only update attributes passed in argument)

Parameters:
partialObject - the object to override
Throws:
AlgoliaException

partialUpdateObjects

public org.json.JSONObject partialUpdateObjects(org.json.JSONArray inputArray)
                                         throws AlgoliaException
Partially Override the content of several objects

Parameters:
objects - the array of objects to update (each object must contains an objectID attribute)
Throws:
AlgoliaException

partialUpdateObjects

public org.json.JSONObject partialUpdateObjects(List<org.json.JSONObject> objects)
                                         throws AlgoliaException
Partially Override the content of several objects

Parameters:
objects - the array of objects to update (each object must contains an objectID attribute)
Throws:
AlgoliaException

saveObject

public org.json.JSONObject saveObject(org.json.JSONObject object,
                                      String objectID)
                               throws AlgoliaException
Override the content of object

Parameters:
object - the object to update
Throws:
AlgoliaException

saveObjects

public org.json.JSONObject saveObjects(List<org.json.JSONObject> objects)
                                throws AlgoliaException
Override the content of several objects

Parameters:
objects - the array of objects to update (each object must contains an objectID attribute)
Throws:
AlgoliaException

saveObjects

public org.json.JSONObject saveObjects(org.json.JSONArray inputArray)
                                throws AlgoliaException
Override the content of several objects

Parameters:
objects - the array of objects to update (each object must contains an objectID attribute)
Throws:
AlgoliaException

deleteObject

public org.json.JSONObject deleteObject(String objectID)
                                 throws AlgoliaException
Delete an object from the index

Parameters:
objectID - the unique identifier of object to delete
Throws:
AlgoliaException

deleteByQuery

public void deleteByQuery(Query query)
                   throws AlgoliaException
Delete all objects matching a query

Parameters:
query - the query string
params - the optional query parameters
Throws:
AlgoliaException

search

public org.json.JSONObject search(Query params)
                           throws AlgoliaException
Search inside the index

Throws:
AlgoliaException

deleteObjects

public org.json.JSONObject deleteObjects(List<String> objects)
                                  throws AlgoliaException
Delete several objects

Parameters:
objects - the array of objectIDs to delete
Throws:
AlgoliaException

browse

public org.json.JSONObject browse(int page)
                           throws AlgoliaException
Browse all index content

Parameters:
page - Pagination parameter used to select the page to retrieve. Page is zero-based and defaults to 0. Thus, to retrieve the 10th page you need to set page=9
Throws:
AlgoliaException

browse

public org.json.JSONObject browse(int page,
                                  int hitsPerPage)
                           throws AlgoliaException
Browse all index content

Parameters:
page - Pagination parameter used to select the page to retrieve. Page is zero-based and defaults to 0. Thus, to retrieve the 10th page you need to set page=9
hitsPerPage: - Pagination parameter used to select the number of hits per page. Defaults to 1000.
Throws:
AlgoliaException

waitTask

public void waitTask(String taskID)
              throws AlgoliaException
Wait the publication of a task on the server. All server task are asynchronous and you can check with this method that the task is published.

Parameters:
taskID - the id of the task returned by server
Throws:
AlgoliaException

getSettings

public org.json.JSONObject getSettings()
                                throws AlgoliaException
Get settings of this index

Throws:
AlgoliaException

clearIndex

public org.json.JSONObject clearIndex()
                               throws AlgoliaException
Delete the index content without removing settings and index specific API keys.

Throws:
AlgoliaException

setSettings

public org.json.JSONObject setSettings(org.json.JSONObject settings)
                                throws AlgoliaException
Set settings for this index

Parameters:
settigns - the settings object that can contains : - minWordSizefor1Typo: (integer) the minimum number of characters to accept one typo (default = 3). - minWordSizefor2Typos: (integer) the minimum number of characters to accept two typos (default = 7). - hitsPerPage: (integer) the number of hits per page (default = 10). - attributesToRetrieve: (array of strings) default list of attributes to retrieve in objects. If set to null, all attributes are retrieved. - attributesToHighlight: (array of strings) default list of attributes to highlight. If set to null, all indexed attributes are highlighted. - attributesToSnippet**: (array of strings) default list of attributes to snippet alongside the number of words to return (syntax is attributeName:nbWords). By default no snippet is computed. If set to null, no snippet is computed. - attributesToIndex: (array of strings) the list of fields you want to index. If set to null, all textual and numerical attributes of your objects are indexed, but you should update it to get optimal results. This parameter has two important uses: - Limit the attributes to index: For example if you store a binary image in base64, you want to store it and be able to retrieve it but you don't want to search in the base64 string. - Control part of the ranking*: (see the ranking parameter for full explanation) Matches in attributes at the beginning of the list will be considered more important than matches in attributes further down the list. In one attribute, matching text at the beginning of the attribute will be considered more important than text after, you can disable this behavior if you add your attribute inside `unordered(AttributeName)`, for example attributesToIndex: ["title", "unordered(text)"]. - attributesForFaceting: (array of strings) The list of fields you want to use for faceting. All strings in the attribute selected for faceting are extracted and added as a facet. If set to null, no attribute is used for faceting. - ranking: (array of strings) controls the way results are sorted. We have six available criteria: - typo: sort according to number of typos, - geo: sort according to decreassing distance when performing a geo-location based search, - proximity: sort according to the proximity of query words in hits, - attribute: sort according to the order of attributes defined by attributesToIndex, - exact: sort according to the number of words that are matched identical to query word (and not as a prefix), - custom: sort according to a user defined formula set in **customRanking** attribute. The standard order is ["typo", "geo", "proximity", "attribute", "exact", "custom"] - customRanking: (array of strings) lets you specify part of the ranking. The syntax of this condition is an array of strings containing attributes prefixed by asc (ascending order) or desc (descending order) operator. For example `"customRanking" => ["desc(population)", "asc(name)"]` - queryType: Select how the query words are interpreted, it can be one of the following value: - prefixAll: all query words are interpreted as prefixes, - prefixLast: only the last word is interpreted as a prefix (default behavior), - prefixNone: no query word is interpreted as a prefix. This option is not recommended. - highlightPreTag: (string) Specify the string that is inserted before the highlighted parts in the query result (default to ""). - highlightPostTag: (string) Specify the string that is inserted after the highlighted parts in the query result (default to ""). - optionalWords: (array of strings) Specify a list of words that should be considered as optional when found in the query.
Throws:
AlgoliaException

listUserKeys

public org.json.JSONObject listUserKeys()
                                 throws AlgoliaException
List all existing user keys with their associated ACLs

Throws:
AlgoliaException

getUserKeyACL

public org.json.JSONObject getUserKeyACL(String key)
                                  throws AlgoliaException
Get ACL of a user key

Throws:
AlgoliaException

deleteUserKey

public org.json.JSONObject deleteUserKey(String key)
                                  throws AlgoliaException
Delete an existing user key

Throws:
AlgoliaException

addUserKey

public org.json.JSONObject addUserKey(List<String> acls)
                               throws AlgoliaException
Create a new user key

Parameters:
acls - the list of ACL for this key. Defined by an array of strings that can contains the following values: - search: allow to search (https and http) - addObject: allows to add/update an object in the index (https only) - deleteObject : allows to delete an existing object (https only) - deleteIndex : allows to delete index content (https only) - settings : allows to get index settings (https only) - editSettings : allows to change index settings (https only)
Throws:
AlgoliaException

updateUserKey

public org.json.JSONObject updateUserKey(String key,
                                         List<String> acls)
                                  throws AlgoliaException
Update a user key

Parameters:
acls - the list of ACL for this key. Defined by an array of strings that can contains the following values: - search: allow to search (https and http) - addObject: allows to add/update an object in the index (https only) - deleteObject : allows to delete an existing object (https only) - deleteIndex : allows to delete index content (https only) - settings : allows to get index settings (https only) - editSettings : allows to change index settings (https only)
Throws:
AlgoliaException

addUserKey

public org.json.JSONObject addUserKey(List<String> acls,
                                      int validity,
                                      int maxQueriesPerIPPerHour,
                                      int maxHitsPerQuery)
                               throws AlgoliaException
Create a new user key

Parameters:
acls - the list of ACL for this key. Defined by an array of strings that can contains the following values: - search: allow to search (https and http) - addObject: allows to add/update an object in the index (https only) - deleteObject : allows to delete an existing object (https only) - deleteIndex : allows to delete index content (https only) - settings : allows to get index settings (https only) - editSettings : allows to change index settings (https only)
validity - the number of seconds after which the key will be automatically removed (0 means no time limit for this key)
maxQueriesPerIPPerHour - Specify the maximum number of API calls allowed from an IP address per hour. Defaults to 0 (no rate limit).
maxHitsPerQuery - Specify the maximum number of hits this API key can retrieve in one call. Defaults to 0 (unlimited)
Throws:
AlgoliaException

updateUserKey

public org.json.JSONObject updateUserKey(String key,
                                         List<String> acls,
                                         int validity,
                                         int maxQueriesPerIPPerHour,
                                         int maxHitsPerQuery)
                                  throws AlgoliaException
Update a user key

Parameters:
acls - the list of ACL for this key. Defined by an array of strings that can contains the following values: - search: allow to search (https and http) - addObject: allows to add/update an object in the index (https only) - deleteObject : allows to delete an existing object (https only) - deleteIndex : allows to delete index content (https only) - settings : allows to get index settings (https only) - editSettings : allows to change index settings (https only)
validity - the number of seconds after which the key will be automatically removed (0 means no time limit for this key)
maxQueriesPerIPPerHour - Specify the maximum number of API calls allowed from an IP address per hour. Defaults to 0 (no rate limit).
maxHitsPerQuery - Specify the maximum number of hits this API key can retrieve in one call. Defaults to 0 (unlimited)
Throws:
AlgoliaException

searchDisjunctiveFaceting

public org.json.JSONObject searchDisjunctiveFaceting(Query query,
                                                     List<String> disjunctiveFacets,
                                                     Map<String,List<String>> refinements)
                                              throws AlgoliaException
Perform a search with disjunctive facets generating as many queries as number of disjunctive facets

Parameters:
query - the query
disjunctiveFacets - the array of disjunctive facets
refinements - Map> representing the current refinements ex: { "my_facet1" => ["my_value1", "my_value2"], "my_disjunctive_facet1" => ["my_value1", "my_value2"] }
Throws:
AlgoliaException

searchDisjunctiveFaceting

public org.json.JSONObject searchDisjunctiveFaceting(Query query,
                                                     List<String> disjunctiveFacets)
                                              throws AlgoliaException
Throws:
AlgoliaException


Copyright © 2015. All rights reserved.