Index

@objcMembers
public class Index : NSObject, Searchable

A proxy to an Algolia index.

Note

You cannot construct this class directly. Please use Client.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) -> Operation

    Parameters

    object

    The object to add.

    requestOptions

    Request-specific options.

    completionHandler

    Completion 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) -> Operation

    Parameters

    object

    The object to add.

    objectID

    Identifier that you want to assign this object.

    requestOptions

    Request-specific options.

    completionHandler

    Completion 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) -> Operation

    Parameters

    objects

    Objects to add.

    requestOptions

    Request-specific options.

    completionHandler

    Completion 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) -> Operation

    Parameters

    objectID

    Identifier of object to delete.

    requestOptions

    Request-specific options.

    completionHandler

    Completion 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) -> Operation

    Parameters

    objectIDs

    Identifiers of objects to delete.

    requestOptions

    Request-specific options.

    completionHandler

    Completion 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) -> Operation

    Parameters

    objectID

    Identifier of the object to retrieve.

    attributesToRetrieve

    List of attributes to retrieve. If nil, all attributes are retrieved. If one of the elements is "*", all attributes are retrieved.

    requestOptions

    Request-specific options.

    completionHandler

    Completion 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) -> Operation

    Parameters

    objectIDs

    Identifiers of objects to retrieve.

    attributesToRetrieve

    List of attributes to retrieve. If nil, all attributes are retrieved. If one of the elements is "*", all attributes are retrieved.

    requestOptions

    Request-specific options.

    completionHandler

    Completion 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) -> Operation

    Parameters

    partialObject

    New values/operations for the object.

    objectID

    Identifier of object to be updated.

    createIfNotExists

    Whether an update on a nonexistent object ID should create the object.

    requestOptions

    Request-specific options.

    completionHandler

    Completion 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) -> Operation

    Parameters

    objects

    New values/operations for the objects. Each object must contain an objectID attribute.

    createIfNotExists

    Whether an update on a nonexistent object ID should create the object.

    requestOptions

    Request-specific options.

    completionHandler

    Completion 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) -> Operation

    Parameters

    object

    New version of the object to update. Must contain an objectID attribute.

    requestOptions

    Request-specific options.

    completionHandler

    Completion 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) -> Operation

    Parameters

    objects

    New versions of the objects to update. Each one must contain an objectID attribute.

    requestOptions

    Request-specific options.

    completionHandler

    Completion 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) -> Operation

    Parameters

    query

    Search parameters.

    requestOptions

    Request-specific options.

    completionHandler

    Completion 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) -> Operation

    Parameters

    facetName

    Name of the facet to search. It must have been declared in the index’s attributesForFaceting setting with the searchable() modifier.

    text

    Text to search for in the facet’s values.

    query

    An 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.

    requestOptions

    Request-specific options.

    completionHandler

    Completion 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) -> Operation

    Parameters

    requestOptions

    Request-specific options.

    completionHandler

    Completion 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) -> Operation

    Parameters

    settings

    New settings.

    forwardToReplicas

    When true, the change is also applied to replicas of this index.

    requestOptions

    Request-specific options.

    completionHandler

    Completion 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) -> Operation

    Parameters

    requestOptions

    Request-specific options.

    completionHandler

    Completion 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) -> Operation

    Parameters

    operations

    The array of actions.

    requestOptions

    Request-specific options.

    completionHandler

    Completion 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 browseFrom with that cursor.

    Declaration

    Swift

    @discardableResult
    @objc(browseWithQuery:requestOptions:completionHandler:)
    public func browse(query: Query, requestOptions: RequestOptions? = nil, completionHandler: @escaping CompletionHandler) -> Operation

    Parameters

    query

    The query parameters for the browse.

    requestOptions

    Request-specific options.

    completionHandler

    Completion 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) -> Operation

    Parameters

    cursor

    The cursor of the next page to retrieve

    requestOptions

    Request-specific options.

    completionHandler

    Completion 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) -> Operation

    Parameters

    taskID

    Identifier of the task (as returned by the server).

    requestOptions

    Request-specific options.

    completionHandler

    Completion 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) -> Operation

    Parameters

    query

    The query that objects to delete must match.

    requestOptions

    Request-specific options.

    completionHandler

    Completion 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) -> Operation

    Parameters

    query

    The query that objects to delete must match.

    requestOptions

    Request-specific options.

    completionHandler

    Completion 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) -> Operation

    Parameters

    query

    The query.

    disjunctiveFacets

    List of disjunctive facets.

    refinements

    The current refinements, mapping facet names to a list of values.

    requestOptions

    Request-specific options.

    completionHandler

    Completion 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) -> Operation

    Parameters

    queries

    The queries to run.

    requestOptions

    Request-specific options.

    completionHandler

    Completion 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) -> Operation

    Parameters

    queries

    The queries to run.

    strategy

    The strategy to use.

    requestOptions

    Request-specific options.

    completionHandler

    Completion 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()