Index
@objcMembers
public class Index : NSObject, Searchable
A proxy to an Algolia index.
Note
You cannot construct this class directly. Please useClient.index(withName:) to obtain an instance.
-
This index’s name.
Declaration
Swift
@objc public let name: String -
API client used by this index.
Declaration
Swift
@objc public let client: Client
-
Add an object to this index.
Declaration
Swift
@discardableResult @objc public func addObject(_ object: [String: Any], requestOptions: RequestOptions? = nil, completionHandler: CompletionHandler? = nil) -> OperationParameters
objectThe object to add.
requestOptionsRequest-specific options.
completionHandlerCompletion handler to be notified of the request’s outcome.
Return Value
A cancellable operation.
-
Add an object to this index, assigning it the specified object ID. If an object already exists with the same object ID, the existing object will be overwritten.
Warning
Deprecated, use addObject(_:) instead.Declaration
Swift
@discardableResult @objc public func addObject(_ object: [String: Any], withID objectID: String, requestOptions: RequestOptions? = nil, completionHandler: CompletionHandler? = nil) -> OperationParameters
objectThe object to add.
objectIDIdentifier that you want to assign this object.
requestOptionsRequest-specific options.
completionHandlerCompletion handler to be notified of the request’s outcome.
Return Value
A cancellable operation.
-
Add several objects to this index.
Declaration
Swift
@discardableResult @objc public func addObjects(_ objects: [[String: Any]], requestOptions: RequestOptions? = nil, completionHandler: CompletionHandler? = nil) -> OperationParameters
objectsObjects to add.
requestOptionsRequest-specific options.
completionHandlerCompletion handler to be notified of the request’s outcome.
Return Value
A cancellable operation.
-
Delete an object from this index.
Declaration
Swift
@discardableResult @objc public func deleteObject(withID objectID: String, requestOptions: RequestOptions? = nil, completionHandler: CompletionHandler? = nil) -> OperationParameters
objectIDIdentifier of object to delete.
requestOptionsRequest-specific options.
completionHandlerCompletion handler to be notified of the request’s outcome.
Return Value
A cancellable operation.
-
Delete several objects from this index.
Declaration
Swift
@discardableResult @objc public func deleteObjects(withIDs objectIDs: [String], requestOptions: RequestOptions? = nil, completionHandler: CompletionHandler? = nil) -> OperationParameters
objectIDsIdentifiers of objects to delete.
requestOptionsRequest-specific options.
completionHandlerCompletion handler to be notified of the request’s outcome.
Return Value
A cancellable operation.
-
Get an object from this index, optionally restricting the retrieved content.
Declaration
Swift
@discardableResult @objc public func getObject(withID objectID: String, attributesToRetrieve: [String]? = nil, requestOptions: RequestOptions? = nil, completionHandler: @escaping CompletionHandler) -> OperationParameters
objectIDIdentifier of the object to retrieve.
attributesToRetrieveList of attributes to retrieve. If
nil, all attributes are retrieved. If one of the elements is"*", all attributes are retrieved.requestOptionsRequest-specific options.
completionHandlerCompletion handler to be notified of the request’s outcome.
Return Value
A cancellable operation.
-
Get several objects from this index, optionally restricting the retrieved content.
Declaration
Swift
@discardableResult @objc public func getObjects(withIDs objectIDs: [String], attributesToRetrieve: [String]? = nil, requestOptions: RequestOptions? = nil, completionHandler: @escaping CompletionHandler) -> OperationParameters
objectIDsIdentifiers of objects to retrieve.
attributesToRetrieveList of attributes to retrieve. If
nil, all attributes are retrieved. If one of the elements is"*", all attributes are retrieved.requestOptionsRequest-specific options.
completionHandlerCompletion handler to be notified of the request’s outcome.
Return Value
A cancellable operation.
-
Partially update an object.
Declaration
Swift
@discardableResult public func partialUpdateObject(_ partialObject: [String: Any], withID objectID: String, createIfNotExists: Bool? = nil, requestOptions: RequestOptions? = nil, completionHandler: CompletionHandler? = nil) -> OperationParameters
partialObjectNew values/operations for the object.
objectIDIdentifier of object to be updated.
createIfNotExistsWhether an update on a nonexistent object ID should create the object.
requestOptionsRequest-specific options.
completionHandlerCompletion handler to be notified of the request’s outcome.
Return Value
A cancellable operation.
-
Partially update several objects.
Declaration
Swift
@discardableResult public func partialUpdateObjects(_ objects: [[String: Any]], createIfNotExists: Bool? = nil, requestOptions: RequestOptions? = nil, completionHandler: CompletionHandler? = nil) -> OperationParameters
objectsNew values/operations for the objects. Each object must contain an
objectIDattribute.createIfNotExistsWhether an update on a nonexistent object ID should create the object.
requestOptionsRequest-specific options.
completionHandlerCompletion handler to be notified of the request’s outcome.
Return Value
A cancellable operation.
-
Update an object.
Declaration
Swift
@discardableResult @objc public func saveObject(_ object: [String: Any], requestOptions: RequestOptions? = nil, completionHandler: CompletionHandler? = nil) -> OperationParameters
objectNew version of the object to update. Must contain an
objectIDattribute.requestOptionsRequest-specific options.
completionHandlerCompletion handler to be notified of the request’s outcome.
Return Value
A cancellable operation.
-
Update several objects.
Declaration
Swift
@discardableResult @objc public func saveObjects(_ objects: [[String: Any]], requestOptions: RequestOptions? = nil, completionHandler: CompletionHandler? = nil) -> OperationParameters
objectsNew versions of the objects to update. Each one must contain an
objectIDattribute.requestOptionsRequest-specific options.
completionHandlerCompletion handler to be notified of the request’s outcome.
Return Value
A cancellable operation.
-
Search this index.
Declaration
Swift
@discardableResult @objc public func search(_ query: Query, requestOptions: RequestOptions? = nil, completionHandler: @escaping CompletionHandler) -> OperationParameters
querySearch parameters.
requestOptionsRequest-specific options.
completionHandlerCompletion handler to be notified of the request’s outcome.
Return Value
A cancellable operation.
-
Search for facet values. This searches inside a facet’s values, optionally restricting the returned values to those contained in objects matching other (regular) search criteria.
Declaration
Swift
@discardableResult public func searchForFacetValues(of facetName: String, matching text: String, query: Query? = nil, requestOptions: RequestOptions? = nil, completionHandler: @escaping CompletionHandler) -> OperationParameters
facetNameName of the facet to search. It must have been declared in the index’s
attributesForFacetingsetting with thesearchable()modifier.textText to search for in the facet’s values.
queryAn optional query to take extra search parameters into account. These parameters apply to index objects like in a regular search query. Only facet values contained in the matched objects will be returned.
requestOptionsRequest-specific options.
completionHandlerCompletion handler to be notified of the request’s outcome.
Return Value
A cancellable operation.
-
Get this index’s settings.
Declaration
Swift
@discardableResult @objc(getSettingsWithRequestOptions:completionHandler:) public func getSettings(requestOptions: RequestOptions? = nil, completionHandler: @escaping CompletionHandler) -> OperationParameters
requestOptionsRequest-specific options.
completionHandlerCompletion handler to be notified of the request’s outcome.
Return Value
A cancellable operation.
-
Set this index’s settings, optionally forwarding the change to replicas.
Please refer to our API documentation for the list of supported settings.
Declaration
Swift
@discardableResult public func setSettings(_ settings: [String: Any], forwardToReplicas: Bool? = nil, requestOptions: RequestOptions? = nil, completionHandler: CompletionHandler? = nil) -> OperationParameters
settingsNew settings.
forwardToReplicasWhen true, the change is also applied to replicas of this index.
requestOptionsRequest-specific options.
completionHandlerCompletion handler to be notified of the request’s outcome.
Return Value
A cancellable operation.
-
Delete the index content without removing settings and index specific API keys.
Declaration
Swift
@discardableResult @objc(clearIndexWithRequestOptions:completionHandler:) public func clearIndex(requestOptions: RequestOptions? = nil, completionHandler: CompletionHandler? = nil) -> OperationParameters
requestOptionsRequest-specific options.
completionHandlerCompletion handler to be notified of the request’s outcome.
Return Value
A cancellable operation.
-
Batch operations.
Declaration
Swift
@discardableResult @objc(batchOperations:requestOptions:completionHandler:) public func batch(operations: [[String: Any]], requestOptions: RequestOptions? = nil, completionHandler: CompletionHandler? = nil) -> OperationParameters
operationsThe array of actions.
requestOptionsRequest-specific options.
completionHandlerCompletion handler to be notified of the request’s outcome.
Return Value
A cancellable operation.
-
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
browseFromwith that cursor.Declaration
Swift
@discardableResult @objc(browseWithQuery:requestOptions:completionHandler:) public func browse(query: Query, requestOptions: RequestOptions? = nil, completionHandler: @escaping CompletionHandler) -> OperationParameters
queryThe query parameters for the browse.
requestOptionsRequest-specific options.
completionHandlerCompletion handler to be notified of the request’s outcome.
Return Value
A cancellable operation.
-
Browse the index from a cursor. This method should be called after an initial call to
browse(). It returns a cursor, unless the end of the index has been reached.Declaration
Swift
@discardableResult @objc(browseFromCursor:requestOptions:completionHandler:) public func browse(from cursor: String, requestOptions: RequestOptions? = nil, completionHandler: @escaping CompletionHandler) -> OperationParameters
cursorThe cursor of the next page to retrieve
requestOptionsRequest-specific options.
completionHandlerCompletion handler to be notified of the request’s outcome.
Return Value
A cancellable operation.
-
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.
Declaration
Swift
@discardableResult @objc public func waitTask(withID taskID: Int, requestOptions: RequestOptions? = nil, completionHandler: @escaping CompletionHandler) -> OperationParameters
taskIDIdentifier of the task (as returned by the server).
requestOptionsRequest-specific options.
completionHandlerCompletion handler to be notified of the request’s outcome.
Return Value
A cancellable operation.
-
Delete all objects matching a query.
Declaration
Swift
@discardableResult @objc public func deleteBy(_ query: Query, requestOptions: RequestOptions? = nil, completionHandler: CompletionHandler? = nil) -> OperationParameters
queryThe query that objects to delete must match.
requestOptionsRequest-specific options.
completionHandlerCompletion handler to be notified of the request’s outcome.
Return Value
A cancellable operation.
-
Delete all objects matching a query (helper).
Warning
Deprecated, use deleteBy instead.Declaration
Swift
@discardableResult @objc public func deleteByQuery(_ query: Query, requestOptions: RequestOptions? = nil, completionHandler: CompletionHandler? = nil) -> OperationParameters
queryThe query that objects to delete must match.
requestOptionsRequest-specific options.
completionHandlerCompletion handler to be notified of the request’s outcome.
Return Value
A cancellable operation.
-
Perform a search with disjunctive facets, generating as many queries as number of disjunctive facets (helper).
Declaration
Swift
@discardableResult @objc public func searchDisjunctiveFaceting(_ query: Query, disjunctiveFacets: [String], refinements: [String: [String]], requestOptions: RequestOptions? = nil, completionHandler: @escaping CompletionHandler) -> OperationParameters
queryThe query.
disjunctiveFacetsList of disjunctive facets.
refinementsThe current refinements, mapping facet names to a list of values.
requestOptionsRequest-specific options.
completionHandlerCompletion handler to be notified of the request’s outcome.
Return Value
A cancellable operation.
-
Run multiple queries on this index. This method is a variant of
Client.multipleQueries(...)where the targeted index is always the receiver.Declaration
Swift
@discardableResult @objc public func multipleQueries(_ queries: [Query], strategy: String?, requestOptions: RequestOptions? = nil, completionHandler: @escaping CompletionHandler) -> OperationParameters
queriesThe queries to run.
requestOptionsRequest-specific options.
completionHandlerCompletion handler to be notified of the request’s outcome.
Return Value
A cancellable operation.
-
Run multiple queries on this index. This method is a variant of
Client.multipleQueries(...)where the targeted index is always the receiver.Declaration
Swift
@discardableResult public func multipleQueries(_ queries: [Query], strategy: Client.MultipleQueriesStrategy? = nil, requestOptions: RequestOptions? = nil, completionHandler: @escaping CompletionHandler) -> OperationParameters
queriesThe queries to run.
strategyThe strategy to use.
requestOptionsRequest-specific options.
completionHandlerCompletion handler to be notified of the request’s outcome.
Return Value
A cancellable operation.
-
Whether the search cache is enabled on this index. Default:
false.Declaration
Swift
@objc public var searchCacheEnabled: Bool { get set } -
Expiration delay for items in the search cache. Default: 2 minutes.
Note
The delay is a minimum threshold. Items may survive longer in cache.Declaration
Swift
@objc public var searchCacheExpiringTimeInterval: TimeInterval { get set } -
Clear the search cache.
Declaration
Swift
@objc public func clearSearchCache()
Index Class Reference