Hi.
GIVEN
A taxonomy vocabulary with terms that has (many start with) a non-Latin character.
Drupal core taxonomy module correctly sort the terms ignoring the diacritics.
Facet API does not correctly sort the terms, as it list the ones that start with a non-Latin character in the end.
IN FACET BLOCK - INCORRECT

IN DRUPAL CORE (admin/structure/taxonomy/VOCABULARY_NAME) - CORRECT

HELP
I was trying to delve into the code but could not find where the actual sorting happens.
Any help here?
Thanks,
Amir
| Comment | File | Size | Author |
|---|---|---|---|
| 2-facet-not-sorted-correctly.png | 19.95 KB | amir simantov | |
| 1-core-taxonomy-sorted-correctly.png | 37.96 KB | amir simantov |
Comments
Comment #2
fmfpereira commentedSame as here for all the facet types.
Comment #3
eugene.ilyin commentedYes, it works great for taxonomy because there they are sorted through mysql.
But for facets values sorted by PHP. I don't see a good way to do it universally for all languages and cases. Also, it's pretty risky because it can lead to regressions on existing sites.
I propose the recipe, which consists of two steps:
1. use hook_facetapi_sort_info_alter and alter the callback for sorting
2. provide your own callback to sort facet values as you want
Comment #4
eugene.ilyin commentedComment #5
amir simantov commentedHi Eugene,
Your explanation was very good - thanks for your time helping me figuring out how to do it, I appreciate it.
For documentation, I add here my code.
Here is the hook overriding where I map my callback function and the implementation of the callback function.
Here is a simple helper function that I have put in my custom library:
I would note that I did try to convert to different encoding but it was getting complicated, so a simple replacing of characters was easier.
Thanks again.
Comment #7
nikolay shapovalov commentedAs an idea, inspired by https://stackoverflow.com/questions/27187285/sorting-russian-english-list
You can transliterate values using https://www.drupal.org/project/transliteration and then sort them.