from rest_framework import generics, permissions
from ..models import Source
from ..serializers import SourceSerializer

class SearchView(generics.ListAPIView):
    serializer_class = SourceSerializer
    permission_classes = [permissions.AllowAny]

    def get_queryset(self):
        query = self.request.query_params.get('q', '')
        return Source.objects.filter(title__icontains=query) | \
               Source.objects.filter(description__icontains=query) | \
               Source.objects.filter(tags__name__icontains=query).distinct()