Gravatar for jschjolberg@awareweb.com

Question by jschjolberg, Jun 16, 2014 8:08 AM

Are There jQuery Extension Methods for SearchBox and SearchInterface Components?

I'm trying to write out a custom summary on my search results page. I'm using the JavaScript Search Framework. I'm wondering if there is a way to access the SearchBox text and the number of results from the SearchInterface using jQuery Extension Methods so I could write out something like this:

"Your search for 'keyword' returned 66 results."

Or, if there is another way to do this, I'd appreciate the help. Thanks!

1 Reply
Gravatar for mlaporte@coveo.com

Answer by Martin Laporte, Jun 16, 2014 8:18 AM

The current query is accessible through the state as in this example:

var query = $('#search').coveo('state', 'q');

This is described here: https://developers.coveo.com/display/JsSearch/State

Then, everytime a query succeeds, the 'querySuccess' event is raised. From where you can get the number of results using the totalCount field. Ex:

$('#search').on('querySuccess', function(e, data) {
  val count = data.results.totalCount;
  ...
});

Relevant doc here: https://developers.coveo.com/display/JsSearch/Events

Gravatar for jschjolberg@awareweb.com

Comment by jschjolberg, Jun 16, 2014 8:22 AM

Thank you - I will try this out.

Ask a question