Sorting text

An article, posted 7 months ago filed in sorting, ruby, programming, database, order, databases & sql.
Sorting text

There are a few hard problems in computing. Correctly handling time, naming, preventing off by one errors… sorting text may not be one of them but recently we ran into a discussion where I couldn't make up my mind anymore. Hence, this post's topic: sorting text.

The problem

How do you sort the following words:

  • cheese
  • Ape
  • Drums
  • dent
  • Beer

If you'd ask ruby I'd get:

 %w[cheese Ape Drums dent Beer].sort

Results in:

  1. Ape
  2. Beer
  3. Drums
  4. cheese
  5. dent

Which in my useless and ramshackle programmer's brain translates to, well why not, it is sorted right?

But then we moved the data into a database which was correctly set up with a proper locale for 'collation', a term that I've seen but never meant anything to me until this problem. Collation is:

> the assembly of written information into a standard order.

(thanks Wikipedia - Collation)

Databas…

Continue reading...

murb blog