Gravatar for elafleur@coveo.com

Question by elafleur, Nov 7, 2018 10:34 PM

Version number in Facet naturally sorted

Hello,

I have a multi-value string field that contains version numbers in this format:

12.0.0 ; 12.0.0 HF1 ; 12.0.0 HF2 ; 12.0.0 HF3 ; 12.0.0 HF4 ; 12.1.0 ; 12.1.0 HF1 ; 12.1.0 HF2 ; 12.1.1 ; 12.1.1 HF1 ; 12.1.1 HF2 ; 12.1.2 ; 12.1.2 HF1 ; 12.1.2 HF2 ; 12.1.3 ; 12.1.3.1 ; 12.1.3.2 ; 12.1.3.3 ; 12.1.3.4 ; 12.1.3.5 ; 12.1.3.6 ; 12.1.3.7

I want to have them displayed in a facet, and sorted naturally (12.3.4 should come before 9.2.5).... sorting alphabetically doesn't work in this case.

Do you have any suggestions on how this can be done?

Thanks much

1 Reply
Gravatar for jflheureux@coveo.com

Answer by Jean-François L'Heureux, Nov 9, 2018 10:51 AM

Multi-value fields in Coveo are always string fields. As you know, sorting strings that contain numerical-like values is a challenge as you must understand the number formats in the strings and build a custom comparison method. The Coveo Facet component does not support custom item comparison methods.

The only solution I see would be to create a special facet component for that field and hardcode the sort order using the `customSort/data-custom-sort` option of the Facet component: https://coveo.github.io/search-ui/components/facet.html#options.customsort

This means having all the possible version numbers listed in this field in the desired order. Seeing your sample version numbers, you seem to have a lot of versions. Performance might be impacted.

Ask a question