<commit_before>from elasticsearch_dsl import DocType, Object, String, Completion, Nested, Date, Boolean


class NoneAwareDate(Date):
    """Elasticsearch DSL Date field chokes on None values and parses empty
    strings as current date, hence the workaround.
    TODO: move this upstream in some form."""
    def _to_python(self, data):
        if data is None:
            return data
        return super(NoneAwareDate, self)._to_python(data)


class Declaration(DocType):
    """Declaration document.
    Assumes there's a dynamic mapping with all fields not indexed by default."""
    general = Object(
        properties={
            'full_name_suggest': Completion(preserve_separators=False),
            'full_name': String(index='analyzed'),
            'name': String(index='analyzed'),
            'patronymic': String(index='analyzed'),
            'last_name': String(index='analyzed'),
            'family_raw': String(index='analyzed'),
            'family': Nested(
                properties={
                    'name': String(index='analyzed'),
                    'relations': String(index='no'),
                    'inn': String(index='no')
                }
            ),
            'post_raw': String(index='analyzed'),
            'post': Object(
                properties={
                    'region': String(index='not_analyzed'),
                    'office': String(index='not_analyzed'),
                    'post': String(index='analyzed')
                }
            )
        }
    )
    declaration = Object(
        properties={
            'date': NoneAwareDate(),
            'notfull': Boolean(index='no'),
            'notfull_lostpages': String(index='no'),
            'additional_info': Boolean(index='no'),
            'additional_info_text': String(index='no'),
            'needs_scancopy_check': Boolean(index='no')
        }
    )

    class Meta:
        index = 'catalog'<commit_msg>Renamed index<commit_after>from elasticsearch_dsl import DocType, Object, String, Completion, Nested, Date, Boolean


class NoneAwareDate(Date):
    """Elasticsearch DSL Date field chokes on None values and parses empty
    strings as current date, hence the workaround.
    TODO: move this upstream in some form."""
    def _to_python(self, data):
        if data is None:
            return data
        return super(NoneAwareDate, self)._to_python(data)


class Declaration(DocType):
    """Declaration document.
    Assumes there's a dynamic mapping with all fields not indexed by default."""
    general = Object(
        properties={
            'full_name_suggest': Completion(preserve_separators=False),
            'full_name': String(index='analyzed'),
            'name': String(index='analyzed'),
            'patronymic': String(index='analyzed'),
            'last_name': String(index='analyzed'),
            'family_raw': String(index='analyzed'),
            'family': Nested(
                properties={
                    'name': String(index='analyzed'),
                    'relations': String(index='no'),
                    'inn': String(index='no')
                }
            ),
            'post_raw': String(index='analyzed'),
            'post': Object(
                properties={
                    'region': String(index='not_analyzed'),
                    'office': String(index='not_analyzed'),
                    'post': String(index='analyzed')
                }
            )
        }
    )
    declaration = Object(
        properties={
            'date': NoneAwareDate(),
            'notfull': Boolean(index='no'),
            'notfull_lostpages': String(index='no'),
            'additional_info': Boolean(index='no'),
            'additional_info_text': String(index='no'),
            'needs_scancopy_check': Boolean(index='no')
        }
    )

    class Meta:
        index = 'declarations'
{'fraction_non_alphanumeric': 0.12406692406692407, 'fraction_numerical': 0.0, 'mean_word_length': 2.0359375, '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': '7309792', 'n_tokens_mistral': 1040, 'n_tokens_neox': 994, 'n_words': 238}