function createFacetUI() {
        var itemtemplate = _.template(settings.listItemTemplate);
        var titletemplate = _.template(settings.facetTitleTemplate);
        var containertemplate = _.template(settings.facetContainer);

        $(settings.facetSelector).html("");
        _.each(settings.facets, function (facettitle, facet) {
            var facetHtml = $(containertemplate({id: facet}));
            var facetItem = {title: facettitle};
            var facetItemHtml = $(titletemplate(facetItem));

            facetHtml.append(facetItemHtml);
            var facetlist = $(settings.facetListContainer);
            _.each(settings.facetStore[facet], function (filter, filtername) {
                var item = {id: filter.id, name: filtername, count: filter.count};
                var filteritem = $(itemtemplate(item));
                if (_.indexOf(settings.state.filters[facet], filtername) >= 0) {
                    filteritem.addClass("activefacet");
                }
                facetlist.append(filteritem);
            });
            facetHtml.append(facetlist);
            $(settings.facetSelector).append(facetHtml);
        });
        // add the click event handler to each facet item:
        $('.facetitem').click(function (event) {
            var filter = getFilterById(this.id);
            toggleFilter(filter.facetname, filter.filtername);
            $(settings.facetSelector).trigger("facetedsearchfacetclick", filter);
            order();
            updateFacetUI();
            updateResults();
        });
        // Append total result count
        var bottom = $(settings.bottomContainer);

        var countCompile = _.template(settings.countTemplate);
        var countHTML = countCompile({count: settings.currentResults.length});
        $(bottom).append(countHTML);
        // generate the "order by" options:
        var ordertemplate = _.template(settings.orderByTemplate);
        var itemHtml = $(ordertemplate({'options': settings.orderByOptions}));
        $(bottom).append(itemHtml);
        $(settings.facetSelector).append(bottom);
        $('.orderbyitem').each(function () {
            var id = this.id.substr(8);
            if (settings.state.orderBy == id) {
                $(this).addClass("activeorderby");
            }
        });
        // add the click event handler to each "order by" item:
        $('.orderbyitem').click(function (event) {
            var id = this.id.substr(8);
            settings.state.orderBy = id;
            $(settings.facetSelector).trigger("facetedsearchorderby", id);
            settings.state.shownResults = 0;
            order();
            updateResults();
        });
        // Append deselect filters button
        var deselect = $(settings.deselectTemplate).click(function (event) {
            settings.state.filters = {};
            jQuery.facetUpdate();
        });
        $(bottom).append(deselect);
        $(settings.facetSelector).trigger("facetuicreated");
    }
/**
     * This function is only called once, it creates the facets ui.
     */
This function is only called once, it creates the facets ui.
This function is only called once it creates the facets ui .
function createFacetUI() {
        var itemtemplate = _.template(settings.listItemTemplate);
        var titletemplate = _.template(settings.facetTitleTemplate);
        var containertemplate = _.template(settings.facetContainer);
        $(settings.facetSelector).html("");
        _.each(settings.facets, function (facettitle, facet) {
            var facetHtml = $(containertemplate({id: facet}));
            var facetItem = {title: facettitle};
            var facetItemHtml = $(titletemplate(facetItem));
            facetHtml.append(facetItemHtml);
            var facetlist = $(settings.facetListContainer);
            _.each(settings.facetStore[facet], function (filter, filtername) {
                var item = {id: filter.id, name: filtername, count: filter.count};
                var filteritem = $(itemtemplate(item));
                if (_.indexOf(settings.state.filters[facet], filtername) >= 0) {
                    filteritem.addClass("activefacet");
                }
                facetlist.append(filteritem);
            });
            facetHtml.append(facetlist);
            $(settings.facetSelector).append(facetHtml);
        });
        $('.facetitem').click(function (event) {
            var filter = getFilterById(this.id);
            toggleFilter(filter.facetname, filter.filtername);
            $(settings.facetSelector).trigger("facetedsearchfacetclick", filter);
            order();
            updateFacetUI();
            updateResults();
        });
        var bottom = $(settings.bottomContainer);
        var countCompile = _.template(settings.countTemplate);
        var countHTML = countCompile({count: settings.currentResults.length});
        $(bottom).append(countHTML);
        var ordertemplate = _.template(settings.orderByTemplate);
        var itemHtml = $(ordertemplate({'options': settings.orderByOptions}));
        $(bottom).append(itemHtml);
        $(settings.facetSelector).append(bottom);
        $('.orderbyitem').each(function () {
            var id = this.id.substr(8);
            if (settings.state.orderBy == id) {
                $(this).addClass("activeorderby");
            }
        });
        $('.orderbyitem').click(function (event) {
            var id = this.id.substr(8);
            settings.state.orderBy = id;
            $(settings.facetSelector).trigger("facetedsearchorderby", id);
            settings.state.shownResults = 0;
            order();
            updateResults();
        });
        var deselect = $(settings.deselectTemplate).click(function (event) {
            settings.state.filters = {};
            jQuery.facetUpdate();
        });
        $(bottom).append(deselect);
        $(settings.facetSelector).trigger("facetuicreated");
    }
function createFacetUI ( ) { var itemtemplate = _ . template ( settings . listItemTemplate ) ; var titletemplate = _ . template ( settings . facetTitleTemplate ) ; var containertemplate = _ . template ( settings . facetContainer ) ; $ ( settings . facetSelector ) . html ( "" ) ; _ . each ( settings . facets , function ( facettitle , facet ) { var facetHtml = $ ( containertemplate ( { id : facet } ) ) ; var facetItem = { title : facettitle } ; var facetItemHtml = $ ( titletemplate ( facetItem ) ) ; facetHtml . append ( facetItemHtml ) ; var facetlist = $ ( settings . facetListContainer ) ; _ . each ( settings . facetStore [ facet ] , function ( filter , filtername ) { var item = { id : filter . id , name : filtername , count : filter . count } ; var filteritem = $ ( itemtemplate ( item ) ) ; if ( _ . indexOf ( settings . state . filters [ facet ] , filtername ) >= 0 ) { filteritem . addClass ( "activefacet" ) ; } facetlist . append ( filteritem ) ; } ) ; facetHtml . append ( facetlist ) ; $ ( settings . facetSelector ) . append ( facetHtml ) ; } ) ; $ ( '.facetitem' ) . click ( function ( event ) { var filter = getFilterById ( this . id ) ; toggleFilter ( filter . facetname , filter . filtername ) ; $ ( settings . facetSelector ) . trigger ( "facetedsearchfacetclick" , filter ) ; order ( ) ; updateFacetUI ( ) ; updateResults ( ) ; } ) ; var bottom = $ ( settings . bottomContainer ) ; var countCompile = _ . template ( settings . countTemplate ) ; var countHTML = countCompile ( { count : settings . currentResults . length } ) ; $ ( bottom ) . append ( countHTML ) ; var ordertemplate = _ . template ( settings . orderByTemplate ) ; var itemHtml = $ ( ordertemplate ( { 'options' : settings . orderByOptions } ) ) ; $ ( bottom ) . append ( itemHtml ) ; $ ( settings . facetSelector ) . append ( bottom ) ; $ ( '.orderbyitem' ) . each ( function ( ) { var id = this . id . substr ( 8 ) ; if ( settings . state . orderBy == id ) { $ ( this ) . addClass ( "activeorderby" ) ; } } ) ; $ ( '.orderbyitem' ) . click ( function ( event ) { var id = this . id . substr ( 8 ) ; settings . state . orderBy = id ; $ ( settings . facetSelector ) . trigger ( "facetedsearchorderby" , id ) ; settings . state . shownResults = 0 ; order ( ) ; updateResults ( ) ; } ) ; var deselect = $ ( settings . deselectTemplate ) . click ( function ( event ) { settings . state . filters = { } ; jQuery . facetUpdate ( ) ; } ) ; $ ( bottom ) . append ( deselect ) ; $ ( settings . facetSelector ) . trigger ( "facetuicreated" ) ; }
This function is only called once, it creates the facets ui.
This function is only called once it creates the facets ui .
// add the click event handler to each facet item: // Append total result count // generate the "order by" options: // add the click event handler to each "order by" item: // Append deselect filters button