documentcloud / visualsearch

A Rich Search Box for Real Data
http://documentcloud.github.com/visualsearch
MIT License
1.8k stars 237 forks source link

Allow a default / assumed facet #133

Closed brycecorkins closed 10 years ago

brycecorkins commented 10 years ago

I'm trying to modify visualsearch so that if there is only a single facet passed into the callback, this facet will be assumed as the user's choice and the values dropdown will appear in the same step.

i.e. if only State was passed in as a facet, a click on the search box would bring up a dropdown of states instead of a dropdown with "State" as the only entry.

I know I can hide the facet label easily enough with CSS, but is there an easy way to trigger the facet selection programatically (and bring up the value dropdown) without requiring the user to click it?

brycecorkins commented 10 years ago

Answered my own question. Dumb luck mostly, and it's ugly, but it does work:

            facetMatches: function(callback) {
                var facets; //array of facets

                if(facets.length == 1) {
                    visualSearch.searchBox.addFacet(facets[0], '', 99);
                } else {
                    callback(facets, {
                        preserveOrder: true
                    });
                }
            }