/meilisearch-swift

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

Primary LanguageSwiftMIT LicenseMIT

MeiliSearch-Swift

MeiliSearch-Swift

Build Status License Slack

⚡ Lightning Fast, Ultra Relevant, and Typo-Tolerant Search Engine MeiliSearch client written in Swift 🍎

MeiliSearch-Swift is a client for MeiliSearch written in Swift. MeiliSearch is a powerful, fast, open-source, easy to use and deploy search engine. Both searching and indexing are highly customizable. Features such as typo-tolerance, filters, and synonyms are provided out-of-the-box. For more information about features go to our Swift documentation.

Features

  • Complete full API wrapper
  • Easy to install, deploy, and maintain
  • Highly customizable
  • No external dependencies
  • Thread safe
  • Uses Codable

Get started

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")
]

Basic setup

Make sure to firstly setup your MeiliSearch server. Please follow this getting started here.

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

import MeiliSearch

func searchForMovies() {

    // Create a new client instance of MeiliSearch with the default host.
    let client = try! MeiliSearch()

    // Create a new search request with "botman" as query.
    let searchParameters = SearchParameters.query("botman")
    
    // Typealias that represents the result from Meili.
    typealias MeiliResult = Result<SearchResult<Movie>, Swift.Error>

    // Call the function search and wait for the closure result.
    self.client.search(UID: "movies", searchParameters) { (result: MeiliResult) in
        switch result {
        case .success(let searchResult):
            print(searchResult)
        case .failure(let error):
            print(error)
        }
    }

}

private struct Movie: Codable, Equatable {

    let id: Int
    let title: String
    let poster: String
    let overview: String
    let releaseDate: Date

    enum CodingKeys: String, CodingKey {
        case id
        case title
        case poster
        case overview
        case releaseDate = "release_date"
    }

}

Functions

The current functions implemented are:

Index

Swift function Similar to API call
createIndex(UID:_) POST - /indexes
getIndex(UID:_) GET - /indexes/:index_uid
getIndexes(:_) GET - /indexes
updateIndex(UID:_) POST - /indexes/:index_uid
deleteIndex(UID:_) DELETE - /indexes/:index_uid

Documents

Swift function Similar to API call
addOrReplaceDocument(UID:document:primaryKey:_) POST - /indexes/:index_uid/documents
addOrUpdateDocument(UID:document:primaryKey:_) PUT - /indexes/:index_uid/documents
getDocument(UID:identifier:_) GET - /indexes/:index_uid/documents/:document_id
getDocuments(UID:limit:_) GET - /indexes/:index_uid/documents
deleteDocument(UID:identifier:_) DELETE - /indexes/:index_uid/documents/:document_id
deleteAllDocuments(UID:_) DELETE - /indexes/:index_uid/documents
deleteBatchDocuments(UID:documentsUID:_) POST - /indexes/:index_uid/documents/delete-batch

Search

Swift function Similar to API call
search(UID:_:_) GET - /indexes/:index_uid/search

Updates

Swift function Similar to API call
getUpdate(UID:_:_) GET - /indexes/:index_uid/updates/:updateId
getAllUpdates(UID:_) GET - /indexes/:index_uid/updates

Keys

Swift function Similar to API call
keys(masterKey:_) GET - /keys
getAllUpdates(UID:_) GET - /indexes/:index_uid/updates

Settings

All Settings

Swift function Similar to API call
getSetting(UID:_) GET - /indexes/:index_uid/settings
updateSetting(UID:_:_) POST - /indexes/:index_uid/settings
resetSetting(UID:_) DELETE - /indexes/:index_uid/settings

Synonyms

Swift function Similar to API call
getSynonyms(UID:_) GET - /indexes/:index_uid/settings/synonyms
updateSynonyms(UID:_:_) POST - /indexes/:index_uid/settings/synonyms
resetSynonyms(UID:_) DELETE - /indexes/:index_uid/settings/synonyms

Stop-words

Swift function Similar to API call
getStopWords(UID:_) GET - /indexes/:index_uid/settings/stop-words
updateStopWords(UID:_:_) POST - /indexes/:index_uid/settings/stop-words
resetStopWords(UID:_) DELETE - /indexes/:index_uid/settings/stop-words

Ranking rules

Swift function Similar to API call
getRankingRules(UID:_) GET - /indexes/:index_uid/settings/ranking-rules
updateRankingRules(UID:_:_) POST - /indexes/:index_uid/settings/ranking-rules
resetRankingRules(UID:_) DELETE - /indexes/:index_uid/settings/ranking-rules

Distinct attribute

Swift function Similar to API call
getDistinctAttribute(UID:_) GET - /indexes/:index_uid/settings/distinct-attribute
updateDistinctAttribute(UID:_:_) POST - /indexes/:index_uid/settings/distinct-attribute
resetDistinctAttribute(UID:_) DELETE - /indexes/:index_uid/settings/distinct-attribute

Searchable attributes

Swift function Similar to API call
getSearchableAttributes(UID:_) GET - /indexes/:index_uid/settings/searchable-attributes
updateSearchableAttributes(UID:_:_) POST - /indexes/:index_uid/settings/searchable-attributes
resetSearchableAttributes(UID:_) DELETE - /indexes/:index_uid/settings/searchable-attributes

Displayed attributes

Swift function Similar to API call
getDisplayedAttributes(UID:_) GET - /indexes/:index_uid/settings/displayed-attributes
updateDisplayedAttributes(UID:_:_) POST - /indexes/:index_uid/settings/displayed-attributes
resetDisplayedAttributes(UID:_) DELETE - /indexes/:index_uid/settings/displayed-attributes

Accept new fields

Swift function Similar to API call
getAcceptNewFields(UID:_) GET - /indexes/:index_uid/settings/accept-new-fields
updateAcceptNewFields(UID:_:_) POST - /indexes/:index_uid/settings/accept-new-fields

Stats

Swift function Similar to API call
stat(UID:_) GET - /indexes/:index_uid/stats
allStats(:_) GET - /stats

Health

Swift function Similar to API call
health(:_) GET - /health
updateHealth(health:_) PUT - /health

Version

Swift function Similar to API call
version(:_) GET - /version

System information

Swift function Similar to API call
prettySystemInfo(:_) GET - /sys-info/pretty
systemInfo(:_) GET - /sys-info

Demo

Vapor

Please check the Vapor Demo source code here.

Perfect

Please check the Perfect Demo source code here.

Contributing

Hey! We're glad you're thinking about contributing to MeiliSearch-Swift! If you think something is missing or could be improved, please open issues and pull requests. If you'd like to help this project grow, we'd love to have you! To start contributing, checking issues tagged as "good-first-issue" is a good start!

Contact

Feel free to contact us about any questions you may have:

Any suggestion or feedback is highly appreciated. Thank you for your support!

Swift programming language from Apple