You have unlimited access as a PRO member
You are receiving a free preview of 3 lessons
Your free preview as expired - please upgrade to PRO
Contents
Recent Posts
- Object Oriented Programming With TypeScript
- Angular Elements Advanced Techniques
- TypeScript - the Basics
- The Real State of JavaScript 2018
- Cloud Scheduler for Firebase Functions
- Testing Firestore Security Rules With the Emulator
- How to Use Git and Github
- Infinite Virtual Scroll With the Angular CDK
- Build a Group Chat With Firestore
- Async Await Pro Tips
Angular Full Text Search With Algolia Backend - Part 2
Episode 28 written by Jeff DelaneyIn the first Algolia Full Text Search lesson, I showed you how to quickly build a full text search interface with Algolia InstantSearch and Angular. In the second part, we will use Firebase Cloud Functions to create and maintain our own index with the realtime database.
Create a new Index in Algolia
The first step is to create a new index from the Algolia dashboard. Make a note of the name, which is books
in this example.
Database Design
In this example, we have a collection of books, and every book has an author and title.
-|books |
Preparing the NodeJS Environment
The cloud function needs the algoliasearch
package and environment variables for your Algolia API credentials. Make sure to use the admin API key.
cd functions |
Cloud Function - Indexing a Document
A document must be indexed before it can be searched. This function is invoked when a book is created or updated in the database. If the book does not have any data, it is deleted from the Algolia index.
const functions = require('firebase-functions'); |
Pretty simple! Algolia has many other indexing options available may be helpful if you need to index multiple documents in a single pass, or if you want to update individual properties in the index.
Update the Angular App
Back in Angular, we just need to change the indexName
in the options object that is passed to InstantSearch. This object can be updated in the environment file.
export const environment = { |
That’s it for Algolia with Firebase Cloud Functions.