<commit_before>from aldryn_search.utils import get_index_base

from .models import Service


class ServiceIndex(get_index_base()):
    haystack_use_for_indexing = True
    index_title = True

    def get_title(self, obj):
        # XXX what about language?  concatenate all available languages?
        return obj.name_en

    def get_index_queryset(self, language):
        # XXX exclude objects with blank name for the selected language, not simply for EN
        return Service.objects.filter(status=Service.STATUS_CURRENT).exclude(name_en='')

    def get_model(self):
        return Service

    def get_search_data(self, service, language, request):
        # XXX return data for the selected language, not simply for EN
        return ' '.join((
            service.provider.name_en,
            service.name_en,
            service.area_of_service.name_en,
            service.description_en,
            service.additional_info_en,
            service.type.name_en,
        ))
<commit_msg>Implement language-specific aspects of indexing<commit_after>from aldryn_search.utils import get_index_base

from .models import Service


class ServiceIndex(get_index_base()):
    haystack_use_for_indexing = True
    index_title = True

    def get_title(self, obj):
        return obj.name

    def get_index_queryset(self, language):
        # For this language's index, don't include services with no name
        # provided in this language.
        return Service.objects.filter(status=Service.STATUS_CURRENT).exclude(**{
            'name_%s' % language: ''
        })

    def get_model(self):
        return Service

    def get_search_data(self, service, language, request):
        description = getattr(service, 'description_%s' % language, '')
        additional_info = getattr(service, 'additional_info_%s' % language, '')
        return ' '.join((
            service.provider.name,
            service.name,
            service.area_of_service.name,
            description,
            additional_info,
            service.type.name,
        ))

{'fraction_non_alphanumeric': 0.0825242718446602, 'fraction_numerical': 0.0, 'mean_word_length': 2.660746003552398, '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': '6170640', 'n_tokens_mistral': 575, 'n_tokens_neox': 553, 'n_words': 143}