function filter() {
        // first apply the filters to the items
        settings.currentResults = _.select(settings.items, function (item) {
            var filtersApply = true;
            _.each(settings.state.filters, function (filter, facet) {
                if ($.isArray(item[facet])) {
                    var inters = _.intersection(item[facet], filter);
                    if (inters.length == 0) {
                        filtersApply = false;
                    }
                } else {
                    if (filter.length && _.indexOf(filter, item[facet]) == -1) {
                        filtersApply = false;
                    }
                }
            });
            return filtersApply;
        });
        // Update the count for each facet and item:
        // intialize the count to be zero
        resetFacetCount();
        // then reduce the items to get the current count for each facet
        _.each(settings.facets, function (facettitle, facet) {
            _.each(settings.currentResults, function (item) {
                if ($.isArray(item[facet])) {
                    _.each(item[facet], function (facetitem) {
                        settings.facetStore[facet][facetitem].count += 1;
                    });
                } else {
                    if (item[facet] !== undefined) {
                        settings.facetStore[facet][item[facet]].count += 1;
                    }
                }
            });
        });
        // remove confusing 0 from facets where a filter has been set
        _.each(settings.state.filters, function (filters, facettitle) {
            _.each(settings.facetStore[facettitle], function (facet) {
                if (facet.count == 0 && settings.state.filters[facettitle].length) facet.count = "+";
            });
        });
        settings.state.shownResults = 0;
    }
/**
     * Filters all items from the settings according to the currently
     * set filters and stores the results in the settings.currentResults.
     * The number of items in each filter from each facet is also updated
     */
Filters all items from the settings according to the currently
set filters and stores the results in the settings.currentResults.
The number of items in each filter from each facet is also updated
Filters all items from the settings according to the currently set filters and stores the results in the settings . currentResults . The number of items in each filter from each facet is also updated
function filter() {
        settings.currentResults = _.select(settings.items, function (item) {
            var filtersApply = true;
            _.each(settings.state.filters, function (filter, facet) {
                if ($.isArray(item[facet])) {
                    var inters = _.intersection(item[facet], filter);
                    if (inters.length == 0) {
                        filtersApply = false;
                    }
                } else {
                    if (filter.length && _.indexOf(filter, item[facet]) == -1) {
                        filtersApply = false;
                    }
                }
            });
            return filtersApply;
        });
        resetFacetCount();
        _.each(settings.facets, function (facettitle, facet) {
            _.each(settings.currentResults, function (item) {
                if ($.isArray(item[facet])) {
                    _.each(item[facet], function (facetitem) {
                        settings.facetStore[facet][facetitem].count += 1;
                    });
                } else {
                    if (item[facet] !== undefined) {
                        settings.facetStore[facet][item[facet]].count += 1;
                    }
                }
            });
        });
        _.each(settings.state.filters, function (filters, facettitle) {
            _.each(settings.facetStore[facettitle], function (facet) {
                if (facet.count == 0 && settings.state.filters[facettitle].length) facet.count = "+";
            });
        });
        settings.state.shownResults = 0;
    }
function filter ( ) { settings . currentResults = _ . select ( settings . items , function ( item ) { var filtersApply = true ; _ . each ( settings . state . filters , function ( filter , facet ) { if ( $ . isArray ( item [ facet ] ) ) { var inters = _ . intersection ( item [ facet ] , filter ) ; if ( inters . length == 0 ) { filtersApply = false ; } } else { if ( filter . length && _ . indexOf ( filter , item [ facet ] ) == - 1 ) { filtersApply = false ; } } } ) ; return filtersApply ; } ) ; resetFacetCount ( ) ; _ . each ( settings . facets , function ( facettitle , facet ) { _ . each ( settings . currentResults , function ( item ) { if ( $ . isArray ( item [ facet ] ) ) { _ . each ( item [ facet ] , function ( facetitem ) { settings . facetStore [ facet ] [ facetitem ] . count += 1 ; } ) ; } else { if ( item [ facet ] !== undefined ) { settings . facetStore [ facet ] [ item [ facet ] ] . count += 1 ; } } } ) ; } ) ; _ . each ( settings . state . filters , function ( filters , facettitle ) { _ . each ( settings . facetStore [ facettitle ] , function ( facet ) { if ( facet . count == 0 && settings . state . filters [ facettitle ] . length ) facet . count = "+" ; } ) ; } ) ; settings . state . shownResults = 0 ; }
Filters all items from the settings according to the currently
 set filters and stores the results in the settings.currentResults.
Filters all items from the settings according to the currently set filters and stores the results in the settings . currentResults .
// first apply the filters to the items // Update the count for each facet and item: // intialize the count to be zero // then reduce the items to get the current count for each facet // remove confusing 0 from facets where a filter has been set