You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Add search result model with implementing decodable
classDiary:Decodable{lettitle:Stringlettext:String
// Algolia hash tag info
_tags:[String]}
Add search request class with implementing AlgoliaRequestProtocol
structSearchDiaryRequest:AlgoliaRequestProtocol{
// set search result type
typealiasHitType=Diaryletpage:Intletper:Intlettext:String?lethashtags:[String]?varindexName:String{return"diaries"}varquery:AlgentQuery{letquery=AlgentQuery(query: text)
query.page =UInt(page)
query.hitsPerPage =UInt(per)iflet 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.
letrequest=SarchDiaryRequest(page:0, per:20, text:"hello world", hashtags:["trip"])Algent.shared.search(request: request){ result inswitch 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: