<commit_before>{% set nb_displayed_aggregations = 5 %}

{% macro breadcrum_toolbar(result, url=None, exports=None) %}
{% if kwargs %}
    {% set to_url = result.to_url %}
    {% if in_url('sort') %}
        {% if request.args.sort.startswith('-') %}
            {% set current_sort, current_order = request.args.sort[1:], 'desc' %}
        {% else %}
            {% set current_sort, current_order = request.args.sort, 'asc' %}
        {% endif %}
        {% if current_sort in kwargs %}
            {% set label, default_order = kwargs[current_sort] %}
        {% endif %}
    {% endif %}
{% endif %}
<span class="text">{{ _('Sort by') }}</span>
<div class="btn-group">
    <button type="button" class="btn btn-sorter btn-xs dropdown-toggle" data-toggle="dropdown">
        <span class="fa fa-fw fa-chevron-down hidden-sm"></span>
        {{ label|truncate(12, True) or '---' }}
    </button>
    <ul class="dropdown-menu">
        <li>
            <a href="{{ to_url(url=url, sort=None) }}">
                ---
            </a>
        </li>
        {% for field, (label, order) in kwargs.items() %}
            {% set sort = field if order == 'asc' else '-'+field %}
            <li>
                <a href="{{ to_url(url=url, replace=True, sort=sort) }}">
                    {{ label }}
                </a>
            </li>
        {% endfor %}
    </ul>
</div>
{% if current_sort and current_order and default_order %}
    {% set btn_class = 'btn-default' if current_order == default_order else 'btn-warning' %}
    <a class="btn {{ btn_class }} btn-xs"
        href="{{ to_url(url=url, replace=True, sort=current_sort if current_order == 'desc' else '-'+current_sort) }}"
        title="{{ _('Ascending') if current_order == 'asc' else _('Descending') }}">
        <span class="fa fa-sort-amount-{{current_order}}"></span>
    </a>
{% endif %}
{% if result.total and exports %}
    <div class="dropdown pull-right">
        <button class="btn btn-xs btn-warning export-btn dropdown-toggle" type="button" id="export-btn" data-toggle="dropdown">
            <span class="fa fa-download"></span>
        </button>
        <ul class="dropdown-menu" role="menu" aria-labelledby="export-btn">
            <li role="presentation" class="dropdown-header">{{ _('Export') }}</li>
            {% for label, endpoint, type in exports %}
            <li role="presentation">
                <a role="menuitem" tabindex="-1" href="{{ to_url(
                    url_for(endpoint), facets=None, page=None, page_size=None, replace=true)
                }}">
                {{label}}
                <span class="label label-primary">{{type}}</span>
                </a>
            </li>
            {% endfor %}
        </ul>
    </div>
{% endif %}
{% endmacro %}

{% macro filter_label(name, label, icon=None, labelize=None) %}
{% set values = request.args.getlist(name) or [] %}
{% for value in values %}
<span class="tag label label-info" title="{{ label }}">
    {% if icon %}
    <span class="{{ icon }} fa-fw"></span>
    {% endif %}
    <span>{{ labelize(value) if labelize else value }}</span>
    <a href="{{ ''|url_del('page', **{name: value}) }}">
        <span class="close-icon glyphicon glyphicon-remove"></span>
    </a>
</span>
{% endfor %}
{% endmacro %}

{% macro facet_panel(result, name, label, icon=None, url=None) %}
<div class="panel-heading clickable"
    data-toggle="collapse" data-target="#collapse-{{result.class_name}}-{{name}}">
    <h3 class="panel-title">
        {% if in_url(name) %}
        <a href="{{ url_del(None, name, 'page') }}"
            class="btn btn-xs btn-link pull-right" title="{{ _('Clear filter') }}">
            <span class="glyphicon glyphicon-remove"></span>
        </a>
        {% endif %}
        <span class="{{icon or 'glyphicon glyphicon-filter'}} fa-fw"></span>
        {{ label or name }}
        <span class="fa fa-chevron-down pull-right chevrons"></span>
    </h3>
</div>
{% endmacro %}


{% macro terms_facet(result, name, label, icon, url=None) %}
{% set terms = result.facets[name] %}
{% if terms|length > 1 %}
    {{ facet_panel(result, name, label, icon, url) }}
    <div id="collapse-{{result.class_name}}-{{name}}" class="list-group collapse in">
    {% for term, count, selected in terms[:nb_displayed_aggregations] %}
        <a href="{{ result.query.to_url(url, **{name: term}) }}"
            class="list-group-item">
            {{ result.query.facets[name].labelize('', term) }}
            <span class="badge pull-right">{{ count }}</span>
        </a>
    {% endfor %}
    {% if terms|length > nb_displayed_aggregations %}
        <button class="list-group-item"
            data-toggle="collapse" data-target="#collapse-{{result.class_name}}-{{name}}-more">
            {{ _('More results…') }}
            <span class="fa fa-chevron-right pull-right"></span>
        </button>
        <div id="collapse-{{result.class_name}}-{{name}}-more" class="list-group collapse list-group-more">
        {% for term, count, selected in terms[nb_displayed_aggregations:] %}
            <a href="{{ result.query.to_url(url, **{name: term}) }}"
                class="list-group-item">
                {{ result.query.facets[name].labelize('', term) }}
                <span class="badge pull-right">{{ count }}</span>
            </a>
        {% endfor %}
        </div>
    {% endif %}
    </div>
{% endif %}
{% endmacro %}


{% macro model_terms_facet(result, name, label, icon, url=None) %}
{% set objects = result.facets[name] %}
{% if objects|length > 1 %}
    {{ facet_panel(result, name, label, icon, url) }}
    <div id="collapse-{{result.class_name}}-{{name}}" class="list-group collapse in">
    {% for obj, count, selected in objects[:nb_displayed_aggregations] %}
        <a href="{{ result.query.to_url(url, **{name: obj.id|string}) }}"
            class="list-group-item">
            {{ result.query.facets[name].labelize('', obj) }}
            <span class="badge pull-right">{{ count }}</span>
        </a>
    {% endfor %}
    {% if objects|length > nb_displayed_aggregations %}
        <button class="list-group-item list-group-more"
            data-toggle="collapse" data-target="#collapse-{{result.class_name}}-{{name}}-more">
            {{ _('More results…') }}
            <span class="fa fa-chevron-right pull-right"></span>
        </button>
        <div id="collapse-{{result.class_name}}-{{name}}-more" class="list-group collapse list-group-more">
        {% for obj, count, selected in objects[nb_displayed_aggregations:] %}
            <a href="{{ result.query.to_url(url, **{name: obj.id|string}) }}"
                class="list-group-item">
                {{ result.query.facets[name].labelize('', obj) }}
                <span class="badge pull-right">{{ count }}</span>
            </a>
        {% endfor %}
        </div>
    {% endif %}
    </div>
{% endif %}
{% endmacro %}

{% macro range_facet(result, name, label, icon, url=None) %}
{% set ranges = result.facets[name] %}
{% if ranges|length > 1 %}
    {{ facet_panel(result, name, label, icon, url) }}
    <div id="collapse-{{result.class_name}}-{{name}}" class="list-group collapse in">
    {% for key, count, selected in ranges %}
        <a href="{{ result.query.to_url(url, **{name: key}) }}"
            class="list-group-item">
            {{ result.query.facets[name].labelize('', key) }}
            <span class="badge pull-right">{{ count }}</span>
        </a>
    {% endfor %}<commit_msg>Fixes on labelize in search macros<commit_after>{% set nb_displayed_aggregations = 5 %}

{% macro breadcrum_toolbar(result, url=None, exports=None) %}
{% if kwargs %}
    {% set to_url = result.to_url %}
    {% if in_url('sort') %}
        {% if request.args.sort.startswith('-') %}
            {% set current_sort, current_order = request.args.sort[1:], 'desc' %}
        {% else %}
            {% set current_sort, current_order = request.args.sort, 'asc' %}
        {% endif %}
        {% if current_sort in kwargs %}
            {% set label, default_order = kwargs[current_sort] %}
        {% endif %}
    {% endif %}
{% endif %}
<span class="text">{{ _('Sort by') }}</span>
<div class="btn-group">
    <button type="button" class="btn btn-sorter btn-xs dropdown-toggle" data-toggle="dropdown">
        <span class="fa fa-fw fa-chevron-down hidden-sm"></span>
        {{ label|truncate(12, True) or '---' }}
    </button>
    <ul class="dropdown-menu">
        <li>
            <a href="{{ to_url(url=url, sort=None) }}">
                ---
            </a>
        </li>
        {% for field, (label, order) in kwargs.items() %}
            {% set sort = field if order == 'asc' else '-'+field %}
            <li>
                <a href="{{ to_url(url=url, replace=True, sort=sort) }}">
                    {{ label }}
                </a>
            </li>
        {% endfor %}
    </ul>
</div>
{% if current_sort and current_order and default_order %}
    {% set btn_class = 'btn-default' if current_order == default_order else 'btn-warning' %}
    <a class="btn {{ btn_class }} btn-xs"
        href="{{ to_url(url=url, replace=True, sort=current_sort if current_order == 'desc' else '-'+current_sort) }}"
        title="{{ _('Ascending') if current_order == 'asc' else _('Descending') }}">
        <span class="fa fa-sort-amount-{{current_order}}"></span>
    </a>
{% endif %}
{% if result.total and exports %}
    <div class="dropdown pull-right">
        <button class="btn btn-xs btn-warning export-btn dropdown-toggle" type="button" id="export-btn" data-toggle="dropdown">
            <span class="fa fa-download"></span>
        </button>
        <ul class="dropdown-menu" role="menu" aria-labelledby="export-btn">
            <li role="presentation" class="dropdown-header">{{ _('Export') }}</li>
            {% for label, endpoint, type in exports %}
            <li role="presentation">
                <a role="menuitem" tabindex="-1" href="{{ to_url(
                    url_for(endpoint), facets=None, page=None, page_size=None, replace=true)
                }}">
                {{label}}
                <span class="label label-primary">{{type}}</span>
                </a>
            </li>
            {% endfor %}
        </ul>
    </div>
{% endif %}
{% endmacro %}

{% macro filter_label(name, label, icon=None, labelize=None) %}
{% set values = request.args.getlist(name) or [] %}
{% for value in values %}
<span class="tag label label-info" title="{{ label }}">
    {% if icon %}
    <span class="{{ icon }} fa-fw"></span>
    {% endif %}
    <span>{{ labelize(value) if labelize else value }}</span>
    <a href="{{ ''|url_del('page', **{name: value}) }}">
        <span class="close-icon glyphicon glyphicon-remove"></span>
    </a>
</span>
{% endfor %}
{% endmacro %}

{% macro facet_panel(result, name, label, icon=None, url=None) %}
<div class="panel-heading clickable"
    data-toggle="collapse" data-target="#collapse-{{result.class_name}}-{{name}}">
    <h3 class="panel-title">
        {% if in_url(name) %}
        <a href="{{ url_del(None, name, 'page') }}"
            class="btn btn-xs btn-link pull-right" title="{{ _('Clear filter') }}">
            <span class="glyphicon glyphicon-remove"></span>
        </a>
        {% endif %}
        <span class="{{icon or 'glyphicon glyphicon-filter'}} fa-fw"></span>
        {{ label or name }}
        <span class="fa fa-chevron-down pull-right chevrons"></span>
    </h3>
</div>
{% endmacro %}


{% macro terms_facet(result, name, label, icon, url=None) %}
{% set terms = result.facets[name] %}
{% if terms|length > 1 %}
    {{ facet_panel(result, name, label, icon, url) }}
    <div id="collapse-{{result.class_name}}-{{name}}" class="list-group collapse in">
    {% for term, count, selected in terms[:nb_displayed_aggregations] %}
        <a href="{{ result.query.to_url(url, **{name: term}) }}"
            class="list-group-item">
            {{ result.query.facets[name].labelize(term) }}
            <span class="badge pull-right">{{ count }}</span>
        </a>
    {% endfor %}
    {% if terms|length > nb_displayed_aggregations %}
        <button class="list-group-item"
            data-toggle="collapse" data-target="#collapse-{{result.class_name}}-{{name}}-more">
            {{ _('More results…') }}
            <span class="fa fa-chevron-right pull-right"></span>
        </button>
        <div id="collapse-{{result.class_name}}-{{name}}-more" class="list-group collapse list-group-more">
        {% for term, count, selected in terms[nb_displayed_aggregations:] %}
            <a href="{{ result.query.to_url(url, **{name: term}) }}"
                class="list-group-item">
                {{ result.query.facets[name].labelize(term) }}
                <span class="badge pull-right">{{ count }}</span>
            </a>
        {% endfor %}
        </div>
    {% endif %}
    </div>
{% endif %}
{% endmacro %}


{% macro model_terms_facet(result, name, label, icon, url=None) %}
{% set objects = result.facets[name] %}
{% if objects|length > 1 %}
    {{ facet_panel(result, name, label, icon, url) }}
    <div id="collapse-{{result.class_name}}-{{name}}" class="list-group collapse in">
    {% for obj, count, selected in objects[:nb_displayed_aggregations] %}
        <a href="{{ result.query.to_url(url, **{name: obj.id|string}) }}"
            class="list-group-item">
            {{ result.query.facets[name].labelize(obj) }}
            <span class="badge pull-right">{{ count }}</span>
        </a>
    {% endfor %}
    {% if objects|length > nb_displayed_aggregations %}
        <button class="list-group-item list-group-more"
            data-toggle="collapse" data-target="#collapse-{{result.class_name}}-{{name}}-more">
            {{ _('More results…') }}
            <span class="fa fa-chevron-right pull-right"></span>
        </button>
        <div id="collapse-{{result.class_name}}-{{name}}-more" class="list-group collapse list-group-more">
        {% for obj, count, selected in objects[nb_displayed_aggregations:] %}
            <a href="{{ result.query.to_url(url, **{name: obj.id|string}) }}"
                class="list-group-item">
                {{ result.query.facets[name].labelize(obj) }}
                <span class="badge pull-right">{{ count }}</span>
            </a>
        {% endfor %}
        </div>
    {% endif %}
    </div>
{% endif %}
{% endmacro %}

{% macro range_facet(result, name, label, icon, url=None) %}
{% set ranges = result.facets[name] %}
{% if ranges|length > 1 %}
    {{ facet_panel(result, name, label, icon, url) }}
    <div id="collapse-{{result.class_name}}-{{name}}" class="list-group collapse in">
    {% for key, count, selected in ranges %}
        <a href="{{ result.query.to_url(url, **{name: key}) }}"
            class="list-group-item">
            {{ result.query.facets[name].labelize(key) }}
            <span class="badge pull-right">{{ count }}</span>
        </a>
    {% endfor %}
{'fraction_non_alphanumeric': 0.19536224113665304, 'fraction_numerical': 0.0013403927350713759, 'mean_word_length': 2.5251594613749115, 'pattern_counts': {'":': 0, '<': 197, '<?xml version=': 0, '>': 207, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5697164', 'n_tokens_mistral': 4998, 'n_tokens_neox': 4575, 'n_words': 1020}