documentcloud / visualsearch

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

Make visualsearch work with the new history api to enable 'back button' functionality #47

Closed fourlincoln10 closed 12 years ago

fourlincoln10 commented 12 years ago

It would be nice if there was any easy way to push facets and their values into the browser history using pushState and then pop them off again and recreate all of the facets/values and rerun the search when the user hits the back button.

samuelclay commented 12 years ago

You can. Since Backbone is already present on the page, you can just hook into vs.app.searchQuery's events: [add, remove].

On the demo.html page, try adding the following: window.visualSearch.searchQuery.bind('add', function() { console.log(['Added', arguments]); })

Additionally, you could serialize the facet and stick it into pushState call in the search callback:

 callbacks  : {
        search : function(query, searchCollection) {
          console.log(["query", searchCollection.facets(), query]);
        }
 }

You can then set the value with:

window.visualSearch.searchBox.value("Hello: world")