Slide 1

Slide 1 text

Cookpad Inc. Algolia with Firebase Kazuya Miura

Slide 2

Slide 2 text

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 Ͱษڧத

Slide 3

Slide 3 text

Cookpad Inc. All Rights Reserved. Agenda wࣗݾ঺հ wKomerco ʹ͍ͭͯ wͳͥ Algolia Λ࢖͏Α͏ʹͳ͔ͬͨ wAlgolia ͱ Firebase ͷ࿈ܞ wOSS w·ͱΊ

Slide 4

Slide 4 text

Cookpad Inc. All Rights Reserved. About Komerco

Slide 5

Slide 5 text

Cookpad Inc. All Rights Reserved.

Slide 6

Slide 6 text

Cookpad Inc. All Rights Reserved. ։ൃϝϯόʔʢ্ཱͪ͛࣌ʣ wσΟϨΫλʔ wσβΠφʔ wΤϯδχΞ(iOS) wΤϯδχΞ(iOS) wΤϯδχΞ(iOS) αʔόʔαΠυΈΜͳॻ͚ͳ͍
 Πϯϑϥ΋͋·ΓΘ͔Βͳ͍

Slide 7

Slide 7 text

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 Λϑϧʹ׆༻ͨ͠ΞϓϦ

Slide 8

Slide 8 text

Cookpad Inc. All Rights Reserved. Firestore

Slide 9

Slide 9 text

Cookpad Inc. All Rights Reserved. Firestore wDocument-oriented database (NoSQL) wτϥϯβΫγϣϯɺόονॻ͖ࠐΈΛαϙʔτ wϦΞϧλΠϜ

Slide 10

Slide 10 text

Cookpad Inc. All Rights Reserved. Firestore ͷΫΤϦ wͰ͖Δ͜ͱ͕গͳ͍ w!=ԋࢉࢠ͕ͳ͍ wҰͭͷΫΤϦͰෳ਺ͷΧϥϜʹରͯ͠>=΍<=౳Λ࢖͑ͳ͍ wOR ͕ͳ͍ wLIKE ͕ͳ͍ ؆୯ͳ͜ͱ͸Ͱ͖Δ͚Ͳ
 ೉͍͜͠ͱ͕Ͱ͖ͳ͍

Slide 11

Slide 11 text

Cookpad Inc. All Rights Reserved. ެࣜʹιϦϡʔγϣϯ͕͋ͬͨ

Slide 12

Slide 12 text

Cookpad Inc. All Rights Reserved. Firestore ͷΫΤϦ Firebase ެࣜʹҊ಺͕͋ͬͨͷ͕͖͔͚ͬͰ࠾༻ ManagedͳαʔϏεʹ೚ͤΒΕΔͷ͸ॿ͔Δ Algolia ͍ͬͯ͏ͷΛ࢖͏ͱྑ͍Β͍͠ https://firebase.google.com/docs/firestore/solutions/search?hl=ja

Slide 13

Slide 13 text

Cookpad Inc. All Rights Reserved. ࢖͏͔͠ͳ͍ʂ

Slide 14

Slide 14 text

Cookpad Inc. All Rights Reserved. ࣮ࡍʹ࢖͍ͬͯΔͱ͜Ζ wΧελϚʔΞϓϦʮ͕͢͞ʯը໘ wFacet Filter wTag Filter wNumeric Filter wReplica wSynonym

Slide 15

Slide 15 text

Cookpad Inc. All Rights Reserved. ࣮૷ͷ͓࿩

Slide 16

Slide 16 text

Cookpad Inc. All Rights Reserved. Firebase ͱͷ࿈ܞ

Slide 17

Slide 17 text

Cookpad Inc. All Rights Reserved. ྲྀΕ Cloud Firestore Cloud Functions Algolia Save Indexing Trigger Search

Slide 18

Slide 18 text

Cookpad Inc. All Rights Reserved. Cloud Functions export const productCreated = functions .firestore .document('products/{productID}') .onCreate(async (snapshot, context) => { const firProduct = snapshot.data() })

Slide 19

Slide 19 text

Cookpad Inc. All Rights Reserved. ྲྀΕ Cloud Firestore Cloud Functions Algolia Save Indexing Trigger Search

Slide 20

Slide 20 text

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) } }) }) }

Slide 21

Slide 21 text

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) })

Slide 22

Slide 22 text

Cookpad Inc. All Rights Reserved. Index Λߋ৽͢ΔλΠϛϯά " ͋ΔΦϒδΣΫτʹߋ৽͕͔͔ͬͨͱ͖ # ఆظతʹ࣮ߦ͢Δ

Slide 23

Slide 23 text

Cookpad Inc. All Rights Reserved. Index Λߋ৽͢ΔλΠϛϯά wKomerco Ͱ͸౎౓ߋ৽ͷΈΛ͍ͯ͠Δ wKomerco Ͱ͸·ͩͦΜͳʹ৘ใߋ৽ͷස౓͕ߴ͘ͳ͍ͷͰAPI ίʔϧͷճ਺͕গͳ͍ wCloud Functions ࣗମ͸ఆظ࣮ߦͷ࢓૊Έ͕͋ΔͷͰߋ৽ස౓͕ ૿͖͑ͯͨΒҠߦ༧ఆ

Slide 24

Slide 24 text

Cookpad Inc. All Rights Reserved. Index ͷઃఆ

Slide 25

Slide 25 text

Cookpad Inc. All Rights Reserved. Index ͷઃఆ wݕࡧՄೳͳkeyΛઃఆ wෳ਺ͷSortΛ͢ΔͳΒReplicaΛ࡞੒ wΧςΰϦ෼͚Λ͢ΔͳΒFacet attributeΛઃఆ wSynonymͷઃఆ

Slide 26

Slide 26 text

Cookpad Inc. All Rights Reserved. Searchable attributes

Slide 27

Slide 27 text

Cookpad Inc. All Rights Reserved. Index ͷઃఆ wݕࡧՄೳͳkeyΛઃఆ wෳ਺ͷSortΛ͢ΔͳΒReplicaΛ࡞੒ wΧςΰϦ෼͚Λ͢ΔͳΒFacet attributeΛઃఆ wSynonymͷઃఆ

Slide 28

Slide 28 text

Cookpad Inc. All Rights Reserved. Replica

Slide 29

Slide 29 text

Cookpad Inc. All Rights Reserved. Replica

Slide 30

Slide 30 text

Cookpad Inc. All Rights Reserved. Index ͷઃఆ wݕࡧՄೳͳkeyΛઃఆ wෳ਺ͷSortΛ͢ΔͳΒReplicaΛ࡞੒ wΧςΰϦ෼͚Λ͢ΔͳΒFacet attributeΛઃఆ wSynonymͷઃఆ

Slide 31

Slide 31 text

Cookpad Inc. All Rights Reserved. Facet attribute

Slide 32

Slide 32 text

Cookpad Inc. All Rights Reserved. Index ͷઃఆ wݕࡧՄೳͳkeyΛઃఆ wෳ਺ͷSortΛ͢ΔͳΒReplicaΛ࡞੒ wΧςΰϦ෼͚Λ͢ΔͳΒFacet attributeΛઃఆ wSynonymͷઃఆ

Slide 33

Slide 33 text

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, …ʯ

Slide 34

Slide 34 text

Cookpad Inc. All Rights Reserved. ΞϓϦ͔Βͷݕࡧ

Slide 35

Slide 35 text

Cookpad Inc. All Rights Reserved. ྲྀΕ Cloud Firestore Cloud Functions Algolia 4BWF *OEFYJOH 5SJHHFS 4FBSDI

Slide 36

Slide 36 text

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)") } }

Slide 37

Slide 37 text

Cookpad Inc. All Rights Reserved. ܕ͕ͳ͍ Algolia ݕࡧ݁Ռʹܕ͕ͳ͍ʢ͖ͬ͞ͷresponse͕ [String: Any]ʣ
 Swift Ͱॻ͘ͳΒܕ͕ཉ͍͠
 Kotlin Ͱ΋ Java Ͱ΋ TypeScript Ͱ΋ಉ͚ͩ͡Ͳ

Slide 38

Slide 38 text

Cookpad Inc. All Rights Reserved. ϥΠϒϥϦ࡞ͬͨ

Slide 39

Slide 39 text

Cookpad Inc. All Rights Reserved. Algent Type safe Algolia search client for Swift. (Compatible with Swift5)
 https://github.com/miuP/Algent

Slide 40

Slide 40 text

Cookpad Inc. All Rights Reserved. ࢖͍ํ wσʔλͷܕΛ࡞Δ wRequest Λ࡞Δ wIndex ໊ wΫΤϦͷ಺༰ w౤͛Δ

Slide 41

Slide 41 text

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] }

Slide 42

Slide 42 text

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 } }

Slide 43

Slide 43 text

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 print(response.hits) // see hit object case .failure( let error): print(error) } }

Slide 44

Slide 44 text

Cookpad Inc. All Rights Reserved. ݕࡧͰ͖ͨ

Slide 45

Slide 45 text

Cookpad Inc. All Rights Reserved. ·ͱΊ wKomerco Ͱͳͥ Algolia Λ࢖͍ͬͯΔͷ͔ wSaaS Λ͏·͘ར༻ͯ͠Πϯϑϥ΍αʔόαΠυʹ
 ϦιʔεΛׂ͔ͣʹߴ଎ʹαʔϏε։ൃΛਐΊ͔ͨͬͨ wFirebaseΛ࢖͍ͬͯͯ΋ Cloud Functions Ͱ࿈ܞͰ͖Δ wiOS SDK ͷϥούʔͱͳΔ OSS ࡞ͬͨͷͰ࢖ͬͯΈ͍ͯͩ͘͞