⚡ 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.
- Complete full API wrapper
- Easy to install, deploy, and maintain
- Highly customizable
- No external dependencies
- Thread safe
- Uses Codable
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")
]
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"
}
}
The current functions implemented are:
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 |
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 |
Swift function |
Similar to API call |
search(UID:_:_) |
GET - /indexes/:index_uid/search |
Swift function |
Similar to API call |
getUpdate(UID:_:_) |
GET - /indexes/:index_uid/updates/:updateId |
getAllUpdates(UID:_) |
GET - /indexes/:index_uid/updates |
Swift function |
Similar to API call |
keys(masterKey:_) |
GET - /keys |
getAllUpdates(UID:_) |
GET - /indexes/:index_uid/updates |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
Swift function |
Similar to API call |
stat(UID:_) |
GET - /indexes/:index_uid/stats |
allStats(:_) |
GET - /stats |
Swift function |
Similar to API call |
health(:_) |
GET - /health |
updateHealth(health:_) |
PUT - /health |
Swift function |
Similar to API call |
version(:_) |
GET - /version |
Swift function |
Similar to API call |
prettySystemInfo(:_) |
GET - /sys-info/pretty |
systemInfo(:_) |
GET - /sys-info |
Please check the Vapor Demo source code here.
Please check the Perfect Demo source code here.
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!
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