<commit_before># TODO: Figure out how to configure haystack to register indices in
#       ./indices/<IndexName> instead of this default file...

from itertools import chain

from haystack import indexes
from django.db.models import Prefetch
from django.utils import timezone

from api_v2.models.Credential import Credential as CredentialModel
from api_v2.models.Name import Name as NameModel
from api_v2.models.Topic import Topic as TopicModel


class TopicIndex(indexes.SearchIndex, indexes.Indexable):
    document = indexes.CharField(document=True, use_template=True)

    name = indexes.MultiValueField()
    location = indexes.MultiValueField()
    # historical = indexes.BooleanField()

    @staticmethod
    def prepare_name(obj):
        names = ((name.text for name in cred.names.all()) for cred in obj.nonrevoked)
        return list(chain.from_iterable(names))

    @staticmethod
    def prepare_location(obj):
        locations = []
        for credential in obj.nonrevoked:
            for address in credential.addresses.all():<commit_msg>fix issue with individual record indexing<commit_after># TODO: Figure out how to configure haystack to register indices in
#       ./indices/<IndexName> instead of this default file...

from itertools import chain

from haystack import indexes
from django.db.models import Prefetch
from django.utils import timezone

from api_v2.models.Credential import Credential as CredentialModel
from api_v2.models.Name import Name as NameModel
from api_v2.models.Topic import Topic as TopicModel


class TopicIndex(indexes.SearchIndex, indexes.Indexable):
    document = indexes.CharField(document=True, use_template=True)

    name = indexes.MultiValueField()
    location = indexes.MultiValueField()
    # historical = indexes.BooleanField()

    @staticmethod
    def prepare_name(obj):
        creds = getattr(obj, 'nonrevoked', obj.credentials.filter(revoked=False))
        names = ((name.text for name in cred.names.all()) for cred in creds)
        return list(chain.from_iterable(names))

    @staticmethod
    def prepare_location(obj):
        creds = getattr(obj, 'nonrevoked', obj.credentials.filter(revoked=False))
        locations = []
        for credential in creds:
            for address in credential.addresses.all():
{'fraction_non_alphanumeric': 0.08238387379491674, 'fraction_numerical': 0.0026292725679228747, 'mean_word_length': 3.8574468085106384, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4647685', 'n_tokens_mistral': 653, 'n_tokens_neox': 627, 'n_words': 194}