products table, and an optional voice search capability backed by the voice-intelligence Supabase Edge Function.
Routes
| Route | Component | Description |
|---|---|---|
/buscar | SearchResults | Full-page search results with query from URL ?q= param |
| Any page | SearchOverlay | Modal search overlay triggered from the Header |
useSearch() Hook
useSearch (src/hooks/useSearch.ts) is a debounced React Query wrapper over searchProducts().
useDebounce(query, delay) (src/hooks/useDebounce.ts) before triggering the query, preventing a database request on every keystroke. The query is disabled when the debounced value is empty.
searchProducts() Service
The searchProducts function in src/services/search.service.ts performs a multi-field ilike search:
name— ilike%query%short_description— ilike%query%description— ilike%query%sku— ilike%query%tags— array contains{query}
is_featured DESC, name ASC. User-input special characters (%, _) are escaped before building the pattern:
Only
is_active = true and status = 'active' products are searched. Out-of-stock items (stock = 0) are not excluded from search — they can appear in results so customers can see they exist. This differs from catalog listings which hide zero-stock items.SearchOverlay Component
SearchOverlay (src/components/search/SearchOverlay.tsx) is a modal dialog rendered at the top of the DOM via a portal. It is triggered from <Header /> when the search icon is clicked or Ctrl+K is pressed.
Live results
Results appear below the input field after the debounce delay (typically 300ms). Shows product
cover_image, name, price, and section label.Keyboard navigation
Arrow keys navigate results,
Enter follows the link to the product page, Escape closes the overlay.SearchResults Page
SearchResults (src/pages/SearchResults.tsx) is the full-page view at /buscar. It reads the search query from the ?q= URL parameter, enabling shareable search URLs and back-navigation.
Voice Search
VSM Store includes an optional voice search feature powered by:voice.service.ts— Captures audio via the Web Speech API (SpeechRecognition) or a recorded audio blob.voice-intelligenceEdge Function — A Supabase Edge Function (Deno runtime) that sends transcribed or raw audio text to the Gemini 2.0 Flash API, converting natural language queries like “busca líquidos de mango sin nicotina” into structured product search terms.
Voice search requires microphone permission from the browser. It is progressively enhanced — the UI degrades gracefully to text-only input if
SpeechRecognition is unavailable or permission is denied.Voice search data flow
Voice search data flow
Capture speech
voice.service.ts activates window.SpeechRecognition and collects the interim transcript.Send to edge function
The transcript is POST-ed to the
voice-intelligence Supabase Edge Function with the customer context.Gemini NLP processing
The edge function calls
gemini-2.0-flash to normalize the natural language query into clean search terms (e.g., removing filler words, extracting product attributes).