If you’re looking to amplify your Firestore database’s search capabilities, the Firestore Firebase Typesense Search Extension is an excellent choice. This Firebase extension synchronizes your Firestore collection with Typesense, allowing you to perform full-text fuzzy search, filtering, faceting, sorting, and more. Let’s venture into the world of integrations!
What is Typesense?
Typesense is an open-source search engine designed for simplicity, scalability, and effective performance. Think of it as a user-friendly alternative to complex solutions like Algolia and ElasticSearch. For a quick overview, you can check out this guide.
Usage
Step 1⃣: Setup Prerequisites
Before diving into the installation, ensure you’ve met the following prerequisites:
- Set up a Cloud Firestore database in your Firebase project. Ensure your default cloud compute-based service account has the following roles:
- Artifact Registry Administrator
- Artifact Registry Create-on-Push Writer
- Artifact Registry Service Agent
- Logs Writer
- Storage Object Viewer
- Set up a Typesense cluster on Typesense Cloud or self-host it.
- Create a Typesense Collection. Remember, this extension won’t create it for you!
Step 2⃣: Install the Extension
You can install this extension either via the Firebase Web console or Firebase CLI:
Firebase Console
Install this extension in your Firebase project
Install via Firebase Console
Firebase CLI
bash firebase ext:install typesensefirestore-typesense-search --project=[your-project-id]
Refer to the Firebase Extensions documentation for additional installation guidance.
Syncing Multiple Firestore Collections
You can install this extension multiple times in your Firebase project by using different Firestore collection paths for each.
Configuration Parameters
Upon installation, you can configure the following parameters:
- Firestore Collection Path: The specific Firestore collection to index into Typesense.
- Firestore Collection Fields: A list of fields to index from each Firestore document.
- Flatten Nested Documents: Whether to flatten nested documents before indexing.
- Typesense Hosts: A list of Typesense Hosts.
- Typesense API Key: Admin permission API key from your Typesense cluster.
- Typesense Collection Name: Name of the Typesense collection to index data into.
- Cloud Functions location: Deployment location for created functions.
Step 3⃣: [Optional] Backfill Existing Data
To backfill existing Firestore data after the extension installation:
- Create a Firestore collection named
typesense_sync
. - Create a document with the ID
backfill
and set contents totrigger: true
. - You can specify which collections are backfilled by adjusting the document contents accordingly.
Cloud Functions
- indexOnWrite: Indexes data into Typesense when Firestore changes are detected.
- backfill: Backfills data from Firestore into Typesense.
Development Workflow
To test your setup:
shell
npm run emulator
npm run typesenseServer
Your local emulator will be accessible at http://localhost:4000
, and the local Typesense server at http://localhost:8108
.
Troubleshooting Common Issues
Here are some troubleshooting ideas for common issues you might encounter:
- My Typesense collection is empty: The extension only syncs data created after installation. Ensure to backfill data if needed.
- Missing records in Typesense: This may occur due to schema mismatches. Check Firestore documents against Typesense’s collection schema.
- The backfill function isn’t triggering: Ensure your backfill document is correctly formatted and set the
trigger
key totrue
to restart the function. - Conflicting collections: If you’ve set up this extension multiple times, ensure correct paths are specified for each instance.
For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.
Conclusion
Integrating Firestore with Typesense elevates your ability to search through data efficiently. By following the steps above, you’re on your way to unlocking powerful search capabilities.
At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.