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

Xano - February 8, 2009 - 09:37
Status:active» postponed (maintainer needs more info)

Could you please be more specific? A screenshot would be really helpful :)

#2

Xano - February 8, 2009 - 10:17

You mean like in the attached screen shots?

AttachmentSize
Picture 5.png 14.84 KB
Picture 6.png 13.81 KB

#3

ianchan - February 8, 2009 - 16:33

I've attached an example of the problem. Thank you for your help (and for creating a very useful module).

AttachmentSize
screenshot1.png 60.18 KB

#4

Xano - February 9, 2009 - 07:42
Status:postponed (maintainer needs more info)» active

#5

Xano - February 10, 2009 - 18:46

Are you sure the terms are sorted differently at Administer > Content > Taxonomy?

#6

ianchan - February 11, 2009 - 18:18

Yes, I checked the terms list for the vocabulary in question and the sort is alphabetically correct.

#7

ianchan - February 24, 2009 - 23:58

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

abramo - March 16, 2009 - 17:28

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

Xano - March 16, 2009 - 17:50

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

abramo - March 16, 2009 - 19:57

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

Xano - March 16, 2009 - 19:54

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

abramo - March 16, 2009 - 20:10

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

abramo - March 16, 2009 - 20:38

Printscreen of issue attached.

AttachmentSize
index-issue.jpg 146.09 KB

#14

Xano - March 25, 2009 - 23:19

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

ianchan - March 26, 2009 - 04:26

Thank you for the follow-up on this issue.

#16

abramo - March 26, 2009 - 08:51

Thanks from me too.

#17

Xano - April 16, 2009 - 23:38
Assigned to:Anonymous» Xano
Status:active» needs review

This patch should fix the problem for 5.x-2.x.

AttachmentSize
alpha_sort_d5_00.patch 1.24 KB

#18

abramo - April 17, 2009 - 09:20

Many thanks for the good effort - shall test and report!

#19

abramo - April 18, 2009 - 15:20

YES!!!

Excellent, Xano! - it works 100% fine for me. A real alphabetical index!
Many thanks, indeed.

#20

Xano - April 18, 2009 - 16:10

I guess this is RTBC then?

#21

abramo - April 19, 2009 - 08:44

RTBC, as far as I am concerned!
Goed gedaan meneer :)

#22

Xano - April 19, 2009 - 09:12
Status:needs review» reviewed & tested by the community

Goed gedaan meneer :)

Mwhaha :-P

#23

ianchan - April 21, 2009 - 16:53

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

Xano - April 21, 2009 - 17:31
Status:reviewed & tested by the community» needs work

Use strcasecmp() instead of strcmp(). I will have to check if either of these functions work with multibyte data though.

#25

ianchan - April 22, 2009 - 20:58

Thanks! Changing to strcasecmp() enabled case-insensitive sorting.

#26

Xano - September 12, 2009 - 18:57
Status:needs work» fixed

Fixed and committed to 5.x-2.x-dev and 6.x-2.x-dev. Thanks a lot!

#27

System Message - September 26, 2009 - 19:00
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.