Float values in refinement list don't sort properly.
See original GitHub issueDescribe the bug 🐛 Float values in refinement list don’t sort properly.
To Reproduce 🔍 Steps to reproduce the behavior:
- Pick a test index
- Add
size
attribute and put values like 9, 9.5, 10, 10.5, 11… - Add
size
as a facet filter - Add refinement list to your page:
search.addWidget(
instantsearch.widgets.refinementList({
container: '#brand-list',
attributeName: 'size',
sortBy: ['size:asc'],
})
);
https://codesandbox.io/s/420yp9lyn0
Expected behavior 💭 Should be sorted 9, 9.5, 10. It’s 9, 10, 9.5 instead.
Screenshots 🖥
Environment:
- OS: Mac
- Browser: Chrome
- Version 68.0.3440.106
Additional context Please ping me back when it’s solved so I can contact the customer who reported it.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Python how to sort list with float values - Stack Overflow
Hi, just use the sort() methode : >>> list1.sort() · Those are two very different lists. You probably don't really want the second...
Read more >InstantSearch.js FAQ - Algolia
1. How to use float values in a rating menu widget? ... 7. Why is my facet value disappearing from a refinement list...
Read more >Filtering and sorting search results - Google Developers
For the Restrict to Range operator, Google supports numbers in float format and dates in ISO 8601 YYYYMMDD without dashes. You do not...
Read more >[pitch] Comparison Reform - Pitches - Swift Forums
correctly. I don't understand ... No, they are effectively refinement siblings. ... Do you want to be able to sort floating point numbers...
Read more >Manage the search schema in SharePoint - Microsoft Learn
If the casing is incorrect, no value will be returned. Refine on managed properties. If you want to use a managed property as...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks @noclat that’s indeed an annoying problem and definetely unexpected. We should be able to do better.
Looking at a response from Algolia, we can notice two things:
We should be able to leverage that information to infer the type of the facet and apply a correct sort but it implies a lot of magic behind the scene.
On the other hand, the user knows better and could easily implement a custom sort function:
This can be solved by using sortBy with a parseFloat (otherwise it sorts alphabetically). As using numerical values for facets is not the main use case (because it usually will explode quickly in number of values, making a range more interesting), I’ll close this issue for now.