<commit_before>window.SearchView = function(options) {
    var el = options['el'];
    var type = 'type' in options ? options['type'] : 'server';
    var pagination = 'pagination' in options ? options['pagination'] : false;
    var collection = options['collection'];
    var page_size = options['page_size'] || 10;
    var type = 'type' in options ? options['type'] : 'server';
    var facets = options['facets'] || [];
    var query_obj = {};

    var parseFacets = function (loaded_facets, facet) {
        return _.map(_.compact(_.uniq(_.pluck(loaded_facets, facet))), function(val) { return String(val); });
    }

    el.html(template.mediasearch({type: type, pagination: pagination}));
    console.log('Render: SearchView');

    switch(pagination) {
        case 'traditional':
            collection.switchMode('server', {fetch: false});
            collection.setPageSize(page_size,{fetch:false, first: true});
            renderBootstrapPaginator();
            break;
        case 'endless':
            var offset = 100;
            var wait = 100;
            collection.switchMode('endless', {fetch: false});
            collection.setPageSize(page_size,{fetch: false, first: true});
            var scroll_callback = function () {
                if ($(window).scrollTop() >= ( $(document).height() - $(window).height() - offset)
                     && collection.hasNext() ){
                    collection.getNextPage();
                }
            };

            var throttled = _.throttle(scroll_callback, wait);
            $(window).scroll(throttled);
            break;

        case false: break;
        default:
    }

    switch(type) {
        case 'server':
            var loaded_facets = {};
            var searchBox = $('.visual_search', el);
            var visualSearch = VS.init({
                container : searchBox,
                query     : '',
                showFacets: true,
                placeholder: '',
                callbacks : {
                    clearSearch: function(clear_cb) {
                        clear_cb();
                        query_obj = {};
                        searchOnServer();
                    },
                    search: function(query, searchCollection) {
                        query_obj = _.object(searchCollection.pluck('category'), searchCollection.pluck('value'));
                        searchOnServer();
                    },
                    facetMatches : function(callback) {
                        callback(facets);
                    },
                    valueMatches : function(facet, searchTerm, callback) {
                        var options = {preserveOrder: true};
                        if (!loaded_facets.length) {
                            Backbone.sync('read', collection, {
                                silent: true,
                                data: { fields: facets },
                                success: function(res) {
                                    loaded_facets = res[1];
                                    var f = parseFacets(loaded_facets, facet);
                                    callback(f, options);
                                }
                            });
                        } else {
                            var f = parseFacets(loaded_facets, facet);
                            callback(f, options);
                        }
                    },
                    focus: function() {
                    },
                    blur: function() {
                    }
                }
            });
            break;
        case 'client': break;
        default:
    }

    function renderBootstrapPaginator() {
        $(".pagination", el).html("");
        if(collection.state.totalPages > 1) {
            var pag_options = { currentPage: 1,
                totalPages: collection.state.totalPages ,
                size: 'mini',
                onPageClicked: function(e, originalEvent, type, page) {
                    collection.getPage((page-1));
                }
            };
            $(".pagination", el).bootstrapPaginator(pag_options);
        }
    }

    function searchOnServer() {
        collection.setQuery(query_obj, page_size);
        collection.fetch({ success: function() {
            if( pagination == 'traditional') {
                renderBootstrapPaginator();
            }
        }});
    }

    return;
}<commit_msg>Not showing always facets, just when typing<commit_after>window.SearchView = function(options) {
    var el = options['el'];
    var type = 'type' in options ? options['type'] : 'server';
    var pagination = 'pagination' in options ? options['pagination'] : false;
    var collection = options['collection'];
    var page_size = options['page_size'] || 10;
    var type = 'type' in options ? options['type'] : 'server';
    var facets = options['facets'] || [];
    var query_obj = {};

    var parseFacets = function (loaded_facets, facet) {
        return _.map(_.compact(_.uniq(_.pluck(loaded_facets, facet))), function(val) { return String(val); });
    }

    el.html(template.mediasearch({type: type, pagination: pagination}));
    console.log('Render: SearchView');

    switch(pagination) {
        case 'traditional':
            collection.switchMode('server', {fetch: false});
            collection.setPageSize(page_size,{fetch:false, first: true});
            renderBootstrapPaginator();
            break;
        case 'endless':
            var offset = 100;
            var wait = 100;
            collection.switchMode('endless', {fetch: false});
            collection.setPageSize(page_size,{fetch: false, first: true});
            var scroll_callback = function () {
                if ($(window).scrollTop() >= ( $(document).height() - $(window).height() - offset)
                     && collection.hasNext() ){
                    collection.getNextPage();
                }
            };

            var throttled = _.throttle(scroll_callback, wait);
            $(window).scroll(throttled);
            break;

        case false: break;
        default:
    }

    switch(type) {
        case 'server':
            var loaded_facets = {};
            var searchBox = $('.visual_search', el);
            var visualSearch = VS.init({
                container : searchBox,
                query     : '',
                showFacets: false,
                placeholder: '',
                callbacks : {
                    clearSearch: function(clear_cb) {
                        clear_cb();
                        query_obj = {};
                        searchOnServer();
                    },
                    search: function(query, searchCollection) {
                        query_obj = _.object(searchCollection.pluck('category'), searchCollection.pluck('value'));
                        searchOnServer();
                    },
                    facetMatches : function(callback) {
                        callback(facets);
                    },
                    valueMatches : function(facet, searchTerm, callback) {
                        var options = {preserveOrder: true};
                        if (!loaded_facets.length) {
                            Backbone.sync('read', collection, {
                                silent: true,
                                data: { fields: facets },
                                success: function(res) {
                                    loaded_facets = res[1];
                                    var f = parseFacets(loaded_facets, facet);
                                    callback(f, options);
                                }
                            });
                        } else {
                            var f = parseFacets(loaded_facets, facet);
                            callback(f, options);
                        }
                    },
                    focus: function() {
                    },
                    blur: function() {
                    }
                }
            });
            searchBox.find('input').focus();
            break;
        case 'client': break;
        default:
    }

    function renderBootstrapPaginator() {
        $(".pagination", el).html("");
        if(collection.state.totalPages > 1) {
            var pag_options = { currentPage: 1,
                totalPages: collection.state.totalPages ,
                size: 'mini',
                onPageClicked: function(e, originalEvent, type, page) {
                    collection.getPage((page-1));
                }
            };
            $(".pagination", el).bootstrapPaginator(pag_options);
        }
    }

    function searchOnServer() {
        collection.setQuery(query_obj, page_size);
        collection.fetch({ success: function() {
            if( pagination == 'traditional') {
                renderBootstrapPaginator();
            }
        }});
    }

    return;
}
{'fraction_non_alphanumeric': 0.11559919660790002, 'fraction_numerical': 0.0026779736665922785, 'mean_word_length': 1.2993842996408416, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '752833', 'n_tokens_mistral': 2234, 'n_tokens_neox': 2075, 'n_words': 431}