documentcloud / visualsearch

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

Prevent Duplicate Facet #89

Closed devmondo closed 11 years ago

devmondo commented 11 years ago

Hi, awesome work, could we prevent repeating a search on a facet, like right now if user chose to search on country, if he clicks again, the country facet shows up, and this causes incorrect search results.

thanks in advanced.

samuelclay commented 11 years ago

Not sure I understand the issue. I think what you're getting at is that you want to prevent a search from going through if it matches the previous search? I think you should handle this in your implementation and response functions, not in the visualsearch code.

knowtheory commented 11 years ago

And in fact DocumentCloud uses multiple facets and merges them into an OR statement. This is definitely something for a server to decide upon.

devmondo commented 11 years ago

hi, thanks for reply, what i actually meant is not serverside, what i meant if user search on City facet, i dont want him to again, see City from the drop down Facets List, this will confuse him, hope i am clear on this.

nfriend commented 11 years ago

@devmondo - As far as I can tell, this functionality isn't provided by the plugin. However, this effect can be accomplished by querying the searchbox in the plugin's callbacks for the searchbox's current contents and returning only the facets and facet items that haven't already been used. It's a little heavy-handed, but it does work.

brycecorkins commented 10 years ago

For example:

facetMatches: function(callback) {
    var facets = $.parseJSON(your_facet_source);
    var currentFacets = visualSearch.searchQuery.pluck("category");

    facets = facets.filter( function( el ) {
        return currentFacets.indexOf( el ) < 0;
    });

    callback(facets, {
        preserveOrder: true
    });
}