Getting Started
Quick Start
Set up pg-smart-search in 3 minutes. Install the package, run the interactive CLI, and execute your first search.
Quick Start
Get sub-15ms search running in your PostgreSQL database in three steps.
Step 1: Install the package
bash npm install pg-smart-search bash yarn add pg-smart-search bash pnpm add pg-smart-search Step 2: Initialize your database
The CLI will automatically create the required indices and generated columns for your dataset.
npx pg-smart-search initFollow the interactive prompts to select your table, columns, and search tier.
Migrations in CI/CD? You can apply migrations programmatically or via the CLI in non-interactive mode. See CLI & Migrations.
Step 3: Implement the Search Engine
import { TrigramSearchEngine, MemoryCacheProvider } from "pg-smart-search";
// Initialize with your pg adapter
const adapter = yourDbAdapter;
const engine = new TrigramSearchEngine(adapter, {
tableName: "products",
searchColumns: ["name", "description"],
ftsColumn: "search_vector", // Enabled via Turbo Mode (AOT)
cacheProvider: new MemoryCacheProvider(),
defaultTTL: 3600,
});
// Execute search with typo tolerance ("laptpp" instead of "laptop")
const results = await engine.search({
query: "laptpp",
language: "en",
});
console.log(results);Next Steps
- Learn how Parallel Fast-Track achieves low latency.
- Configure Redis Caching for distributed environments.