# Create Search Tags View The search function requires a database view called `view_searchable_tags` for efficient tag searching. ## Why This Is Needed Without this view, the search function would need to download ALL posts from the database just to count tags, which will: - Timeout with 1000+ posts - Crash the Edge Function - Cause poor performance The view pre-aggregates tag counts at the database level, making searches instant. ## How to Create the View ### Option 1: Via Supabase Dashboard (Recommended) 1. Go to your Supabase project's SQL Editor: https://supabase.com/dashboard/project/zwkihedetedlatyvplyz/sql 2. Paste and run this SQL: ```sql CREATE OR REPLACE VIEW view_searchable_tags AS SELECT unnest(tags) as tag, COUNT(*) as count FROM posts WHERE deleted_at IS NULL AND tags IS NOT NULL AND array_length(tags, 1) > 0 GROUP BY unnest(tags) ORDER BY count DESC; ``` 3. Click "RUN" to execute ### Option 2: Via PowerShell (if you have psql installed) Run this from the project root: ```powershell Get-Content supabase\migrations\create_searchable_tags_view.sql | psql $DATABASE_URL ``` Replace `$DATABASE_URL` with your Supabase database connection string. ## Verifying It Works After creating the view, test it with: ```sql SELECT * FROM view_searchable_tags LIMIT 10; ``` You should see a list of tags with their counts. ## What Happens If You Don't Create It? The search function will return an error when searching for tags. Users and posts will still work fine, but tag search will fail until this view is created.