Sorting by CustomField

Hi all,

The ability to sort search results by custom fields is great.

However, in this case, we have a numeric custom field, and the default
Ascending sorts ‘10’ before ‘2’. Any hint on how to specify numerical
instead of alphabetical sort order?

/Lars

However, in this case, we have a numeric custom field, and the default
Ascending sorts ‘10’ before ‘2’. Any hint on how to specify numerical
instead of alphabetical sort order?

Pack the single digits with a leading zero.

However, in this case, we have a numeric custom field, and the default
Ascending sorts ‘10’ before ‘2’. Any hint on how to specify numerical
instead of alphabetical sort order?

Pack the single digits with a leading zero.

Good workaround, but ugly. Also, the length of these numbers is not
upwardly bounded, so I’d have to prepend a lot of zeroes to be sure of
the sorting.

Maybe there’s a way to prepend zeros, do the sorting, and the remove
the zeroes before display?

Am I to assume there is not way to specify the sorting, numerical vs
alphabetical?

/Lars

However, in this case, we have a numeric custom field, and the default
Ascending sorts ‘10’ before ‘2’. Any hint on how to specify numerical
instead of alphabetical sort order?

Pack the single digits with a leading zero.

Good workaround, but ugly. Also, the length of these numbers is not
upwardly bounded, so I’d have to prepend a lot of zeroes to be sure of
the sorting.

Below I suggest two solutions, but both need coding and can not work
for arbitrary long numbers.

Maybe there’s a way to prepend zeros, do the sorting, and the remove
the zeroes before display?

There is way to append zeroes before storing in DB and strip them
before showing value.

Am I to assume there is not way to specify the sorting, numerical vs
alphabetical?

There is way - CAST function.

First solution can store up to 255 digits and sort by them, but using
full length of the field will slow down sorting and DB would be much
bigger. Second solution I like more as it’s more proper way to do
this, but number will be limitted by the system(DB, 32bit/64bit).

/Lars


http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users

Community help: http://wiki.bestpractical.com
Commercial support: sales@bestpractical.com

Discover RT’s hidden secrets with RT Essentials from O’Reilly Media.
Buy a copy at http://rtbook.bestpractical.com

Best regards, Ruslan.