MeiliSearch

public struct MeiliSearch

A MeiliSearch instance represents a MeiliSearch client used to easily integrate your Swift product with the MeiliSearch server.

Warning

MeiliSearch instances are thread safe and can be shared across threads or dispatch queues.

Initializers

  • Create an instance of MeiliSearch client.

    Declaration

    Swift

    public init(host: String, apiKey: String? = nil, session: URLSessionProtocol? = nil, request: Request? = nil) throws

    Parameters

    host

    The host to the MeiliSearch http server.

    apiKey

    The authorisation key to communicate with MeiliSearch.

    session

    A custom produced URLSessionProtocol.

Index

  • Create an instance of Index.

    Declaration

    Swift

    public func index(_ uid: String) -> Indexes

    Parameters

    uid

    The unique identifier for the Index to be created.

  • Create a new index.

    Declaration

    Swift

    public func createIndex(
      uid: String,
      primaryKey: String? = nil,
      _ completion: @escaping (Result<Indexes, Swift.Error>) -> Void)

    Parameters

    uid

    The unique identifier for the Index to be created.

    primaryKey

    the unique field of a document.

    completion

    The completion closure used to notify when the server completes the write request, it returns a Result object that contains Index value. If the request was sucessful or Error if a failure occured.

  • Undocumented

    Declaration

    Swift

    public func getOrCreateIndex(
      uid: String,
      primaryKey: String? = nil,
      _ completion: @escaping (Result<Indexes, Swift.Error>) -> Void)
  • Get an index.

    Declaration

    Swift

    public func getIndex(
      _ uid: String,
      _ completion: @escaping (Result<Indexes, Swift.Error>) -> Void)

    Parameters

    uid

    The unique identifier for the Index to be found.

    completion

    The completion closure used to notify when the server completes the query request, it returns a Result object that contains Index value. If the request was sucessful or Error if a failure occured.

  • List all indexes.

    Declaration

    Swift

    public func getIndexes(
      _ completion: @escaping (Result<[Indexes], Swift.Error>) -> Void)

    Parameters

    completion

    The completion closure used to notify when the server completes the query request, it returns a Result object that contains [Index] value. If the request was sucessful or Error if a failure occured.

  • Update the primaryKey of the index.

    Declaration

    Swift

    public func updateIndex(
      uid: String,
      primaryKey: String,
      _ completion: @escaping (Result<Indexes, Swift.Error>) -> Void)

    Parameters

    uid

    The unique identifier of the index

    primaryKey

    the unique field of a document.

    completion

    The completion closure used to notify when the server completes the update request, it returns a Result object that contains () value. If the request was sucessful or Error if a failure occured.

  • Delete an index.

    Declaration

    Swift

    public func deleteIndex(
      _ uid: String,
      _ completion: @escaping (Result<(), Swift.Error>) -> Void)

    Parameters

    uid

    The unique identifier of the index.

    completion

    The completion closure used to notify when the server completes the delete request, it returns a Result object that contains () value. If the request was sucessful or Error if a failure occured.

Keys

  • Each instance of MeiliSearch has three keys: a master, a private, and a public. Each key has a given set of permissions on the API routes.

    Declaration

    Swift

    public func keys(
      _ completion: @escaping (Result<Key, Swift.Error>) -> Void)

    Parameters

    masterKey

    Master key to access the keys function.

    completion

    The completion closure used to notify when the server completes the query request, it returns a Result object that contains Key value. If the request was sucessful or Error if a failure occured.

Stats

  • Get stats of all indexes.

    Declaration

    Swift

    public func allStats(
      _ completion: @escaping (Result<AllStats, Swift.Error>) -> Void)

    Parameters

    completion

    The completion closure used to notify when the server completes the query request, it returns a Result object that contains AllStats value. If the request was sucessful or Error if a failure occured.

System

  • Get health of MeiliSearch server.

    Declaration

    Swift

    public func health(_ completion: @escaping (Result<Health, Swift.Error>) -> Void)

    Parameters

    completion

    The completion closure used to notify when the server completes the query request, it returns a Result object that contains Health value. If the request was sucessful or Error if a failure occured.

  • Get health of MeiliSearch server.

    Declaration

    Swift

    public func isHealthy(_ completion: @escaping (Bool) -> Void)

    Parameters

    completion

    The completion closure used to notify when the server completes the query request, it returns a Bool that is true If the request was sucessful or false if a failure occured.

  • Get version of MeiliSearch.

    Declaration

    Swift

    public func version(
      _ completion: @escaping (Result<Version, Swift.Error>) -> Void)

    Parameters

    completion

    The completion closure used to notify when the server completes the query request, it returns a Result object that contains Version value. If the request was sucessful or Error if a failure occured.

  • Triggers a dump creation process. Once the process is complete, a dump is created in the dumps folder. If the dumps folder does not exist yet, it will be created.

    Declaration

    Swift

    public func createDump(_ completion: @escaping (Result<Dump, Swift.Error>) -> Void)

    Parameters

    completion

    The completion closure used to notify when the server completes the dump request, it returns a Dump object that contains uid value that can be used later to check the status of the dump. If the request was successful or Error if a failure occurred.

  • Get the status of a dump creation process using the uid returned after calling the dump creation route. The returned status could be:

    Dump.Status.inProgress: Dump creation is in progress. Dump.Status.failed: An error occurred during the dump process, and the task was aborted. Dump.Status.done: Dump creation is finished and was successful.

    Declaration

    Swift

    public func getDumpStatus(
      _ uid: String,
      _ completion: @escaping (Result<Dump, Swift.Error>) -> Void)

    Parameters

    completion

    The completion closure used to notify when the server completes the dump request, it returns a Dump object that contains uid value that can be used later to check the status of the Dump. If the request was successful or Error if a failure occurred.

Error

  • Undocumented

    See more

    Declaration

    Swift

    struct MSErrorResponse : Decodable, Encodable, Equatable
  • Undocumented

    Declaration

    Swift

    static func errorHandler(url: URL, data: Data?, response: URLResponse?, error: Swift.Error?) throws
  • Generic Error types for MeiliSearch,

    See more

    Declaration

    Swift

    enum Error : Swift.Error, LocalizedError, Equatable