# Product Full-Text Search

Implements product search with pg_search or Elasticsearch, sync and reindexing.

- Repository: https://github.com/lobehub/lobehub (83676 stars)
- Category: Engineering
- License: see repository
- Last updated: 2026-11-01
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add lobehub/lobehub --skill full-text-search -g -a claude-code -y`
Codex: `npx skills add lobehub/lobehub --skill full-text-search -g -a codex -y`
Cursor: `npx skills add lobehub/lobehub --skill full-text-search -g -a cursor -y`
Gemini CLI: `npx skills add lobehub/lobehub --skill full-text-search -g -a gemini-cli -y`

## Description

Use for product search: FtsSearchRepo, pg_search/pg_like/Elasticsearch, mapping migrations, projections, Outbox sync, reindexing and performance. Excludes agent web search.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# Product Full-Text Search

This skill covers search over LobeHub-owned product data such as agents, topics, messages, files,
knowledge bases, documents, chat groups, and memories. It does not cover the agent's external web
search providers under `apps/server/src/services/search/` or builtin web-browsing tools.

## Architecture

Product reads follow one stable path:

```text
router/service -> createFtsSearchRepo -> FtsSearchRepo -> selected backend -> existing result schema
```

- `apps/server/src/services/ftsSearch/` owns request-scoped provider selection, Elasticsearch
  configuration, its HTTP client, and backend telemetry. Routers and domain services must call
  `createFtsSearchRepo`; they must not construct providers themselves.
- `packages/database/src/repositories/ftsSearch/` owns the provider-neutral contract and the concrete
  PostgreSQL and Elasticsearch implementations. Keep public result shapes stable in `FtsSearchRepo`.
- `packages/types/src/ftsSearch.ts` owns the shared searchable-entity list and search domain types.
- `packages/database/src/repositories/ftsSearchDocument/` owns Elasticsearch document schemas,
  mappings, queryable fields, and source-to-document projection.
- `packages/database/src/schemas/ftsSearchSyncOutbox.ts` and
  `packages/database/src/repositories/ftsSearchSyncOutbox/` own durable change capture, claims,
  retries, dead letters, leases, revision fences, and capture-definition validation.
- `scripts/elasticsearchReindex/` owns the resumable full-backfill command and its operational
  runtime. Shared database source queries and document construction remain in
  `packages/database/src/repositories/ftsSearchDocument/`. `apps/server/src/services/ftsSearchSync/` and
  `scripts/elasticsearchSync/` own continuous incremental draining.
- `packages/env/src/ftsSearch.ts` owns generic Elasticsearch environment variables.

## Provider and Permission Invariants

The rest: https://github.com/lobehub/lobehub/blob/HEAD/.agents/skills/full-text-search/SKILL.md
