All Projects → algolia → Algoliasearch Client Swift

algolia / Algoliasearch Client Swift

Licence: mit
⚡️ A fully-featured and blazing-fast Swift API client to interact with Algolia.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Algoliasearch Client Swift

Algoliasearch Magento
Algolia Search integration for Magento 1 - compatible with versions from 1.6.x to 1.9.x
Stars: ✭ 163 (-1.81%)
Mutual labels:  algolia, search
Algoliasearch Client Android
Algolia Search API Client for Android
Stars: ✭ 92 (-44.58%)
Mutual labels:  algolia, search
Github Awesome Autocomplete
Add instant search capabilities to GitHub's search bar
Stars: ✭ 1,015 (+511.45%)
Mutual labels:  algolia, search
Gatsby Plugin Algolia
A plugin to push to Algolia based on graphQl queries
Stars: ✭ 154 (-7.23%)
Mutual labels:  algolia, search
Algoliasearch Client Python
⚡️ A fully-featured and blazing-fast Python API client to interact with Algolia.
Stars: ✭ 138 (-16.87%)
Mutual labels:  algolia, search
Vue Instantsearch
👀 Algolia components for building search UIs with Vue.js
Stars: ✭ 707 (+325.9%)
Mutual labels:  algolia, search
Autocomplete
🔮 Fast and full-featured autocomplete library
Stars: ✭ 1,268 (+663.86%)
Mutual labels:  algolia, search
Awesome Algolia
🔍👋 START HERE! A curated list of Algolia libraries, resources and projects.
Stars: ✭ 475 (+186.14%)
Mutual labels:  algolia, search
Algoliasearch Magento 2
Algolia Search integration for Magento 2 - compatible with versions from 2.3.x to 2.4.x
Stars: ✭ 131 (-21.08%)
Mutual labels:  algolia, search
Instantsearch Android
A library of widgets and helpers to build instant-search applications on Android.
Stars: ✭ 129 (-22.29%)
Mutual labels:  algolia, search
Algoliasearch Client Php
⚡️ A fully-featured and blazing-fast PHP API client to interact with Algolia.
Stars: ✭ 565 (+240.36%)
Mutual labels:  algolia, search
Algoliasearch Helper Js
Helper for implementing advanced search features with Algolia
Stars: ✭ 147 (-11.45%)
Mutual labels:  algolia, search
Jekyll Theme Basically Basic
Your new Jekyll default theme
Stars: ✭ 524 (+215.66%)
Mutual labels:  algolia, search
Algoliasearch Client Javascript
⚡️ A fully-featured and blazing-fast JavaScript API client to interact with Algolia.
Stars: ✭ 907 (+446.39%)
Mutual labels:  algolia, search
Instantsearch Ios
⚡️ A library of widgets and helpers to build instant-search applications on iOS.
Stars: ✭ 498 (+200%)
Mutual labels:  algolia, search
Instantsearch Ios Examples
Example apps built with InstantSearch iOS
Stars: ✭ 55 (-66.87%)
Mutual labels:  algolia, search
Docsearch Configs
DocSearch - Configurations
Stars: ✭ 339 (+104.22%)
Mutual labels:  algolia, search
Algoliasearch Rails
AlgoliaSearch integration to your favorite ORM
Stars: ✭ 352 (+112.05%)
Mutual labels:  algolia, search
React Instantsearch
⚡️ Lightning-fast search for React and React Native applications, by Algolia.
Stars: ✭ 1,320 (+695.18%)
Mutual labels:  algolia, search
Docsearch
📘 The easiest way to add search to your documentation.
Stars: ✭ 2,266 (+1265.06%)
Mutual labels:  algolia, search

Algolia for Swift

The perfect starting point to integrate Algolia within your Swift project

DocumentationCommunity ForumStack OverflowReport a bugFAQSupport

✨ Features

  • Pure cross-platform Swift client
  • Typed requests and responses
  • Widespread use of Result type
  • Uses the power of Codable protocol for easy integration of your domain models
  • Thread-safe clients
  • Detailed logging
  • Injectable HTTP client

Install

Swift Package Manager

The Swift Package Manager is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies. Since the release of Swift 5 and Xcode 11, SPM is compatible with the iOS, macOS and tvOS build systems for creating apps.

To use SwiftPM, you should use Xcode 11 to open your project. Click File -> Swift Packages -> Add Package Dependency, enter InstantSearch repo's URL.

If you're a framework author and use Swift API Client as a dependency, update your Package.swift file:

let package = Package(
    // 8.8.0 ..< 9.0.0
    dependencies: [
        .package(url: "https://github.com/algolia/algoliasearch-client-swift", from: "8.8.0")
    ],
    // ...
)

Add import AlgoliaSearchClient to your source files.

Cocoapods

CocoaPods is a dependency manager for Cocoa projects.

To install Algolia Swift Client, simply add the following line to your Podfile:

pod 'AlgoliaSearchClient', '~> 8.8'
# pod 'InstantSearchClient', '~> 6.0' // Swift 4.2
# pod 'InstantSearchClient', '~> 5.0' // Swift 4.1

Then, run the following command:

$ pod update

Carthage

Carthage is a simple, decentralized dependency manager for Cocoa.

  • To install InstantSearch, simply add the following line to your Cartfile:
github "algolia/algoliasearch-client-swift" ~> 8.8
# github "algolia/algoliasearch-client-swift" ~> 6.0.0 // Swift 4.2
# github "algolia/algoliasearch-client-swift" ~> 5.0.0 // Swift 4.1
  • Launch the following commands from the project directory (for v.8.0+)
carthage update
./Carthage/Checkouts/algoliasearch-client-swift/carthage-prebuild
carthage build

If this is your first time using Carthage in the project, you'll need to go through some additional steps as explained over at Carthage.

💡 Getting Started

Initialize the client

To start, you need to initialize the client. To do this, you need your Application ID and API Key. You can find both on your Algolia account.

let client = Client(appID: "YourApplicationID", apiKey: "YourAdminAPIKey")
let index = client.index(withName: "your_index_name")

Push data

Without any prior configuration, you can start indexing contacts in the contacts index using the following code:

struct Contact: Encodable {
  let firstname: String
  let lastname: String
  let followers: Int
  let company: String
}

let contacts: [Contact] = [
  .init(firstname: "Jimmie", lastname: "Barninger", followers: 93, company: "California Paint"),
  .init(firstname: "Warren", lastname: "Speach", followers: 42, company: "Norwalk Crmc")
]

let index = client.index(withName: "contacts")
index.saveObjects(contacts, autoGeneratingObjectID: true) { result in
  if case .success(let response) = result {
    print("Response: \(response)")
  }
}

Search

You can now search for contacts by firstname, lastname, company, etc. (even with typos):

index.search(query: "jimmie") { result in
  switch result {
  case .failure(let error):
    print("Error: \(error)")
  case .success(let response):
    print("Response: \(response)")
    do {
      let foundContacts: [Contact] = try response.extractsHits()
      print("Found contacts: \(foundContacts)")
    } catch let error {
      print("Contact parsing error: \(error)")
    }
  }
}

Configure

Settings can be customized to tune the search behavior. For example, you can add a custom sort by number of followers to the already great built-in relevance:

let settings = Settings()
  .set(\.customRanking, to: [.desc("followers")])
index.setSettings(settings) { result in
  if case .failure(let error) = result {
    print("Error when applying settings: \(error)")
  }
}

You can also configure the list of attributes you want to index by order of importance (first = most important):

Note: Since the engine is designed to suggest results as you type, you'll generally search by prefix. In this case the order of attributes is very important to decide which hit is the best:

let settings = Settings()
  .set(\.searchableAttributes, to: ["lastname", "firstname", "company"])
index.setSettings(settings) { result in
  if case .failure(let error) = result {
    print("Error when applying settings: \(error)")
  }
}

For full documentation, visit the Algolia Swift API Client's documentation.

📝 Examples

You can find code samples in the Algolia's API Clients playground.

Use the Dockerfile

If you want to contribute to this project without installing all its dependencies, you can use our Docker image. Please check our dedicated guide to learn more.

📄 License

Algolia Swift API Client is an open-sourced software licensed under the MIT license.

Notes

Objective-C support

The Swift API client is compatible with Objective-C up to version 7.0.5. Please use this version of the client if you're working with an Objective-C project.

Swift 3

You can use this library with Swift by one of the following ways:

  • pod 'AlgoliaSearch-Client-Swift', '~> 4.8.1'
  • pod 'AlgoliaSearch-Client-Swift', :git => 'https://github.com/algolia/algoliasearch-client-swift.git', :branch => 'swift-3'

Getting Help

  • Need help? Ask a question to the Algolia Community or on Stack Overflow.
  • Encountering an issue? Before reaching out to support, we recommend heading to our FAQ where you will find answers for the most common issues and gotchas with the client.
  • Found a bug? You can open a GitHub issue.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].