Windsurf prompt to add a search feature
Search touches both ends of the stack, and this prompt has Windsurf handle the pair together: an indexed query endpoint plus a debounced frontend with request cancellation. Cascade will add the migration, wire the UI states, and leave you a small test that checks exact matches rank above partial ones.
Last updated
Add search for {{resource}} records to this codebase, end to end. Backend: a GET /api/search endpoint taking q, limit, and offset, matching against name and description fields case-insensitively, returning results plus a total count. Use the database's native text search if available, otherwise ILIKE with a trigram or prefix index, and add that index in a migration. Debounce the frontend input at around 300ms, cancel stale requests with AbortController so out-of-order responses never overwrite newer ones, and show three states: searching, results with the match count, and a no-results message echoing the query. Empty or whitespace-only queries should clear results, not hit the API. Escape user input so % and _ cannot act as wildcards. Verify with a test covering ranking of exact match above partial match, then tell me which files changed and how to try it.Customize it
Runs in your browser. Nothing you type here is sent anywhere.
Add search for users records to this codebase, end to end. Backend: a GET /api/search endpoint taking q, limit, and offset, matching against name and description fields case-insensitively, returning results plus a total count. Use the database's native text search if available, otherwise ILIKE with a trigram or prefix index, and add that index in a migration. Debounce the frontend input at around 300ms, cancel stale requests with AbortController so out-of-order responses never overwrite newer ones, and show three states: searching, results with the match count, and a no-results message echoing the query. Empty or whitespace-only queries should clear results, not hit the API. Escape user input so % and _ cannot act as wildcards. Verify with a test covering ranking of exact match above partial match, then tell me which files changed and how to try it.
Same task in other tools
Questions about this prompt
My database is Postgres. Which search approach will Cascade take?
For this prompt it typically writes ILIKE with a pg_trgm index, which satisfies the case-insensitive and wildcard-escaping requirements. If you want stemming and relevance ranking, say 'use Postgres full-text search with tsvector' and the ranking test will exercise ts_rank instead of simple match ordering.
Old results flash over newer ones while I type fast. What broke?
The AbortController wiring is missing or attached to the wrong fetch. Point Cascade at the search hook and say 'abort the in-flight request on each keystroke and swallow abort rejections', then type a quick query and delete it to confirm stale responses no longer land.
How do I extend this to search across multiple entity types?
Change the response contract to grouped results with a per-group limit, something like users, posts, and comments arrays, and index each table in its own migration. Do this as a follow-up flow after single-type search passes its test so regressions are easy to attribute.