Latest 0.4.0
Homepage https://github.com/miup/Algent
License MIT
Platforms ios 10.0
Dependencies InstantSearchClient, Result
Authors

CI Status
Version
License
Platform

Algent is a type safe algolia wrapper library.

You can use algolia with Swift decodable type as a search result.

Example

To run the example project, clone the repo, and run pod install from the Example directory first.
Open AppDelegate.swift and set your AlgoliaSearch AppID and APIKey.

Algent.initialize(appID: "YOUR_APP_ID", apiKey: "YOUR_API_KEY")

custom search

Add search result model with implementing decodable

class Diary: Decodable {
    let title: String
    let text: String
    // Algolia hash tag info
    _tags: [String]
}

Add search request class with implementing AlgoliaRequestProtocol

struct SarchDiaryRequest: AlgoliaRequestProtocol {
    // set search result type
    typealias HitType = Diary

    let page: Int
    let per: Int
    let text: String?
    let hashtags: [String]?

    var indexName: String {
        return "diaries"
    }

    var query: AlgentQuery {
        let query = AlgentQuery(query: text)
        query.page = UInt(page)
        query.hitsPerPage = UInt(per)
        if let hashtags = hashtags {
            query.tagFilters = hashtags
        }
        return query
    }

    init(page: Int, per: Int, text: String? = nil, hashtags: [String]? = nil) {
        self.page = page
        self.per = per
        self.text = text
        self.hashtags = hashtags
    }
}

Call Algent search method using your request.

let request = SarchDiaryRequest(page: 0, per: 20, text: "hello world", hashtags: ["trip"])
Algent.shared.search(request: request) { result in
    switch result {
    case .success(let response):
        // response is AlgoliaResponse<Request.HitType>
        print(response.hits) // see hit object
    case .failure( let error):
        print(error) // get error
    }
}

Requirements

Installation

Algent is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'Algent'

Author

miup, [email protected]

License

Algent is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "Algent",
    "version": "0.4.0",
    "summary": "Algent is a wrapper of Algolia search client for iOS.",
    "description": "Algent is a wrapper of Algolia search client for iOS.nIf you need more infomation, look https://github.com/miup/Algent.git.",
    "homepage": "https://github.com/miup/Algent",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "miup": "[email protected]"
    },
    "source": {
        "git": "https://github.com/miup/Algent.git",
        "tag": "0.4.0"
    },
    "platforms": {
        "ios": "10.0"
    },
    "source_files": "Algent/Classes/**/*",
    "dependencies": {
        "InstantSearchClient": [
            "~> 5.4"
        ],
        "Result": []
    }
}

Pin It on Pinterest

Share This