Gravatar for marshall.smith@acuitybrands.com

Question by Marshall_Smith, Feb 25, 2019 10:15 PM

Coveo Hive - Custom Facet Sort Options

Hello,

I have some facet values that start with numbers and are not sorting correctly since they are sorting as a strings (ex... 1 IN, 10 IN, 12 IN, 2 IN, 22 IN, 3 IN, 4 IN...). What are the options for customizing how facet values are sorted? I found the article below from 3 years ago. Is that still the way it's done? I'm using Coveo 5.

https://answers.coveo.com/questions/7506/custom-sort-in-coveo-for-sitecore.html

Coveo for Sitecore version: 5.0.140.19

Sitecore version: 9.0.2.180604

Thanks!

1 Reply
Gravatar for jflheureux@coveo.com

Answer by Jean-François L'Heureux, Feb 26, 2019 2:27 PM

The solution you found is still valid with recent Coveo for Sitecore versions.

In Coveo for Sitecore v5 with Coveo for Sitecore Hive, the UI components are now MVC renderings. So the file names and items to duplicate would be different.

With Coveo for Sitecore Hive, the initialization happens only when the DOM is loaded. Another approach is to alter the data attributes values before initialization. See https://docs.coveo.com/en/2401/coveo-for-sitecore-v5/overriding-coveo-for-sitecore-hive-initialization-options

You must set a fixed `DOM Unique Id` value in your facet data source item. E.g.: `sizeFacet`.

Your script would be inserted on the page after the facet component and would look like this:

<script>
  var sizeFacet = document.getElementById("sizeFacet");
  sizeFacet.dataset.customSort = "1 IN,2 IN,3 IN...";
</script>
Ask a question