documentcloud / visualsearch

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

Auto Search on SearchBox.setQuery #56

Closed stoussaint closed 12 years ago

stoussaint commented 12 years ago

Hi,

I can't find a way to programmatically execute a search after setting the searchBox query. For instance I display a search screen with a restored search query and i'd like to see the result immediately without to have to press return within the search box.

Is this a feature eligible to Pull Requests or something that I miss ?

Thanks in advance

stoussaint commented 12 years ago

Hi,

I only achieve to do this by simulating the 'keypress' event on 'enter' like this :

var e = jQuery.Event("keypress"); e.which = 13; $("input.ui-autocomplete-input:first").trigger(e);

Is this a good way to do this, or is there something more efficient ?

Thanks

samuelclay commented 12 years ago

Here you go:

// Returns the unstructured search query
visualSearch.searchBox.value() 
// "country: "South Africa" account: 5-samuel title: "Pentagon Papers""

// Returns an array of Facet model instances
visualSearch.searchQuery.facets()
// [FacetModel<country:"South Africa">, 
//  FacetModel<account:5-samuel>, 
//  FacetModel<title:"Pentagon Papers">]

// Set the search query with raw text
visualSearch.searchBox.value("Country: US State: \"New York\" Key: Value")
stoussaint commented 12 years ago

Thanks for those simple get/set commands.

I replace my use of :

visualSearch.searchBox.setQuery(query);

by

visualSearch.searchBox.value(query)

But still the search request is not send automatically. I still need to simulate a keypress event.

samuelclay commented 12 years ago

It's the developer's responsibility for doing something to the search query. So serialize the query using the searchBox.value() method, and then send it using ajax or whatever method you were using.

schue commented 11 years ago

you can trigger the search by using visualSearch.searchBox.searchEvent({}) after setting value() or setQuery(). The empty object is probably an incorrect hack but it doesn't throw an error.