link,[object Object]
Skip to content

Search & Indexing ​

Purpose: Document how search/filters work and which indexes support them. Audience: Developer Prerequisites: Explore pages implemented; Supabase database access.

Explore filters (from code)

  • Source: src/hooks/useEnhancedExploreQuery.ts
    • status = 'active' (line ~29)
    • searchTerm (ilike on title, description) (lines ~32-34)
    • category eq (36-38)
    • technologies array contains (cs) with mapped names (40-48) using useTechStack
    • established_date range by businessAge (50-70)
    • price range (73-78)
    • monthly_revenue range (81-85)
    • monthly_profit range (87-92)
    • number_of_customers range (94-99)
    • sponsored first, then sort: price asc/desc, monthly_revenue, monthly_profit, created_at (101-114)

Recommended indexes (btree unless specified)

  • listings(status) WHERE status='active' (partial) — supports public browse
  • listings(category)
  • listings(price)
  • listings(monthly_revenue)
  • listings(monthly_profit)
  • listings(number_of_customers)
  • listings(created_at desc)
  • listings(is_sponsored desc, created_at desc) — composite for sponsored-first
  • listings(technologies) — GIN index for array contains (if used frequently)
  • Optional: trigram index for title/description if full-text search is needed

Existing indexes (from docs/features/listings.md)

  • CREATE INDEX idx_listings_price ON listings(price);
  • CREATE INDEX idx_listings_featured ON listings(featured, created_at);

Saved data

  • favorites(user_id, listing_id)
  • saved_searches(user_id, created_at)

Notes

  • Keep filter set stable to avoid missing indexes
  • Monitor slow queries in Supabase and add composite/partial indexes as patterns emerge
  • Consider a dedicated search service if ilike becomes a bottleneck

Related

  • Listings: docs/features/listings.md
  • Performance: docs/performance.md