Search
Route: /search
File: ayts-fe/app/search/page.tsx
Auth required: No
Purpose
Full-text search across stores and products. Powered by PostgreSQL FTS indexes on the Supabase database.
Features
- Real-time autocomplete as user types
- Searches both stores and products simultaneously
- Filters by category
- Debounced input (300ms) to reduce API calls
- Results grouped by type (Stores / Products)
Data Fetching
// Search with query
GET /api/search?q={query}&type=all&limit=20
// Autocomplete suggestions
GET /api/search/autocomplete?q={query}&limit=5
Search Behavior
- User types in search box
- After 300ms debounce, calls
/api/search/autocompletefor suggestions - On form submit or suggestion click, navigates to
/search?q={query} - Results page calls
/api/search?q={query}and displays grouped results
FTS Implementation
Full-text search is implemented via PostgreSQL FTS indexes:
-- Products search index (migration 0010_performance_indexes.sql)
CREATE INDEX idx_products_fts ON products USING GIN(to_tsvector('english', name || ' ' || description));
-- Stores search index
CREATE INDEX idx_stores_fts ON stores USING GIN(to_tsvector('english', name || ' ' || description));
Known Issues / Status
| Item | Status |
|---|---|
| FTS search working | ✅ Working |
| Autocomplete | ✅ Working |
| Category filter | ✅ Working |
| "hardware" suggestion text | ⚠️ No hardware stores exist — update copy |
| Empty results state | ✅ Working |
Suggested Copy Fix
The search page suggests: Try "rice", "pharmacy", or "hardware"
Change to: Try "rice", "pharmacy", or "vegetables" (remove "hardware" until hardware stores are onboarded).