<commit_before>from .es_query import HQESQuery
from . import filters


class SMSES(HQESQuery):
    index = 'sms'

    @property
    def builtin_filters(self):
        return [
            incoming_messages,
            outgoing_messages,
            to_commcare_user,
            to_commcare_case,
            to_web_user,
            to_couch_user,
            to_commcare_user_or_case,
            received,
        ] + super(SMSES, self).builtin_filters


def incoming_messages():
    return filters.term("direction", "i")


def outgoing_messages():
    return filters.term("direction", "o")


def to_commcare_user():
    return filters.term("couch_recipient_doc_type", "commcareuser")


def to_commcare_case():
    return filters.term("couch_recipient_doc_type", "commcarecase")


def to_web_user():
    return filters.term("couch_recipient_doc_type", "webuser")

<commit_msg>Add user facet for SMS<commit_after>from .es_query import HQESQuery
from . import filters


class SMSES(HQESQuery):
    index = 'sms'

    @property
    def builtin_filters(self):
        return [
            incoming_messages,
            outgoing_messages,
            to_commcare_user,
            to_commcare_case,
            to_web_user,
            to_couch_user,
            to_commcare_user_or_case,
            received,
        ] + super(SMSES, self).builtin_filters

    def user_facet(self, size=None):
        return self.terms_facet('couch_recipient', 'user', size=size)


def incoming_messages():
    return filters.term("direction", "i")


def outgoing_messages():
    return filters.term("direction", "o")


def to_commcare_user():
    return filters.term("couch_recipient_doc_type", "commcareuser")


def to_commcare_case():
    return filters.term("couch_recipient_doc_type", "commcarecase")


def to_web_user():
    return filters.term("couch_recipient_doc_type", "webuser")


{'fraction_non_alphanumeric': 0.09856153436334576, 'fraction_numerical': 0.0, 'mean_word_length': 3.0128205128205128, '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': '880378', 'n_tokens_mistral': 619, 'n_tokens_neox': 588, 'n_words': 111}