Skip to content

firecmsco/typesense-extension

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Typesense Search for Firestore

A Firebase Extension that automatically deploys Typesense on a Compute Engine VM and syncs your Firestore data for full-text search.

Features

  • One-click installation: Deploy Typesense with a single command
  • Auto-sync: Firestore documents are automatically indexed when created, updated, or deleted
  • Low cost: ~$7-14/month for the VM (persistent, doesn't scale to zero)
  • Persistent storage: Data survives VM restarts via attached persistent disk
  • Client access: External IP allows direct search from web/mobile apps

Architecture

┌─────────────────┐     ┌──────────────────┐     ┌─────────────────┐
│   Firestore     │────▶│  Cloud Function  │────▶│  Compute Engine │
│   (write)       │     │  (onWrite)       │     │  VM (Typesense) │
└─────────────────┘     └──────────────────┘     └─────────────────┘
                                                          │
                                                          ▼
                                                  ┌───────────────┐
                                                  │ Persistent    │
                                                  │ Disk (/data)  │
                                                  └───────────────┘

Cost Breakdown

Machine Type RAM Monthly Cost
e2-micro 1 GB ~$7
e2-small 2 GB ~$14
e2-medium 4 GB ~$28

Plus:

  • Persistent disk: ~$0.04/GB/month
  • External IP: ~$3/month (for direct client access)
  • Secret Manager: ~$0.03/month

Installation

Prerequisites

  1. Enable required APIs:

    gcloud services enable compute.googleapis.com secretmanager.googleapis.com --project=YOUR_PROJECT
  2. Grant IAM permissions (one-time setup):

    PROJECT_NUMBER=$(gcloud projects describe YOUR_PROJECT --format="value(projectNumber)")
    gcloud projects add-iam-policy-binding YOUR_PROJECT \
      --member="serviceAccount:service-${PROJECT_NUMBER}@gcp-sa-firebasemods.iam.gserviceaccount.com" \
      --role="roles/resourcemanager.projectIamAdmin"

Install

firebase ext:install . --project=YOUR_PROJECT

Configuration

Parameter Description
VM_ZONE Zone for the Typesense VM
TYPESENSE_MACHINE_TYPE VM size (e2-micro, e2-small, e2-medium)
DISK_SIZE_GB Persistent disk size in GB
COLLECTIONS_TO_INDEX Firestore collections to sync

Usage

Get Configuration

import { getFunctions, httpsCallable } from "firebase/functions";

const getSearchConfig = httpsCallable(getFunctions(), "ext-typesense-search-getSearchConfig");
const { data } = await getSearchConfig();

Search

import Typesense from "typesense";

const client = new Typesense.Client({
  nodes: [{ host: data.host, port: data.port, protocol: data.protocol }],
  apiKey: data.apiKey,
});

const results = await client.collections("products").documents().search({
  q: "search query",
  query_by: "name,description",
});

Backfill Existing Data

curl -X POST -H "Authorization: Bearer TOKEN" \
  https://REGION-PROJECT.cloudfunctions.net/ext-typesense-search-backfill

For maintainers:

Publish the extension with: firebase ext:dev:upload firecms/typesense-search --repo=https://github.com/firecmsco/typesense-extension --root=.

License

Apache-2.0

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published