question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[refinementList]: sortBy does not correctly sort UTF8 chars

See original GitHub issue

image

When using the the name sorting (or keeping the default one), facets starting with an accented character are put at the end.

Instead of the default sorting on strings, we could use localeCompare. It needs to know the user locale, but this is already an information we can pass to the main instance (to specify how to format numbers), so we could re-use it here as well.

It will require a change in the Helper as well I guess.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

7reactions
pixelasticcommented, Oct 5, 2016

Seems there is no way to pass a custom sort function to sortBy. What can be done though, is use a normalized string through _.deburr.

Something like

var facets = _.sortBy(facetValues, (facet) => { return _.deburr(facet.name) });

This will convert Éric to Eric before applying the sort. Not perfect, but closer to what we want to achieve here.

1reaction
Haroenvcommented, Dec 13, 2018

You can use the sortBy argument to pass a regular JS sort function to override the sorting behaviour.

search.addWidget(
  instantsearch.widgets.refinementList({
    container: '#brand-list',
    attributeName: 'brand',
    sortBy({ name: a }, { name: b }) {
      return a.localeCompare(b);
    },
  })
);

https://codesandbox.io/s/713rl3zwzq

Sorting can also be done in transformItems if you so prefer.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Refinementlist Sorting Confusion - Algolia Community
Ideally I'd like to use the sortBy parameter to order the categories by their order attribute. Is this not possible or should I...
Read more >
How to sort an array of UTF-8 strings? - php - Stack Overflow
You're right - this property is respected by using the correct locale and strcoll() for sorting. The problem here is, that on Windows...
Read more >
Instant Meilisearch - npm
When placeholder search is set to false , no results appears when searching on no characters. For example, if the query is ""...
Read more >
instantsearch.js - UNPKG
If no refinement value\n * is provided, test if the refinementList contains ... });\n\n return sortBy.reduce(\n function preparePredicate(out, sort) {\n var ...
Read more >
Oracle Commerce Guided Search : MDEX Engine Developer's ...
No Dgidx flags are necessary to enable record sorting. If a property or dimension is properly enabled for sorting,.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found