from django.core.management.base import BaseCommand
from links.search_backend import search_backend


class Command(BaseCommand):
    help = 'Rebuild the full-text search index'

    def handle(self, *args, **options):
        self.stdout.write('Rebuilding search index...')
        try:
            search_backend.rebuild_index()
            self.stdout.write(self.style.SUCCESS('Successfully rebuilt search index'))
        except Exception as e:
            self.stdout.write(self.style.ERROR(f'Failed to rebuild index: {e}'))
