<commit_before>from rest_framework import generics, serializers
from rest_framework.response import Response

from waffle.decorators import waffle_switch

from addons.models import Addon


class AddonSerializer(serializers.ModelSerializer):
    name = serializers.CharField()
    icon_url = serializers.CharField()

    class Meta:
        model = Addon
        fields = [
            'name',
            'slug',
            'icon_url',
            'id',
        ]


class SearchView(generics.RetrieveAPIView):
    serializer_class = AddonSerializer

    @waffle_switch('frontend-prototype')
    def retrieve(self, request, *args, **kwargs):
        queryset = Addon.objects.all()
        if 'q' in request.GET:
            queryset = queryset.filter(slug__contains=request.GET['q'])
        serializer = self.get_serializer(queryset, many=True)
        return Response(serializer.data)<commit_msg>More fields in prototype add-on search<commit_after>from rest_framework import generics, serializers
from rest_framework.response import Response

from waffle.decorators import waffle_switch

import amo
from addons.models import Addon


class AddonSerializer(serializers.ModelSerializer):
    addon_type = serializers.SerializerMethodField('get_addon_type')
    description = serializers.CharField()
    icons = serializers.SerializerMethodField('get_icons')
    name = serializers.CharField()
    rating = serializers.FloatField(source='average_rating')
    summary = serializers.CharField()

    class Meta:
        model = Addon
        fields = [
            'addon_type',
            'description',
            'icons',
            'id',
            'guid',
            'name',
            'rating',
            'slug',
            'summary',
        ]

    def get_addon_type(self, instance):
        return unicode(amo.ADDON_TYPE[instance.type])

    def get_icons(self, instance):
        return {
            '32': instance.get_icon_url(32),
            '64': instance.get_icon_url(64),
        }


class SearchView(generics.RetrieveAPIView):
    serializer_class = AddonSerializer

    @waffle_switch('frontend-prototype')
    def retrieve(self, request, *args, **kwargs):
        queryset = Addon.objects.filter(type__in=amo.GROUP_TYPE_ADDON)
        if 'q' in request.GET:
            queryset = queryset.filter(slug__contains=request.GET['q'])
        serializer = self.get_serializer(queryset[:20], many=True)
        return Response(serializer.data)
{'fraction_non_alphanumeric': 0.0982940698619009, 'fraction_numerical': 0.004061738424045491, 'mean_word_length': 2.8605015673981193, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3360539', 'n_tokens_mistral': 714, 'n_tokens_neox': 701, 'n_words': 142}