pg-smart-search
Guides

Configuration

Complete reference for configuring the TrigramSearchEngine, including adapter setup, table mapping, and cache options.

Configuration

The TrigramSearchEngine constructor accepts a database adapter and a configuration object. This page details all available configuration options.

Basic Setup

import { TrigramSearchEngine, MemoryCacheProvider } from "pg-smart-search";

const engine = new TrigramSearchEngine(adapter, {
  tableName: "products",
  searchColumns: ["name", "description"],
  cacheProvider: new MemoryCacheProvider(),
});

EngineConfig Options

Prop

Type

Database Adapter

The engine requires an adapter to communicate with your database. The adapter must implement the query execution interface expected by the engine, wrapping your preferred database driver (e.g., pg or drizzle-orm).

// Example adapter structure
const adapter = {
  query: async (sql: string, params: any[]) => {
    // Execute parameterized query using your driver
    return db.query(sql, params);
  },
};