• Stars
    star
    122
  • Rank 282,319 (Top 6 %)
  • Language
    JavaScript
  • License
    Apache License 2.0
  • Created almost 3 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Firebase Extension to automatically push Firestore documents to Typesense for full-text search with typo tolerance, faceting, and more

Firestore / Firebase Typesense Search Extension ⚡ 🔍

CircleCI

A Firebase extension to sync data from your Firestore collection to Typesense, to be able to do full-text fuzzy search on your Firestore data, with typo tolerance, faceting, filtering, sorting, curation, synonyms, geosearch and more.

This extension listens to your specified Firestore collection and syncs Firestore documents to Typesense on creation, updates and deletes. It also provides a function to help you backfill data.

What is Typesense?

If you're new to Typesense, it is an open source search engine that is simple to use, run and scale, with clean APIs and documentation. Think of it as an open source alternative to Algolia and an easier-to-use, batteries-included alternative to ElasticSearch. Get a quick overview from this guide.

⚙️ Usage

Step 1️⃣ : Setup Prerequisites

Before installing this extension, make sure that you have:

  1. Set up a Cloud Firestore database in your Firebase project.
  2. Set up a Typesense cluster on Typesense Cloud or Self-Hosted (free).
  3. Set up a Typesense Collection either through the Typesense Cloud dashboard or through the API.

⚠️ ☝️ #3 above is a commonly missed step. This extension does not create the Typesense Collection for you. Instead it syncs data to a Typesense collection you've already created. If you see an HTTP 404 in the extension logs, it's most likely because of missing this step.

Step 2️⃣ : Install the Extension

You can install this extension either through the Firebase Web console or through the Firebase CLI.

Firebase Console

Install this extension in your Firebase project

Firebase CLI
firebase ext:install typesense/firestore-typesense-search --project=[your-project-id]

Learn more about installing extensions in the Firebase Extensions documentation: Console, CLI.

🎛️ Configuration Parameters

When you install this extension, you'll be able to configure the following parameters:

Parameter Description
Firestore Collection Path The Firestore collection that needs to be indexed into Typesense.
Firestore Collection Fields A comma separated list of fields that need to be indexed from each Firestore document. Leave blank to index all fields.
Flatten Nested Documents Should nested documents in Firestore be flattened before they are indexed in Typesense? Set to "Yes" for Typesense Server versions v0.23.1 and below, since indexing Nested objects is natively supported only in Typesense Server v0.24 and above.
Typesense Hosts A comma-separated list of Typesense Hosts (only domain without https or port number). For single node clusters, a single hostname is sufficient. For multi-node Highly Available or (Search Delivery Network) SDN Clusters, please be sure to mention all hostnames in a comma-separated list.
Typesense API Key A Typesense API key with admin permissions. Click on "Generate API Key" in cluster dashboard in Typesense Cloud.
Typesense Collection Name Typesense collection name to index data into (you need to create this collection in Typesense yourself. This extension does not create the Typesense Collection for you).
Cloud Functions location Where do you want to deploy the functions created for this extension? You usually want a location close to your database. For help selecting a location, refer to the location selection guide.

⚠️ You'll notice that there is no way to configure the port number or protocol. This is because this extension only supports connecting to Typesense running HTTPS on Port 443, since your data goes from Firebase to Typesense over the public internet and we want your data to be encrypted in transit. For Typesense Cloud, HTTPS is already configured for you.

When self-hosting Typesense, you want to make sure you set --api-port=443 and also get an SSL certificate from say LetsEncrypt or any registrar and configure Typesense to use it using the --ssl-certificate and --ssl-certificate-key server parameters. Alternatively, if you're running Typesense on your local machine, you can also set up a local HTTPS tunnel using something like ngrok (ngrok http 8108) and use the ngrok hostname in the extension.

Example

If you have a Firestore database like this called users:

Firestore DB Example

Here's the extension configuration screen with all the options filled out, if you want to sync the users Firestore collection to Typesense:

Firestore DB Example

Syncing Multiple Firestore collections

You can install this extension multiple times in your Firebase project by clicking on the installation link above multiple times, and use a different Firestore collection path in each installation instance. Here is a screenshot of how this looks.

Step 3️⃣ : [Optional] Backfill existing data

This extension only syncs data that was created or changed in Firestore, after it was installed. In order to backfill data that already exists in your Firestore collection to your Typesense Collection:

  • Create a new Firestore collection called typesense_sync through the Firestore UI.
  • Create a new document with the ID backfill and contents of {trigger: true}
  • [Optional] If you have multiple instances of the extension installed to sync multiple collections, you can specify which particular collections are backfilled by setting the contents of the backfill document in the previous step to {trigger: true, firestore_collections: ["path/to/firestore_collection_1", "path/to/firestore_collection_2"] }

This will trigger the backfill background Cloud function, which will read data from your Firestore collection(s) and create equivalent documents in your Typesense collection.

☁️ Cloud Functions

  • indexToTypesenseOnFirestoreWrite: A function that indexes data into Typesense when it's triggered by Firestore changes.

  • backfillToTypesenseFromFirestore: A function that backfills data from a Firestore collection into Typesense, triggered when a Firestore document with the path typesense_sync/backfill has the contents of trigger: true.

🔑 Access Required

This extension will operate with the following project IAM roles:

  • datastore.user (Reason: Required to backfill data from your Firestore collection into Typesense)

🧾 Billing

To install an extension, your project must be on the Blaze (pay as you go) plan.

  • You will be charged a small amount (typically around $0.01/month) for the Firebase resources required by this extension (even if it is not used).
  • This extension uses other Firebase and Google Cloud Platform services, which have associated charges if you exceed the service’s free tier:
    • Cloud Firestore
    • Cloud Functions (Node.js 14+ runtime. See FAQs)
  • Usage of this extension also requires you to have a running Typesense cluster either on Typesense Cloud or some self-hosted server. You are responsible for any associated costs with these services.

Development Workflow

Run Emulator

npm run emulator
npm run typesenseServer

Add records in the Firestore UI and they should be created in Typesense.

Run Integration Tests

npm run test

Generate README

The Firebase CLI provides the following convenience command to auto-generate a README file containing content pulled from extension.yaml file and PREINSTALL.md file:

firebase ext:info ./ --markdown > README.md

Publish Extension

  • Update version number in extension.yaml
  • Add entry to CHANGELOG.md
  • Create release in GitHub
  • firebase ext:dev:upload typesense/firestore-typesense-search

ℹ️ Support

Please open a Github issue or join our Slack community.

More Repositories

1

typesense

Open Source alternative to Algolia and an Easier-to-Use alternative to ElasticSearch ⚡ 🔍 ✨ Fast, typo tolerant, in-memory fuzzy Search Engine for building delightful search experiences
C++
12,770
star
2

showcase-recipe-search

Instantly search 2M cooking recipes using Typesense Search (an open source alternative to Algolia / ElasticSearch) ⚡ 🥘 🔍
JavaScript
437
star
3

typesense-js

JavaScript / TypeScript client for Typesense
JavaScript
266
star
4

typesense-instantsearch-adapter

A JS adapter library to build rich search interfaces with Typesense and InstantSearch.js
JavaScript
262
star
5

typesense-php

PHP client for Typesense: https://github.com/typesense/typesense
PHP
141
star
6

showcase-songs-search

A site to instantly search 32M songs from the MusicBrainz songs database, using Typesense Search (an open source alternative to Algolia / ElasticSearch) ⚡ 🎵 🔍
JavaScript
135
star
7

showcase-books-search

A site to instantly search 28M books from OpenLibrary using Typesense Search (an open source alternative to Algolia / ElasticSearch) ⚡ 📚 🔍
JavaScript
130
star
8

typesense-go

Go client for Typesense: https://github.com/typesense/typesense
Go
124
star
9

laravel-scout-typesense-driver

Laravel Scout Driver for Typesense
PHP
114
star
10

typesense-python

Python client for Typesense: https://github.com/typesense/typesense
Python
104
star
11

typesense-docsearch-scraper

A fork of Algolia's awesome DocSearch Scraper, customized to index data in Typesense (an open source alternative to Algolia)
Python
70
star
12

typesense-dart

Dart client for Typesense
Dart
59
star
13

docusaurus-theme-search-typesense

A fork of the awesome @docusaurus/theme-search-algolia library customized to work with Typesense
TypeScript
48
star
14

typesense-ruby

Ruby client for Typesense: https://github.com/typesense/typesense
Ruby
43
star
15

typesense-instantsearch-demo

A demo app that shows how to use the Typesense InstantSearch adapter, to build rich search interfaces.
JavaScript
41
star
16

showcase-nextjs-typesense-ecommerce-store

An app showing how you can use Typesense & Next.js / React to build a full-fledged ecommerce browsing and searching experience
JavaScript
36
star
17

typesense-swift

Swift Client for Typesense ⚡️🔎
Swift
34
star
18

typesense-website

Typesense website and documentation | An open source search engine alternative to Algolia, Elasticsearch and Pinecone
Vue
33
star
19

typesense-java

Java client for Typesense
Java
31
star
20

showcase-ecommerce-store

An app showing how you can use Typesense to build a full-fledged ecommerce browsing and searching experience
JavaScript
31
star
21

gatsby-plugin-typesense

A Gatsby plugin to automatically index content to Typesense post-build
JavaScript
30
star
22

showcase-linux-commits-search

Instantly search 1M Linux Kernel Commit Messages using Typesense Search (an open source alternative to Algolia / ElasticSearch) ⚡ 💻 🔍
JavaScript
29
star
23

typesense-kubernetes

Typesense Kubernetes
24
star
24

postman

Postman collection for Typesense
21
star
25

typesense-rust

Rust client for Typesense | Work In Progress & Help Wanted
Rust
21
star
26

typesense-mongodb

A Node.js CLI to sync documents from a MongoDB collection to Typesense.
TypeScript
21
star
27

showcase-hn-comments-semantic-search

Semantic Search + Keyword Search + Hybrid Search + Filtering + Faceting on 300K HN Comments
JavaScript
20
star
28

typesense-docsearch.js

A fork of Algolia's awesome DocSearch.js, customized to use data from Typesense.
TypeScript
20
star
29

typesense-api-spec

Contains the API specs for the Typesense HTTP API
14
star
30

typesense-autocomplete-demo

A demo app that shows you how to use Algolia's autocomplete.js library with Typesense
HTML
13
star
31

typesense-instantsearch-semantic-search-demo

A demo that shows how to build a semantic search experience with Typesense's vector search feature and Instantsearch.js
JavaScript
13
star
32

showcase-xkcd-search

Search & Browse xkcd by topic & keywords | Using Typesense, an open source Algolia alternative and an easier-to-use alternative to Elasticsearch
JavaScript
12
star
33

typesense-rails

Rails Integration for Typesense | Work in Progress | Help Needed
Ruby
9
star
34

showcase-spellcheck

Use Typesense to build a type-ahead spellchecker
JavaScript
8
star
35

typesense-instantsearch-demo-no-npm-yarn

A demo that shows how to use typesense-instantsearch-adapter without NPM or YARN
HTML
8
star
36

showcase-airbnb-geosearch

Browse & GeoSearch 1 Million AirBnB listings with Typesense ⚡🔍 ️🌎
JavaScript
8
star
37

typesense-wordpress-plugin

Deprecated in favor of https://wordpress.org/plugins/search-with-typesense/
JavaScript
7
star
38

typesense-vue-instantsearch-demo

A demo app that shows you how to use Vue & the Typesense InstantSearch adapter, to build rich search interfaces.
Vue
6
star
39

homebrew-tap

Homebrew Formulae for Typesense
Ruby
4
star
40

showcase-federated-search

An app that showcases federated search in Typesense (Open source alternative to Algolia)
JavaScript
3
star
41

typesense-lando-plugin

A Lando plugin for Typesense
JavaScript
2
star
42

typesense-flutter-demo

1
star
43

.github

Org-wide shared github configs
1
star
44

solr-xml-to-jsonl

A CLI utility to convert a solr data file to a simple JSONL file
JavaScript
1
star
45

user-admin-search-laravel-demo

A demo Laravel app that integrates with Typesense
PHP
1
star