Index: views_audio.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/audio/views_audio.inc,v
retrieving revision 1.10
diff -u -p -u -r1.10 views_audio.inc
--- views_audio.inc	31 Jul 2007 23:41:22 -0000	1.10
+++ views_audio.inc	29 Aug 2007 15:11:14 -0000
@@ -123,6 +123,13 @@ function audio_views_tables() {
     );
   }
 
+  // Use a different handler for numeric tags.
+  foreach (array('track', 'year') as $tag) {
+    if (isset($tables["audio_metadata_$tag"])) {
+      $tables["audio_metadata_$tag"]['sorts']['value']['handler'] = 'audio_views_handler_sort_numeric_tag';
+    }
+  }
+
   return $tables;
 }
 
@@ -151,3 +158,16 @@ function audio_views_handler_filter_tags
   }
   return $tags;
 }
+
+/**
+ * Handler to convert numeric strings to numbers for proper sorting.
+ *
+ * For more info on how this works see: http://blog.feedmarker.com/2006/02/01/how-to-do-natural-alpha-numeric-sort-in-mysql/
+ */
+function audio_views_handler_sort_numeric_tag($op, &$query, $sortinfo, $sort) {
+  $fullname = $sortinfo['table'] .'.'. $sortinfo['field'];
+  $alias = $sortinfo['table'] .'_'. $sortinfo['field'];
+  $query->ensure_table($sortinfo['table']);
+  $query->add_orderby('', $fullname.' + 0', $sort['sortorder'], $alias);
+}
+

