Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Firestore のクエリと全文検索
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
miup
August 07, 2018
Programming
3.6k
7
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Firestore のクエリと全文検索
Firebase Meetup #5
miup
August 07, 2018
More Decks by miup
See All by miup
Algolia with Firebase
miup
2
1.5k
Firestore, Cloud Storage を用いた アプリ内での画像の扱い方
miup
5
25k
Firebase Cloud Messaging 入門編
miup
0
5.2k
The way of truly serverless application
miup
1
4.6k
Other Decks in Programming
See All in Programming
이 함수, 실패하면 어떻게 되나요? null부터 Rich Errors까지, Kotlin 에러 처리 15년
haeti2
0
130
Swift愛好会と私(ウホーイ) / Swift Fan Club and Uhooi
uhooi
0
120
リアルな遅延を測る仕様
kota_yata
1
140
What We Talk About When We Talk About XP
m_seki
2
340
LLMは4年分のCompose移行を再現できるのか?実プロダクト279件のXMLで探る自動化の境界線
makun
0
370
【DroidKaigi 2026】「アクセシビリティを利用するとき、 アクセシビリティもまたこちらを利用している」 〜マルウェアによる攻撃と防衛について〜
halunoyo
0
330
Press start. Python's next generation.
willingc
PRO
3
300
LL言語やWebフレームワークのPostgreSQL対応 〜DBの機能がユーザーに届くまで〜
kentaroutakeda
0
130
高専キャリア LT 発表内容
crysta1221
6
5.5k
高専、大学編入、そして未踏へ〜プロダクト開発とキャリアの歩み - Technical College, University Transfer, and On to “Mitou” / My Journey in Product Development and Career
pkmiya
0
130
型解析で実現する Go の言語内 DSL / Conference に Go! タイムテーブルの歩き方 for Gophers
mazrean
0
120
自分的「カンファレンスの楽しみ方」
syumai
0
190
Featured
See All Featured
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.6k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.6k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
1
390
Art, The Web, and Tiny UX
lynnandtonic
304
22k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
430
The browser strikes back
jonoalderson
0
1.6k
Optimising Largest Contentful Paint
csswizardry
37
3.9k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Building Flexible Design Systems
yeseniaperezcruz
330
41k
The Mindset for Success: Future Career Progression
greggifford
PRO
0
490
How to Ace a Technical Interview
jacobian
281
24k
Designing for Timeless Needs
cassininazir
1
470
Transcript
Cookpad Inc. Firestore ͷΫΤϦͱશจݕࡧ ࡾӜ
Cookpad Inc. All Rights Reserved. ࣗݾհ w໊લࡾӜ wܦྺ wCookpad 17৽ଔ
(Komerco ࣄۀ෦ wiOSྺ5 Firebase ྺ1ͪΐͬͱ wTwitter: __miup (ΞϯμʔείΞ2ຊʂ wGithub: miuP
Cookpad Inc. All Rights Reserved. ࠓ͢͜ͱ wFirestore ͷΫΤϦͰͰ͖Δ͜ͱ wFirestore ͷΫΤϦͰͰ͖ͳ͍͜ͱ
wղܾࡦ
Cookpad Inc. All Rights Reserved. Firestore ͷΫΤϦͰͰ͖Δ͜ͱ wsort worderBy wwhere
wisEqualTo wisLessThan (orEqualTo) wisGreaterThan (orEqualTo)
Cookpad Inc. All Rights Reserved. Firestore ͷΫΤϦͰͰ͖Δ͜ͱ wpaging wlimit wstartAfter,
endBefore (order ͍ͯ͠Δ, DocumentReference) wetc…
Cookpad Inc. All Rights Reserved. Firestore ͷΫΤϦͰͰ͖Δ͜ͱ 1ճͷΫΤϦͰ isLessThan ͱ
isGreaterThan 1ͭͷ Field ʹର͔ͯ͑͠͠ͳ͍ʂ ͨͩ͠ʂ ੍͕͋Δ
interface Product { name: string // ໊ price: number //
Ձ֨ stock: number // ࡏݿ isActive: boolean // ཧআ createdAt: firestore.Timestamp updatedAt: firestore.Timestamp }
Cookpad Inc. All Rights Reserved. Firestore ͷΫΤϦͰͰ͖Δ͜ͱ w୯ҰͷϑΟʔϧυʹର͢Δෳͷൣғൺֱ wෳͷϑΟʔϧυʹର͢ΔՁԋࢉࢠ wެ։தͷ5000ԁ~10000ԁͷࡏݿͷlͳ͍zΛऔಘ
const products = await admin.firestore().collection('products') .where('isActive', '==', true) .where(‘stock', '==',
0) .where('price', '<=', 10000) .where('price', ‘>=', 5000) .then(querySnapshot => { return querySnapshot.docs.map(doc => { ... }) })
Cookpad Inc. All Rights Reserved. Firestore ͷΫΤϦͰͰ͖Δ͜ͱ wෳͷϑΟʔϧυʹ·͕ͨΔΫΤϦ wΧελϜΠϯσοΫε͕ඞཁ ෳ߹ΠϯσοΫεΈ͍ͨͳͷʣ
wΫΤϦ͛ͯΤϥʔ͕ฦͬͯ͘Δͱ URL ͕ॻ͍ͯ͋ΔͷͰͦ͜ Λ౿Ί؆୯ʹઃఆͰ͖Δ
Cookpad Inc. All Rights Reserved. Firestore ͷΫΤϦͰͰ͖ͳ͍͜ͱ wશจݕࡧ -*,&
wisNotEqualTo (݁ߏͭΒ͍) wෳͷϑΟʔϧυʹର͢Δൣғൺֱ wެ։தͷ5000ԁ~10000ԁͷࡏݿͷl͋ΔzΛऔಘ
const products = await admin.firestore().collection('products') .where('isActive', '==', true) .where('stock', '>',
0) .where('price', '<=', 10000) .where('price', ‘>=', 5000) .then(querySnapshot => { return querySnapshot.docs.map(doc => { ... }) }) ❌
const products = await admin.firestore().collection('products') .where('isActive', '==', true) .where('stock', '!=',
0) .where('price', '<=', 10000) .where('price', ‘>=', 5000) .then(querySnapshot => { return querySnapshot.docs.map(doc => { ... }) }) ❌
Cookpad Inc. All Rights Reserved. Firestore ͷΫΤϦͰͰ͖ͳ͍͜ͱ wެ։தͷ5000ԁ~10000ԁͷࡏݿͷl͋ΔzΛऔಘ͕Ͱ͖ͳ͍ wશจݕࡧ͕Ͱ͖ͳ͍ ݁ߏݫ͍͠
Cookpad Inc. All Rights Reserved. Ͳ͏͢Εʜ
Cookpad Inc. All Rights Reserved. Algolia 4BB4ʹཔΖ͏ શจݕࡧʢincremental search) Λఏڙ͍ͯ͠Δ
SaaS iOS, Android, Web Ͱ SDK ఏڙ͞Ε͍ͯΔ ʢଞʹݕࡧ4BB4͋Δ͚Ͳެࣜʹ໊લ͕ग़͍ͯΔͷͰ"MHPMJBΛհ͠·͢ʣ
Cookpad Inc. All Rights Reserved. ྲྀΕ Cloud Firestore Cloud Functions
Algolia Save Document Event trigger Algolia API Search
algoliasearch(functions.config().algolia.app_id, functions.config().algolia.api_key) const productsIndex = algolia.default.initIndex('products') functions.firestore.document('products/{productID}').onCreate(async (snapshot, context) =>
{ const firProduct = new Tart.Snapshot<Firebase.Product>(snapshot) // আࡁΈͷొ͠ͳ͍ if (!firProduct.data.isActive) { return undefined } // Algolia ʹอଘ͢Δσʔλʹม(Reference Λ ID ʹ͢Δͱ͔͢Δ) 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 Firestore Cloud Functions
Algolia Save Document Event trigger Algolia API Search
Cookpad Inc. All Rights Reserved. ܕ͕ͳ͍ Algolia ݕࡧ݁Ռʹܕ͕ͳ͍ Swift Ͱॻ͘ͳΒܕ͕ཉ͍͠
Kotlin Ͱ Java Ͱ TypeScript Ͱಉ͚ͩ͡Ͳ
Cookpad Inc. All Rights Reserved. ϥΠϒϥϦ࡞ͬͨ
Cookpad Inc. All Rights Reserved. Algent Type Safe Algolia Search
Client for Swift https://github.com/miuP/Algent
Cookpad Inc. All Rights Reserved. ͍ํ wσʔλͷܕΛ࡞Δ wRequest Λ࡞Δ w͛Δ
struct User: Decodable { let objectID: String let name: String
let bio: String let isActive: Bool let followerCount: Int let followeeCount: Int let _tags: [String] }
struct SarchUserRequest: AlgoliaRequestProtocol { // set search result type 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 } init(page: Int, per: Int, text: String? = nil, hashtags: [String]? = nil) { self.page = page self.per = per self.text = text self.hashtags = hashtags } }
let request = SarchUserRequest(page: 0, per: 20, text: "", hashtags:
[]) Algent.shared.search(request: request) { result in switch result { case .success(let response): // response is AlgoliaResponse<Request.HitType> print(response.hits) // see hit object:[HitType] case .failure( let error): print(error) } }
Cookpad Inc. All Rights Reserved. ·ͱΊ wFirestore ͰͷΫΤϦ wൣғࢦఆΛҟͳΔFieldʹ͔͚ΒΕͳ͍ wisNotEqualTo
͕ͳ͍ wLIKEͱ͔શจݕࡧ͕Ͱ͖ͳ͍ wAlgolia w֎෦αʔϏεʹͳΔͷͰ࿈ܞ͕ඞཁ(Firebase ͷ༗ྉϓϥϯඞཁ) wAlgent ͬͯΈ͍ͯͩ͘͞