Share
Embed
Transcript
45 slides
-
Cookpad Inc. All Rights Reserved. About me wࡾӜʢΈ͏ͽʔʣ wCookpad৽ଔ3 wLanguage:
Japanese, Swift, Typescript wTwitter: __miup wGithub: miuP wHobby: Fishing, Snowboard, Guitar, Drive wݕࡧʹ͍ͭͯ Algolia Ͱษڧத -
Cookpad Inc. All Rights Reserved. Agenda wࣗݾհ wKomerco ʹ͍ͭͯ wͳͥ
Algolia Λ͏Α͏ʹͳ͔ͬͨ wAlgolia ͱ Firebase ͷ࿈ܞ wOSS w·ͱΊ -
Cookpad Inc. All Rights Reserved. ։ൃϝϯόʔʢ্ཱͪ͛࣌ʣ wσΟϨΫλʔ wσβΠφʔ wΤϯδχΞ(iOS) wΤϯδχΞ(iOS)
wΤϯδχΞ(iOS) αʔόʔαΠυΈΜͳॻ͚ͳ͍ Πϯϑϥ͋·ΓΘ͔Βͳ͍ -
Cookpad Inc. All Rights Reserved. About Komerco Auth, Firestore, Storage,
Hosting, CloudFunctions, Crashlytics, Analytics, Performance Monitoring Predictions, A/B Testing, Cloud Messaging, Remote Config, Dynamic Links Firebase Λϑϧʹ׆༻ͨ͠ΞϓϦ -
Cookpad Inc. All Rights Reserved. Firestore ͷΫΤϦ wͰ͖Δ͜ͱ͕গͳ͍ w!=ԋࢉࢠ͕ͳ͍ wҰͭͷΫΤϦͰෳͷΧϥϜʹରͯ͠>=<=Λ͑ͳ͍
wOR ͕ͳ͍ wLIKE ͕ͳ͍ ؆୯ͳ͜ͱͰ͖Δ͚Ͳ ͍͜͠ͱ͕Ͱ͖ͳ͍ -
Cookpad Inc. All Rights Reserved. Firestore ͷΫΤϦ Firebase ެࣜʹҊ͕͋ͬͨͷ͕͖͔͚ͬͰ࠾༻ ManagedͳαʔϏεʹͤΒΕΔͷॿ͔Δ
Algolia ͍ͬͯ͏ͷΛ͏ͱྑ͍Β͍͠ https://firebase.google.com/docs/firestore/solutions/search?hl=ja -
Cookpad Inc. All Rights Reserved. ࣮ࡍʹ͍ͬͯΔͱ͜Ζ wΧελϚʔΞϓϦʮ͕͢͞ʯը໘ wFacet Filter wTag
Filter wNumeric Filter wReplica wSynonym -
Cookpad Inc. All Rights Reserved. ྲྀΕ Cloud Firestore Cloud Functions
Algolia Save Indexing Trigger Search -
Cookpad Inc. All Rights Reserved. Cloud Functions export const productCreated
= functions .firestore .document('products/{productID}') .onCreate(async (snapshot, context) => { const firProduct = snapshot.data() }) -
Cookpad Inc. All Rights Reserved. ྲྀΕ Cloud Firestore Cloud Functions
Algolia Save Indexing Trigger Search -
Cookpad Inc. All Rights Reserved. Cloud Functions algoliasearch(functions.config().algolia.app_id, functions.config().algolia.api_key) const
productsIndex = algolia.default.initIndex('products') async function indexProduct(firProduct: Firebase.Product) { const product = new Product(firProduct) return new Promise((resolve, reject) => { productsIndex.addObject(product, async (error, response) => { if (error) { throw error } else { resolve(response) } }) }) } -
Cookpad Inc. All Rights Reserved. Cloud Functions export const productCreated
= functions .firestore .document('products/{productID}') .onCreate(async (snapshot, context) => { const firProduct = snapshot.data() await indexProduct(firProduct) }) -
Cookpad Inc. All Rights Reserved. Index Λߋ৽͢ΔλΠϛϯά wKomerco Ͱߋ৽ͷΈΛ͍ͯ͠Δ wKomerco
Ͱ·ͩͦΜͳʹใߋ৽ͷස͕ߴ͘ͳ͍ͷͰAPI ίʔϧͷճ͕গͳ͍ wCloud Functions ࣗମఆظ࣮ߦͷΈ͕͋ΔͷͰߋ৽ස͕ ૿͖͑ͯͨΒҠߦ༧ఆ -
Cookpad Inc. All Rights Reserved. Index ͷઃఆ wݕࡧՄೳͳkeyΛઃఆ wෳͷSortΛ͢ΔͳΒReplicaΛ࡞ wΧςΰϦ͚Λ͢ΔͳΒFacet
attributeΛઃఆ wSynonymͷઃఆ -
Cookpad Inc. All Rights Reserved. Index ͷઃఆ wݕࡧՄೳͳkeyΛઃఆ wෳͷSortΛ͢ΔͳΒReplicaΛ࡞ wΧςΰϦ͚Λ͢ΔͳΒFacet
attributeΛઃఆ wSynonymͷઃఆ -
Cookpad Inc. All Rights Reserved. Index ͷઃఆ wݕࡧՄೳͳkeyΛઃఆ wෳͷSortΛ͢ΔͳΒReplicaΛ࡞ wΧςΰϦ͚Λ͢ΔͳΒFacet
attributeΛઃఆ wSynonymͷઃఆ -
Cookpad Inc. All Rights Reserved. Index ͷઃఆ wݕࡧՄೳͳkeyΛઃఆ wෳͷSortΛ͢ΔͳΒReplicaΛ࡞ wΧςΰϦ͚Λ͢ΔͳΒFacet
attributeΛઃఆ wSynonymͷઃఆ -
Cookpad Inc. All Rights Reserved. Synonym wಉٛޠ wʮφεɺࢠɺͳ͢ʯʮΰʔϠɺʹ͕͏Γʯ ͦΕͧΕಉ͡Α͏ͳ݁ՌΛग़͍ͨ͠ wछྨ͕͍͔ͭ͋͘Δ
wOne-way Synonym =>ʮ͏ͭΘ>ಃثɺ࣓ثʯ wAlternate Correction => λΠϙΛڐ͢ One-way Synonym wPlaceholder =>ʮiPhone 7 => iPhone XS, iPhone 6 Plus, …ʯ -
Cookpad Inc. All Rights Reserved. ྲྀΕ Cloud Firestore Cloud Functions
Algolia 4BWF *OEFYJOH 5SJHHFS 4FBSDI -
Cookpad Inc. All Rights Reserved. Algolia SDK let client =
Client(appID: "YourApplicationID", apiKey: "YourAPIKey") let index = client.index(withName: "users") index.search(Query(query: "tarou")) { (response, error) in if let response = response { print("Result: \(response)") } } -
Cookpad Inc. All Rights Reserved. ܕ͕ͳ͍ Algolia ݕࡧ݁Ռʹܕ͕ͳ͍ʢ͖ͬ͞ͷresponse͕ [String: Any]ʣ
Swift Ͱॻ͘ͳΒܕ͕ཉ͍͠ Kotlin Ͱ Java Ͱ TypeScript Ͱಉ͚ͩ͡Ͳ -
Cookpad Inc. All Rights Reserved. Algent Type safe Algolia search
client for Swift. (Compatible with Swift5) https://github.com/miuP/Algent -
Cookpad Inc. All Rights Reserved. Data Type struct User: Decodable
{ let objectID: String let name: String let bio: String let followerCount: Int let followeeCount: Int let _tags: [String] } -
Cookpad Inc. All Rights Reserved. Request struct SarchUserRequest: AlgoliaRequestProtocol {
typealias HitType = User let page: Int let per: Int let text: String? let hashtags: [String]? var indexName: String { return "user" } 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 } } -
Cookpad Inc. All Rights Reserved. Search let request = SarchUserRequest(page:
0, per: 20, text: "", hashtags: []) Algent.shared.search(request: request) { result in switch result { case .success(let response): // AlgoliaResponse<Request.HitType> print(response.hits) // see hit object case .failure( let error): print(error) } } -
Cookpad Inc. All Rights Reserved. ·ͱΊ wKomerco Ͱͳͥ Algolia Λ͍ͬͯΔͷ͔
wSaaS Λ͏·͘ར༻ͯ͠ΠϯϑϥαʔόαΠυʹ ϦιʔεΛׂ͔ͣʹߴʹαʔϏε։ൃΛਐΊ͔ͨͬͨ wFirebaseΛ͍ͬͯͯ Cloud Functions Ͱ࿈ܞͰ͖Δ wiOS SDK ͷϥούʔͱͳΔ OSS ࡞ͬͨͷͰͬͯΈ͍ͯͩ͘͞