I recently ran into this issue with Coveo for Sitecore 5, and couldn’t find any reference to this issue on other blogs, nor receive any guidance for a resolution from Coveo. Just in case anyone else encounters this issue, I wanted to share the resolution that I found.
We had recently made a change to modify both the number of results on a Coveo page, as well as change the default layout from the list view to the card view. The problem was that this was appending two hash parameters to the URL, resulting in URLs ending with “#layout=card&numberOfResults=12”. This issue was occurring on every page of our site with a Coveo search interface.
This problem was occurring because all of our Coveo search interfaces had history tracking enabled. The history tracking was enabled so that users could share links directly to the search that they had performed. We couldn’t just turn the history off.
To get around this, I essentially hooked in to 2 events for each search interface – the “afterInitialization” event, and the “newQuery” event. There, I could turn the history tracking off when the interface was first initialized, and turn it back on after the first query was executed after page load. Then, any search modifications the user makes would be saved in the page history as hash parameters.
Coveo.$$({searchInterfaceHere}).on("afterInitialization", function (e, args) {
var searchInterface = {searchInterfaceHere}.CoveoSearchInterface;
// disable coveo search interface history until the first query is executed
if(searchInterface.options.enableHistory === true){
searchInterface.options.enableHistory = false;
searchInterface.options.originalOptionsObject.enableHistory = false;
searchInterface.queryStateModel.defaultAttributes.enableHistory = false;
searchInterface.setupHistoryManager(searchInterface.element, searchInterface._window);
}
// **** Your search interface initializations here ****
// const layoutSelector = Coveo.$$({searchInterfaceHere}).find(".CoveoResultLayoutSelector");
// Coveo.get(layoutSelector).changeLayout("card");
}
After you’ve disabled history tracking, and made any desired changes to the search interface (number of results per page, card layout, etc), you can turn the history tracking back on to capture user input.
Coveo.$$({searchInterfaceHere}).on("newQuery", function (args){
if({searchInterfaceHere}.CoveoSearchInterface.options.enableHistory === false){
var searchInterface = {searchInterface}.CoveoSearchInterface;
searchInterface.options.enableHistory = true;
searchInterface.options.originalOptionsObject.enableHistory = true;
searchInterface.CoveoSearchInterface.queryStateModel.defaultAttributes.enableHistory = true;
searchInterface.setupHistoryManager(searchInterface.element, searchInterface._window);
}
}
After making these edits, we once again had clean URLs, without any of the unnecessary Coveo hash parameters.
Leave a Reply