Skip to main content
coding intermediate

Implement Search Functionality

Get AI assistance to build robust search features for your app. Covers database queries, filtering, pagination, and user experience.

Works with: chatgptclaudegemini

Prompt Template

I need to implement search functionality for my [APPLICATION_TYPE] application. Here are the key requirements: **Technical Stack:** - Frontend: [FRONTEND_TECH] - Backend: [BACKEND_TECH] - Database: [DATABASE_TYPE] **Search Requirements:** - Search across: [SEARCHABLE_FIELDS] - Expected data volume: [DATA_VOLUME] - Performance requirements: [PERFORMANCE_NEEDS] - User experience needs: [UX_REQUIREMENTS] **Specific Features Needed:** [SPECIFIC_FEATURES] Please provide: 1. Database schema considerations and indexing strategies 2. Backend API implementation with query optimization 3. Frontend search interface with real-time suggestions 4. Error handling and edge cases 5. Performance optimization techniques 6. Code examples for key components 7. Testing strategies for search functionality Include best practices for search UX, such as handling typos, empty results, and search result ranking. Also suggest ways to make the search scalable and maintainable as the dataset grows.

Variables to Customize

[APPLICATION_TYPE]

Type of application (e.g., e-commerce, blog, directory)

Example: e-commerce website

[FRONTEND_TECH]

Frontend technology stack

Example: React with TypeScript

[BACKEND_TECH]

Backend technology and framework

Example: Node.js with Express

[DATABASE_TYPE]

Database system being used

Example: PostgreSQL

[SEARCHABLE_FIELDS]

Fields that users should be able to search through

Example: product names, descriptions, categories, and tags

[DATA_VOLUME]

Approximate amount of searchable data

Example: 50,000 products with potential to grow to 500,000

[PERFORMANCE_NEEDS]

Performance requirements and constraints

Example: search results should load within 200ms

[UX_REQUIREMENTS]

User experience requirements for the search

Example: autocomplete suggestions, filters by category and price range

[SPECIFIC_FEATURES]

Any specific search features or functionality needed

Example: fuzzy matching for typos, advanced filtering, search history

Example Output

## Database Schema & Indexing For your e-commerce search, create a full-text search index: ```sql CREATE INDEX idx_products_search ON products USING gin(to_tsvector('english', name || ' ' || description)); CREATE INDEX idx_products_category ON products(category_id); ``` ## Backend API (Node.js/Express) ```javascript app.get('/api/search', async (req, res) => { const { q, category, minPrice, maxPrice, page = 1 } = req.query; let query = ` SELECT p.*, ts_rank(to_tsvector('english', p.name || ' ' || p.description), plainto_tsquery($1)) as rank FROM products p WHERE 1=1 `; const params = []; if (q) { query += ` AND to_tsvector('english', p.name || ' ' || p.description) @@ plainto_tsquery($${params.length + 1})`; params.push(q); } // Add price and category filters... query += ' ORDER BY rank DESC, created_at DESC LIMIT 20 OFFSET $' + (params.length + 1); params.push((page - 1) * 20); const results = await db.query(query, params); res.json({ products: results.rows, total: results.rowCount }); }); ``` ## Frontend React Component ```jsx const SearchBar = () => { const [query, setQuery] = useState(''); const [suggestions, setSuggestions] = useState([]); const debouncedSearch = useCallback( debounce(async (searchTerm) => { if (searchTerm.length > 2) { const response = await fetch(`/api/search/suggestions?q=${searchTerm}`); setSuggestions(await response.json()); } }, 300), [] ); return ( <div className="search-container"> <input type="text" value={query} onChange={(e) => { setQuery(e.target.value); debouncedSearch(e.target.value); }} placeholder="Search products..." /> {suggestions.length > 0 && ( <SuggestionsList suggestions={suggestions} onSelect={setQuery} /> )} </div> ); }; ```

Pro Tips for Best Results

  • Implement debouncing for search input to avoid overwhelming the server with requests
  • Use database indexes strategically - full-text search indexes for content, B-tree indexes for filters
  • Consider implementing search analytics to understand user behavior and improve results
  • Add fuzzy matching capabilities to handle typos and improve user experience
  • Implement proper caching strategies for popular search queries to improve performance

Tags

Want 500+ Expert Prompts?

Get the Premium Prompt Pack — organized, tested, and ready to use.

Get it for $29

Related Prompts You Might Like