#!/usr/bin/env python3
"""
Test specifically for Eazy-E to see why it's matching to Sleazy-E.
"""

import psycopg2
import psycopg2.extras

# Database configuration
DB_HOST = "172.18.0.2"
DB_PORT = 5432
DB_NAME = "musicbrainz_db"
DB_USER = "musicbrainz"
DB_PASSWORD = "musicbrainz"

def test_eazy_e():
    """Test Eazy-E specifically."""
    print("🔍 Testing Eazy-E specifically...")
    
    try:
        connection = psycopg2.connect(
            host=DB_HOST,
            port=DB_PORT,
            database=DB_NAME,
            user=DB_USER,
            password=DB_PASSWORD,
            connect_timeout=10
        )
        cursor = connection.cursor(cursor_factory=psycopg2.extras.RealDictCursor)
        
        print("✅ Connected to database")
        
        # Test 1: Search for Eazy-E
        print("\n1. Searching for 'Eazy-E'...")
        cursor.execute("SELECT name, gid FROM artist WHERE name = 'Eazy-E' LIMIT 5")
        eazy_e_results = cursor.fetchall()
        print(f"   Found {len(eazy_e_results)} exact matches:")
        for result in eazy_e_results:
            print(f"     {result['name']} (MBID: {result['gid']})")
        
        # Test 2: Search for Sleazy-E
        print("\n2. Searching for 'Sleazy-E'...")
        cursor.execute("SELECT name, gid FROM artist WHERE name = 'Sleazy-E' LIMIT 5")
        sleazy_e_results = cursor.fetchall()
        print(f"   Found {len(sleazy_e_results)} exact matches:")
        for result in sleazy_e_results:
            print(f"     {result['name']} (MBID: {result['gid']})")
        
        # Test 3: Fuzzy search for Eazy-E
        print("\n3. Fuzzy search for 'Eazy-E'...")
        cursor.execute("SELECT name, gid FROM artist WHERE name ILIKE '%Eazy-E%' LIMIT 10")
        fuzzy_results = cursor.fetchall()
        print(f"   Found {len(fuzzy_results)} fuzzy matches:")
        for result in fuzzy_results:
            print(f"     {result['name']} (MBID: {result['gid']})")
        
        # Test 4: Search for Boyz n The Hood
        print("\n4. Searching for 'Boyz n The Hood'...")
        cursor.execute("SELECT name, gid FROM recording WHERE name ILIKE '%Boyz n The Hood%' LIMIT 5")
        recording_results = cursor.fetchall()
        print(f"   Found {len(recording_results)} recordings:")
        for result in recording_results:
            print(f"     {result['name']} (MBID: {result['gid']})")
            
            # Get artist for this recording
            cursor.execute("""
                SELECT a.name, a.gid
                FROM recording r
                JOIN artist_credit_name acn ON r.artist_credit = acn.artist_credit
                JOIN artist a ON acn.artist = a.id
                WHERE r.gid = %s
                LIMIT 1
            """, (result['gid'],))
            artist_result = cursor.fetchone()
            if artist_result:
                print(f"       Artist: {artist_result['name']} (MBID: {artist_result['gid']})")
        
        cursor.close()
        connection.close()
        
    except Exception as e:
        print(f"❌ Error: {e}")
        import traceback
        traceback.print_exc()

if __name__ == "__main__":
    test_eazy_e() 