Alphabetical List not sorting correctly
ianchan - February 7, 2009 - 22:05
| Project: | Vocabulary Index |
| Version: | 5.x-2.0 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Xano |
| Status: | closed |
Description
Terms are not sorting correctly within the vocabulary index within alphabetical display is selected. They grouped under the correct letter (all the A's show up under A) but the problem is within the order of each per-letter listing.

#1
Could you please be more specific? A screenshot would be really helpful :)
#2
You mean like in the attached screen shots?
#3
I've attached an example of the problem. Thank you for your help (and for creating a very useful module).
#4
#5
Are you sure the terms are sorted differently at Administer > Content > Taxonomy?
#6
Yes, I checked the terms list for the vocabulary in question and the sort is alphabetically correct.
#7
It looks like within each alphabetical list it is sorting top level (parent) terms into one list and then sorting child terms into a second list.
#8
Same here - sorting is determined by vocabulary parent term hierarchy and not alphabetically.
This seems somehow inherent in Drupal taxonomy sorting - same issue is affecting the Glossary module.
It needs urgent review, as this renders the alphabetical function unusable.
#9
It doesn't really render the alphabetical view unusable, since paging works correctly (apart from a bug with really exotic characters like Chinese and Greek), but I agree this _is_ annoying.
The little time I have I mostly spend on Drupal 7, but patches or a nudge in the right direction are more than welcome!
#10
Sorry, issue is with purely English vocabularies - no exotic characters whatsoever - nothing else than pure Latin characters.
Sorting in taxonomy is apparently determined including hierarchical considerations in hierarchical vocabularies - some kind of "key" is involved. I have sorted taxonomy vocabularies outside of any other complementary module by php, and the result is the same : terms initially sorted by starting letter and re-sorted by parent term. Of course, the parent terms are not displayed in the list, only under their own starting letter - but they are implicitly there. The same issue is alive and well with the Glossary module, another module using taxonomy vocabularies. Seems this is a more general issue connected to the way the term tree is retrieved by taxonomy.
As the sorting stands now, it does not constitute an alphabetical listing, but a messed up listing based on starting letter. You may leave it this way, of course, if you feel this is a minor consideration.
#11
The philosophy behind the alphabetical view is that all terms are paged by their first letter, which is not what this issue is about. Taxonomy itself sorts terms by weight and then by name, but for alphabetical views Vocabulary Index messes up, probably because the terms are filtered by first letter. It is definitely a bug, but since I haven't got much time due to other obligations, it may take a few weeks before this gets fixed. That is, if nobody else provides a patch.
#12
Many thanks - time constraints are absolutely understandable, no two ways about it.
I believe that there is no sensible drupaler that does not realize that issues need their time to be resolved.
Very frequently my own frustration is that I lack the programming abilities to resolve issues and contribute the solutions back to the community. Same with this case, where if I had the knowledge I would gladly resolve this issue - both for the benefit of my own application, but also for the benefit of my fellow drupalers.
Thus, this issue will have to wait its proper turn . . . .
#13
Printscreen of issue attached.
#14
This is a 'bug' in taxonomy_get_tree(). It should sort by weight and then by name. All terms in my demo setup have the same weight, so the result should be completely sorted by name, which is not the case. I'll see if I can write a workaround for this.
#15
Thank you for the follow-up on this issue.
#16
Thanks from me too.
#17
This patch should fix the problem for 5.x-2.x.
#18
Many thanks for the good effort - shall test and report!
#19
YES!!!
Excellent, Xano! - it works 100% fine for me. A real alphabetical index!
Many thanks, indeed.
#20
I guess this is RTBC then?
#21
RTBC, as far as I am concerned!
Goed gedaan meneer :)
#22
Mwhaha :-P
#23
Thanks for the patch! While the sorting works... it's only working within text of the same case. Could you change it so that it is case-insensitive?
After patching I get lists like the following:
ABC
ADC
AFC
Abc
Adc
AFC
abc
adc
afc
Shouldn't it sort as:
ABC
Abc
abc
ADC
Adc
adc
etc...
Thanks...
#24
Use strcasecmp() instead of strcmp(). I will have to check if either of these functions work with multibyte data though.
#25
Thanks! Changing to strcasecmp() enabled case-insensitive sorting.
#26
Fixed and committed to 5.x-2.x-dev and 6.x-2.x-dev. Thanks a lot!
#27
Automatically closed -- issue fixed for 2 weeks with no activity.