Skip to content
Swift Library for appbase.io and ElasticSearch
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Carthage
Documentation
Sources
SwiftElasticSearch iOSTests
SwiftElasticSearch macOSTests
SwiftElasticSearch.xcodeproj
SwiftSearch.xcworkspace
Cartfile
Cartfile.resolved
LICENSE
Package.swift
README.md

README.md

Appbase-Swift

A Swift Client Library for building search apps. Supports appbase.io and ElasticSearch.

Table of Contents

  1. About Project
  2. Installation
  3. Quick Start
  4. Docs

About Project

This project aims to create fast responsive Swift Library, supported for IPhone and Mac apps which provides the functionality of Elastic Search to be integrated in the app.

The library provides very high performance results i.e. it provides response to user queries in milliseconds of time including the elastic search processing time.

Installation

Dynamic Framework (Simplest way)

  • Download the latest release of SwiftElasticSearch from Github and extract the zip

  • Navigate to your Xcode's project General settings (Click on the the blue icon showing your project's workspace -> General)

  • Drag the SwiftElasticSearch.xcodeproj file from the extracted folder in the Embedded Binaries section and select the Copy items if needed checkbox in the prompted dialog box (if it appears) and click Finish

  • Go to Linked Frameworks and Libraries section and click on the + icon

  • Click on the SwiftElasticSearch.framework to add it to dependencies

  • Build the project

Here is the GIF showing all the above steps in action -

Demo GIF

Carthage

Carthage is a decentralized dependency manager that builds dependencies and provides binary frameworks for direct use.

To install Carthage, use Homebrew package manager and write the following commands :

$ brew update
$ brew install carthage

To integrate SwiftElasticSearch in your Xcode project :

  • Switch to your project directory in terminal

  • Now make a Cartfile using command :

touch Cartfile
  • Now open the Cartfile using command :
open Cartfile
  • Add the following dependency in your Cartfile :
github "appbaseio-apps/SwiftElasticSearch" ~> <Release Version>

The current latest Release Version is 0.1.0

  • Run carthage update to build the framework

  • Drag the SwiftElasticSearch.framework file that is generated inside Build folder of Carthage to your Xcode project

  • Build the project

Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler. It is in early development, but ElasticSwift does support its use on supported platforms.

To add SwiftElasticSearch library as dependency, add the following line in the dependencies value of Package.swift :

dependencies: [
.Package(url: "https://github.com/harsh-2711/SwiftElasticSearch.git", "0.1.0")
]

Quick Start

Working code example. Please note that each step is dependent on previous step.

Step 1: Import library and initiate the SwiftElasticSearch client

import SwiftElasticSearch

// app and authentication configurations
let HOST_URL = "https://scalr.api.appbase.io"
let APPNAME = "SwiftClientES"
let CREDENTIALS = "9MrI8sWhQ:7cf68f3b-51f7-45c0-973f-f3e85ad10f4b"

let client = Client.init(url: HOST_URL, app: APPNAME, credentials: CREDENTIALS)

Step 2: Add some data into the app

// Index some movie names

client.index(type: "SwiftClientES", id: "movie1", body: ["title" : "Iron Man"]) { (json, response, error) in
  // json - provides recieved JSON body
  // response - provides the received response from the server
  // error - provides the error encountered if any

  print(json!)
}

Console Output

{
    "_id" = movie1;
    "_index" = SwiftClientES;
    "_shards" =     {
        failed = 0;
        successful = 2;
        total = 2;
    };
    "_type" = SwiftClientES;
    "_version" = 2;
    created = 0;
    result = updated;
}

Step 3: Get the posted data

client.get(type: "SwiftClientES", id: "movie1") { (json, response, error) in
    print(json!)
}

Console output

{
    "_id" = movie1;
    "_index" = SwiftClientES;
    "_source" =     {
        title = "Iron Man";
    };
    "_type" = SwiftClientES;
    "_version" = 2;
    found = 1;
}

Docs

The documentation of SwiftElasticSearch library is made with the help of Jazzy library. For contributing to the documentation of this library, follow the given steps:

  • Make the necessary changes in the inline code comments
  • If you haven't, install jazzy library by typing the following command in the terminal:
[sudo] gem install jazzy
  • After installing, navigate to the project directory and type the following to generate the docs.
jazzy

For more functionalities like skipping specific files or folders, refer to documentation of the Jazzy library:

  • Now add and commit the changes and then submit a pull request :-)

Hosted docs of SwiftElasticSearch library are available at https://swift-elasticsearch.netlify.com

You can’t perform that action at this time.