MeiliSearch

Lightning Fast, Ultra Relevant, and Typo-Tolerant Search Engine Client written in Swift

Showing:

Popularity

Downloads/wk

0

GitHub Stars

53

Maintenance

Last Commit

2d ago

Contributors

14

Package

Dependencies

0

License

MIT

Categories

Readme

MeiliSearch-Swift

MeiliSearch Swift

MeiliSearch | Documentation | Slack | Roadmap | Website | FAQ

GitHub Workflow Status License Bors enabled

⚡ The MeiliSearch API client written for Swift 🍎

MeiliSearch Swift is the MeiliSearch API client for Swift developers.

MeiliSearch is an open-source search engine. Discover what MeiliSearch is!

Table of Contents

📖 Documentation

For more information about this API see our Swift documentation.

For more information about MeiliSearch see our Documentation or our API References.

🔧 Installation

With Cocoapods

CocoaPods is a dependency manager for Cocoa projects.

MeiliSearch-Swift is available through CocoaPods. To install it, add the following line to your Podfile:

pod 'MeiliSearch'

Then, run the following command:

pod install

This will download the latest version of MeiliSearch pod and prepare the xcworkspace.

With the Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler.

Once you have your Swift package set up, adding MeiliSearch-Swift as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .package(url: "https://github.com/meilisearch/meilisearch-swift.git")
]

🏃‍♀️ Run MeiliSearch

There are many easy ways to download and run a MeiliSearch instance.

For example, if you use Docker:

docker pull getmeili/meilisearch:latest # Fetch the latest version of MeiliSearch image from Docker Hub
docker run -it --rm -p 7700:7700 getmeili/meilisearch:latest ./meilisearch --master-key=masterKey

NB: you can also download MeiliSearch from Homebrew or APT.

🎬 Getting Started

To do a simply search using the client, you can create a Swift script like this:

Add documents

    import MeiliSearch

    // Create a new client instance of MeiliSearch.
    let client = try! MeiliSearch(host: "http://localhost:7700")

    struct Movie: Codable, Equatable {
        let id: Int
        let title: String
        let genres: [String]
    }

    let movies: [Movie] = [
        Movie(id: 1, title: "Carol", genres: ["Romance", "Drama"]),
        Movie(id: 2, title: "Wonder Woman", genres: ["Action", "Adventure"]),
        Movie(id: 3, title: "Life of Pi", genres: ["Adventure", "Drama"]),
        Movie(id: 4, title: "Mad Max: Fury Road", genres: ["Adventure", "Science Fiction"]),
        Movie(id: 5, title: "Moana", genres: ["Fantasy", "Action"]),
        Movie(id: 6, title: "Philadelphia", genres: ["Drama"])
    ]

    let semaphore = DispatchSemaphore(value: 0)

    // An index is where the documents are stored.
    // The uid is the unique identifier to that index.
    let indexUid = "movies"

    // If the index 'movies' does not exist, MeiliSearch creates it when you first add the documents.
    client.addDocuments(
        UID: indexUid,
        documents: movies,
        primaryKey: nil
    ) { result in
        switch result {
        case .success(let update):
            print(update) // => Update(updateId: 0)
        case .failure(let error):
            print(error.localizedDescription)
        }
        semaphore.signal()
      }
    semaphore.wait()

With the updateId, you can check the status (enqueued, processing, processed or failed) of your documents addition using the update endpoint.


let semaphore = DispatchSemaphore(value: 0)

// Typealias that represents the result from MeiliSearch.
typealias MeiliResult = Result<SearchResult<Movie>, Swift.Error>

// Call the function search and wait for the closure result.
client.search(UID: "movies", SearchParameters( query: "philoudelphia" )) { (result: MeiliResult) in
    switch result {
    case .success(let searchResult):
        dump(searchResult)
    case .failure(let error):
        print(error.localizedDescription)
    }
    semaphore.signal()
}
semaphore.wait()

Output:

 MeiliSearch.SearchResult<SwiftWork.(unknown context at $10d9e7f3c).Movie>
  ▿ hits: 1 element
    ▿ SwiftWork.(unknown context at $10d9e7f3c).Movie
      - id: 6
      - title: "Philadelphia"
      ▿ genres: 1 element
        - "Drama"
  - offset: 0
  - limit: 20
  - nbHits: 1
  ▿ exhaustiveNbHits: Optional(false)
    - some: false
  - facetsDistribution: nil
  - exhaustiveFacetsCount: nil
  ▿ processingTimeMs: Optional(1)
    - some: 1
  ▿ query: Optional("philoudelphia")
    - some: "philoudelphia"

Since MeiliSearch is typo-tolerant, the movie philadelphia is a valid search response to philoudelphia.

🤖 Compatibility with MeiliSearch

This package only guarantees the compatibility with the version v0.22.0 of MeiliSearch.

💡 Learn More

The following sections may interest you:

⚙️ Development Workflow and Contributing

Any new contribution is more than welcome in this project!

If you want to know more about the development workflow or want to contribute, please visit our contributing guidelines for detailed instructions!

📜 Demos

To try out a demo you will need to go to its directory in Demos/. In that directory you can either:

  • Open the SwiftPM project in Xcode and press run, or
  • Run swift build or swift run in the terminal.

Vapor

Please check the Vapor Demo source code here.

Perfect

Please check the Perfect Demo source code here.


MeiliSearch provides and maintains many SDKs and Integration tools like this one. We want to provide everyone with an amazing search experience for any kind of project. If you want to contribute, make suggestions, or just know what's going on right now, visit us in the integration-guides repository.

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100