🗄️

Full-Text Search Implementation

Implement fast full-text search using PostgreSQL without external tools

prompt template
Implement full-text search in PostgreSQL for:

**Table:** [TABLE_NAME]
**Searchable columns:** [COLUMNS — e.g., "title, description, tags, author_name"]
**Features needed:** [FEATURES — e.g., "fuzzy matching, ranking, highlighting, autocomplete"]

Generate:
1. **tsvector column** — generated column combining searchable fields with weights
2. **GIN index** — index for fast full-text queries
3. **Search query** — ts_query with ranking by relevance
4. **Fuzzy matching** — pg_trgm for typo-tolerant search
5. **Autocomplete** — prefix matching for search-as-you-type
6. **Highlighting** — ts_headline for showing matched snippets
7. **API endpoint** — complete endpoint with pagination and filters
8. **Performance** — benchmark queries and optimization tips

Include the migration SQL, search function, and API route code.

How to Use This Prompt

  1. 1Copy the prompt template above
  2. 2Paste into Claude, ChatGPT, or Cursor
  3. 3Replace [bracketed placeholders] with your specific project details
  4. 4Iterate on the AI output to refine and customize the results