Skip to content

miup/Algent

Repository files navigation

Algent

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 SearchDiaryRequest: 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.

About

Type safe algolia search swift wrapper

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •