BoilerPrompt
GitHub Copilot

GitHub Copilot prompt to add a search feature

Search touches both halves of an app, and this prompt makes GitHub Copilot handle both: an indexed, injection-safe query endpoint and a debounced input that discards stale responses. The finished feature covers the failure cases ad hoc search implementations skip, wildcard escaping, blank queries, and the race where an old response overwrites a new one.

Last updated

Prompt
Open Copilot Chat with the backend folder as context and describe the query path before generating code. Server side: expose GET /search accepting q, a limit, and an optional filter argument; comparison against {{resource}} name and description must ignore case. Prefer the full-text capability {{database}} offers natively; when that is missing, fall back to ILIKE supported by a trigram index, or a prefix one, added through a new migration. Treat % and _ from users as literal characters, never wildcards. Client side: wire a text box that waits 300ms after typing stops, aborts any in-flight fetch when a newer one starts, renders an empty-state card echoing the sanitized query when nothing matches, and truncates long result sets behind a show-more control. A blank q must yield an empty array with status 200, not an error. Cover the literal-character escaping and the empty-string request in tests, run them, and summarize the diff.

Customize it

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

Your customized prompt
Open Copilot Chat with the backend folder as context and describe the query path before generating code. Server side: expose GET /search accepting q, a limit, and an optional filter argument; comparison against users name and description must ignore case. Prefer the full-text capability PostgreSQL offers natively; when that is missing, fall back to ILIKE supported by a trigram index, or a prefix one, added through a new migration. Treat % and _ from users as literal characters, never wildcards. Client side: wire a text box that waits 300ms after typing stops, aborts any in-flight fetch when a newer one starts, renders an empty-state card echoing the sanitized query when nothing matches, and truncates long result sets behind a show-more control. A blank q must yield an empty array with status 200, not an error. Cover the literal-character escaping and the empty-string request in tests, run them, and summarize the diff.

Same task in other tools

Questions about this prompt

We use Elasticsearch, not database text search. Can this target our existing index?

Yes. Replace the backend paragraph with "query the existing Elasticsearch index for {{resource}}" and reference your client wrapper with #file. Keep the escaping and blank-query lines; those bugs exist regardless of the engine.

Copilot Edits split this across many files. Is that expected?

Yes, a migration, a route, a hook or component, and tests is the normal footprint for this feature. Review the migration first, since an index is the hardest piece to undo after deploy.

The debounce works but results still flicker. What went wrong?

Flicker usually means stale-request cancellation got skipped. Check that the fetch uses an AbortController or ignores responses from outdated queries, and tell Copilot to add a test that resolves two requests out of order.

Related prompts