I did a ham-handed way of building my own facets and resetting the query, by doing this:

Coveo.$('#search').on(Coveo.QueryEvents.buildingQuery, createQuery)

Where "createQuery" is my query that sets up all of the search criteria. The catch seems to be that when I do this, it knocks out pagination...I see the paging, but clicking a page number or the arrow to move forward just causes the section to fade out and in without changing pages.

How can I either rebind pagination, or is there a way to quickly reset this to requery Coveo (call my "createQuery" function) without doing off/on?


Calling Coveo.$('#search').off(Coveo.QueryEvents.buildingQuery) not only removes your event, but every other event bound to buildingQuery.

Looking at the Pager code in the coveo-search-ui, its buildingQuery event updates the query like so:

data.queryBuilder.firstResult = eventArgs.first;
data.queryBuilder.numberOfResults = eventArgs.count;

If this event is not triggered, firstResult and numberOfResults would not be updated, thus stalling the pager.

I really think you should not call .off(Coveo.QueryEvents.buildingQuery) as I suspect it will disable every other events that were bound to it.

I would instead suggest to bind your buildingQuery event once in your component initialization. If you needed that .off to temporarily disable your buildingQuery, put this condition directly in your createQuery instead to add your own information to the query only when needed.

  • Also Coveo.$('#search').on(Coveo.QueryEvents.buildingQuery, createQuery) needs to be called only once at the initialization of your search interface. The event handler will be registered once and used every time the search interface needs to build a query for the entire lifetime of the search interface. You generally do not need to unregister your event handler. – Jean-François L'Heureux Nov 18 '16 at 13:29
  • Thanks for the input. So assuming all of my query-building data is in my "createQuery" function, what's the best way to re-execute the function to generate a fresh search result, based on changing criteria? I'm just using standard jQuery to run through my custom checkboxes, etc, to set up the query conditions. I think if I get that right, I don't need to do the .off bit and I spare myself the entire hassle you've correctly pointed out. – Ken McAndrew Nov 18 '16 at 15:26
  • Since the buildingQuery event is triggered every time a query is executed, all you have to do is inject the right values in createQuery depending on what is selected in your facet. You can then do a regular .coveo("executeQuery") to "refresh" the results. – flguillemette Nov 18 '16 at 17:36
  • It's always the easiest thing...perfect. Thanks! – Ken McAndrew Nov 21 '16 at 15:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.