Skip to main content

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

  1. User types in search box
  2. After 300ms debounce, calls /api/search/autocomplete for suggestions
  3. On form submit or suggestion click, navigates to /search?q={query}
  4. 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

ItemStatus
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).