// The search wiring, shared so app.config (the plugin) and the boot startup // (the backfill) use the SAME backend instance + index spec. // // `memoryBackend()` is an in-process index — zero infra, perfect for dev. It's // a closure over a Map, so two `memoryBackend()` calls would be two SEPARATE // indexes; sharing ONE instance here is what lets the startup's `backfillIndex` // seed the very index the plugin's `search.query` reads from. Swap it for // `{ engine: 'typesense', url, apiKey }` (or meilisearch / algolia) for prod — // nothing else changes. import { memoryBackend, type IndexSpec, type SearchDoc } from '@voltro/plugin-search' export const searchBackend = memoryBackend() // One index over the `articles` table. `map` flattens a row → a search doc // (must include `id`); `tenantField` makes `search.query` auto-filter to the // caller's tenant, so one tenant can never see another's hits. export const articlesIndex: IndexSpec = { index: 'articles', map: (row): SearchDoc => ({ id: row['id'] as string, title: row['title'] as string, body: row['body'] as string, tag: row['tag'] as string, tenantId: row['tenantId'] as string, }), tenantField: 'tenantId', }