fix(analytics): Fix market-summary store count and add search indexes

- market-summary now counts from store_products table (not product_variants)
- Added trigram indexes for fast ILIKE product searches

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Kelly
2025-12-13 00:35:17 -07:00
parent c16c3083b1
commit 54f59c6082
2 changed files with 57 additions and 26 deletions

View File

@@ -0,0 +1,20 @@
-- Migration: Add trigram indexes for fast ILIKE product searches
-- Enables fast searches on name_raw, brand_name_raw, and description
-- Enable pg_trgm extension if not already enabled
CREATE EXTENSION IF NOT EXISTS pg_trgm;
-- Create GIN trigram indexes for fast ILIKE searches
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_store_products_name_trgm
ON store_products USING gin (name_raw gin_trgm_ops);
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_store_products_brand_name_trgm
ON store_products USING gin (brand_name_raw gin_trgm_ops);
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_store_products_description_trgm
ON store_products USING gin (description gin_trgm_ops);
-- Add comment
COMMENT ON INDEX idx_store_products_name_trgm IS 'Trigram index for fast ILIKE searches on product name';
COMMENT ON INDEX idx_store_products_brand_name_trgm IS 'Trigram index for fast ILIKE searches on brand name';
COMMENT ON INDEX idx_store_products_description_trgm IS 'Trigram index for fast ILIKE searches on description';