? facet_sort.patch
Index: apachesolr.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr.module,v
retrieving revision 1.10
diff -u -p -r1.10 apachesolr.module
--- apachesolr.module	28 Jan 2009 20:06:36 -0000	1.10
+++ apachesolr.module	10 Feb 2009 20:04:37 -0000
@@ -654,13 +654,20 @@ function apachesolr_facet_block($respons
         $path = 'search/'. arg(1) .'/'. $new_query->get_query_basic();
         $querystring = $new_query->get_url_querystring();
       }
+      $sort = variable_get('apachesolr_facet_sort_orders', array());
+      $sort_preference = $sort[$module][$delta];
       $countsort = $count == 0 ? '' : 1 / $count;
       // if numdocs == 1 and !active, don't add.
       if ($response->numFound == 1 && !$active) {
         // skip
       }
       else {
-        $items[$active ? $countsort . $facet : 1 + $countsort . $facet] = theme('apachesolr_facet_item', $facet_text, $count, $path, $querystring, $active, $unclick_link, $response->numFound);
+        if ($sort_preference == 2) {
+          $items[$facet] = theme('apachesolr_facet_item', $facet_text, $count, $path, $querystring, $active, $unclick_link, $response->numFound);
+        }
+        else {
+          $items[$active ? $countsort . $facet : 1 + $countsort . $facet] = theme('apachesolr_facet_item', $facet_text, $count, $path, $querystring, $active, $unclick_link, $response->numFound);
+        }
       }
     }
     if (count($items) > 0) {
@@ -682,6 +689,7 @@ function apachesolr_facet_block($respons
 function apachesolr_facetcount_form($module, $delta) {
   $initial = variable_get('apachesolr_facet_query_initial_limits', array());
   $limits = variable_get('apachesolr_facet_query_limits', array());
+  $sort = variable_get('apachesolr_facet_sort_orders', array());
 
   $limit = drupal_map_assoc(array(50, 40, 30, 20, 15, 10, 5, 3));
 
@@ -700,6 +708,13 @@ function apachesolr_facetcount_form($mod
     '#description' => t('The maximum number of filter links to show in this block.'),
     '#default_value' => isset($limits[$module][$delta]) ? $limits[$module][$delta] : variable_get('apachesolr_facet_query_limit_default', 20),
   );
+  $form['apachesolr_facet_sort_order'] = array(
+    '#type' => 'select',
+    '#title' => t('Facet sort order'),
+    '#options' => array(1 => 'Count', 2 => 'Name'),
+    '#description' => t('The order the facets filter appear within the block.'),
+    '#default_value' => isset($sort[$module][$delta]) ? $sort[$module][$delta] : variable_get('apachesolr_facet_sort_order_default', 'count'),
+  );
 
   return $form;
 }
@@ -718,6 +733,9 @@ function apachesolr_facetcount_save($edi
   $initial = variable_get('apachesolr_facet_query_initial_limits', array());
   $initial[$module][$delta] = (int)$edit['apachesolr_facet_query_initial_limit'];
   variable_set('apachesolr_facet_query_initial_limits', $initial);
+  $sort = variable_get('apachesolr_facet_sort_orders', array());
+  $sort[$module][$delta] = (int)$edit['apachesolr_facet_sort_order'];
+  variable_set('apachesolr_facet_sort_orders', $sort);
 }
 
 /**
Index: apachesolr_search.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr_search.module,v
retrieving revision 1.7
diff -u -p -r1.7 apachesolr_search.module
--- apachesolr_search.module	28 Jan 2009 20:06:36 -0000	1.7
+++ apachesolr_search.module	10 Feb 2009 20:04:37 -0000
@@ -348,13 +348,20 @@ function apachesolr_search_block($op = '
                 $path = 'search/' . arg(1) . '/' . $new_query->get_query_basic();
                 $querystring = $new_query->get_url_querystring();
               }
+              $sort = variable_get('apachesolr_facet_sort_orders', array());
+              $sort_preference = $sort['apachesolr_search'][$delta];
               $countsort = $count == 0 ? '' : 1 / $count;
               // if numdocs == 1 and !active, don't add.
               if ($response->numFound == 1 && !$active) {
                 // skip
               }
               else {
-                $terms[$term->vid][$active ? $countsort . $term->name : 1 + $countsort . $term->name] = theme('apachesolr_facet_item', $term->name, $count, $path, $querystring, $active, $unclick_link, $response->numFound);
+                if ($sort_preference == 2) {
+                  $terms[$term->vid][$term->name] = theme('apachesolr_facet_item', $term->name, $count, $path, $querystring, $active, $unclick_link, $response->numFound);
+                }
+                else {
+                  $terms[$term->vid][$active ? $countsort . $term->name : 1 + $countsort . $term->name] = theme('apachesolr_facet_item', $term->name, $count, $path, $querystring, $active, $unclick_link, $response->numFound);
+                }
               }
             }
           }
