BoilerPrompt
Cursor

Cursor prompt to add a search feature

Search touches both ends of the stack, and this prompt covers both: a ranked full-text endpoint that avoids LIKE scans on the backend, and a debounced input with stale-request cancellation on the front. Cursor builds each half against your existing code and closes with tests for ranking order and debounce timing.

Last updated

Prompt
Add search for {{resource}} to this app end to end. Backend: a GET /search endpoint taking q, limit, and offset that uses {{database}} full-text search (tsvector with a GIN index in Postgres, or the configured engine's equivalent) rather than LIKE '%term%' table scans, escapes user input, and returns ranked results with a total count. Frontend: a search input with a 300ms debounce, cancellation of stale in-flight requests so a fast typist never sees older results overwrite newer ones, a loading indicator, an empty state that echoes the query, and keyboard navigation through results. Enforce a two character minimum on both client and server. Add a test for ranking (exact title match beats body match) and one for the debounce, then run everything and list the endpoints and components you touched.

Customize it

Runs in your browser. Nothing you type here is sent anywhere.

Your customized prompt
Add search for users to this app end to end. Backend: a GET /search endpoint taking q, limit, and offset that uses PostgreSQL full-text search (tsvector with a GIN index in Postgres, or the configured engine's equivalent) rather than LIKE '%term%' table scans, escapes user input, and returns ranked results with a total count. Frontend: a search input with a 300ms debounce, cancellation of stale in-flight requests so a fast typist never sees older results overwrite newer ones, a loading indicator, an empty state that echoes the query, and keyboard navigation through results. Enforce a two character minimum on both client and server. Add a test for ranking (exact title match beats body match) and one for the debounce, then run everything and list the endpoints and components you touched.

Same task in other tools

Questions about this prompt

My database is MySQL or SQLite, not Postgres. Does the prompt still apply?

Yes. The prompt says to use the configured engine's equivalent: MySQL has FULLTEXT indexes with MATCH AGAINST, and SQLite has FTS5 virtual tables. Name the engine explicitly so Cursor picks the native mechanism instead of falling back to LIKE.

At what point should this move to a dedicated search service?

When you need typo tolerance, faceting, or millions of rows under strict latency, reach for Meilisearch, Typesense, or Elasticsearch. Keep the frontend half unchanged; only the endpoint's internals move to the external service, which is why the debounced input and the API are built as separate halves.

How do I check that stale-response cancellation actually works?

Throttle the network in devtools, type a word, then quickly change it and watch the network panel: earlier requests should show as cancelled, and the visible results must match the final query. If old results flash in afterward, tell the agent the AbortController wiring is incomplete.

Related prompts