Index: apachesolr.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr.module,v
retrieving revision 1.1.2.12.2.146
diff -u -r1.1.2.12.2.146 apachesolr.module
--- apachesolr.module	12 Jun 2009 18:16:31 -0000	1.1.2.12.2.146
+++ apachesolr.module	18 Jun 2009 07:49:25 -0000
@@ -653,18 +653,16 @@
         // '*' sorts before all numbers.
         $sortpre = '*';
         $new_query->remove_filter($facet_field, $facet);
-
-        $path = $new_query->get_path();
-        $querystring = $new_query->get_url_querystring();
-        $unclick_link = theme('apachesolr_unclick_link', $path, $querystring);
+        $options['query'] = $new_query->get_url_querystring();
+        $link = theme('apachesolr_unclick_link', $facet_text, $new_query->get_path(), $options);
       }
       else {
         $new_query->add_filter($facet_field, $facet, $exclude);
-        $path = $new_query->get_path();
-        $querystring = $new_query->get_url_querystring();
+        $options['query'] = $new_query->get_url_querystring();
+        $link = theme('apachesolr_facet_item', $facet_text, $new_query->get_path(), $options, $count, $active, $response->response->numFound);
       }
       if ($count || $active) {
-        $items[$sortpre . '*' . $facet_text] = theme('apachesolr_facet_item', $facet_text, $count, $path, $querystring, $active, $unclick_link, $response->response->numFound, $options);
+        $items[$sortpre . '*' . $facet_text] = $link;
       }
     }
     // Unless a facet is active only display 2 or more.
@@ -690,18 +688,17 @@
 
   $new_query = clone $query;
   foreach (array_reverse($new_query->get_filters($facet_field)) as $filter) {
+    $options = array();
     // Iteratively remove the date facets.
     $new_query->remove_filter($facet_field, $filter['#value']);
-    $path = $new_query->get_path();
-    $querystring = $new_query->get_url_querystring();
-    $unclick_link = theme('apachesolr_unclick_link', $path, $querystring);
     if ($facet_callback && function_exists($facet_callback)) {
-      $facet_text = $facet_callback($filter['#start']);
+      $facet_text = $facet_callback($filter['#start'], $options);
     }
     else {
       $facet_text = apachesolr_date_format_iso_by_gap(apachesolr_date_find_query_gap($filter['#start'], $filter['#end']), $filter['#start']);
     }
-    array_unshift($items, theme('apachesolr_facet_item', $facet_text, 0, $path, $querystring, TRUE, $unclick_link));
+    $options['query'] = $new_query->get_url_querystring();
+    array_unshift($items, theme('apachesolr_unclick_link', $facet_text, $new_query->get_path(), $options));
   }
   // Add links for additional date filters.
   if (!empty($response->facet_counts->facet_dates->$facet_field)) {
@@ -725,22 +722,21 @@
     $range_end[$prev_facet] = $end;
 
     foreach ($field as $facet => $count) {
+      $options = array();
       // Solr sends this back if it's empty.
       if ($facet == '_empty_' || $count == 0) {
         continue;
       }
       if ($facet_callback && function_exists($facet_callback)) {
-        $facet_text = $facet_callback($facet);
+        $facet_text = $facet_callback($facet, $options);
       }
       else {
         $facet_text = apachesolr_date_format_iso_by_gap(substr($gap, 2), $facet);
       }
       $new_query = clone $query;
       $new_query->add_filter($facet_field, '['. $facet .' TO '. $range_end[$facet] .']');
-      $path = $new_query->get_path();
-      $querystring = $new_query->get_url_querystring();
-
-      $items[] = theme('apachesolr_facet_item', $facet_text, $count, $path, $querystring, FALSE, '', $response->response->numFound);
+      $options['query'] = $new_query->get_url_querystring();
+      $items[] = theme('apachesolr_facet_item', $facet_text, $new_query->get_path(), $options, $count, FALSE, $response->response->numFound);
     }
   }
   if (count($items) > 0) {
@@ -1183,21 +1179,39 @@
  */
 function apachesolr_theme() {
   return array(
+    /**
+     * Returns a link for a facet term with the # of results clicking it will yeild (count)
+     */
     'apachesolr_facet_item' => array(
-      'arguments' => array('name' => NULL, 'count' => NULL, 'path' => NULL, 'querystring' => '', 'active' => FALSE, 'unclick_link' => NULL, 'num_found' => NULL, 'options' => NULL),
+      'arguments' => array('facet_text' => NULL, 'path' => NULL, 'options' => NULL, 'count' => NULL, 'active' => FALSE, 'num_found' => NULL),
     ),
+    /**
+     * Returns a link to remove a facet filter from the current search.
+     */
     'apachesolr_unclick_link' => array(
-      'arguments' => array('url' => NULL, 'querystring' => ''),
+      'arguments' => array('facet_text' => NULL, 'path' => NULL, 'options' => NULL),
     ),
+    /**
+     * Returns a list of links from the above functions (apachesolr_facet_item and apachesolr_unclick_link)
+     */
     'apachesolr_facet_list' => array(
       'arguments' => array('items' => NULL),
     ),
+    /**
+     * Returns a list of links generated by apachesolr_sort_link
+     */
     'apachesolr_sort_list' => array(
       'arguments' => array('items' => NULL),
     ),
+    /**
+     * Returns a link which can be used to search the results.
+     */
     'apachesolr_sort_link' => array(
       'arguments' => array('text' => NULL, 'path' => NULL, 'querystring' => '', 'active' => FALSE, 'direction' => ''),
     ),
+    /**
+     * Returns a list of results (docs) in content recommendation block
+     */
     'apachesolr_mlt_recommendation_block' => array(
       'arguments' => array('docs' => NULL),
     ),
@@ -1307,7 +1321,7 @@
   return theme('item_list', $links);
 }
 
-function theme_apachesolr_facet_item($name, $count, $path, $querystring = '', $active = FALSE, $unclick_link = NULL, $num_found = NULL, $options = array()) {
+function theme_apachesolr_facet_item($facet_text, $path, $options = array(), $count, $active = FALSE, $num_found = NULL) {
 
   if ($active) {
     if (isset($options['attributes']['class'])) {
@@ -1317,16 +1331,7 @@
       $options['attributes']['class'] = 'active';
     }
   }
-  if ($unclick_link) {
-    if (empty($options['html'])) {
-      $name = check_plain($name);
-    }
-    return $unclick_link . ' '. $name;
-  }
-  else {
-    $options['query'] = $querystring;
-    return apachesolr_l($name ." ($count)",  $path, $options);
-  }
+  return apachesolr_l($facet_text ." ($count)",  $path, $options);
 }
 
 /**
@@ -1353,8 +1358,16 @@
 }
 
 
-function theme_apachesolr_unclick_link($path, $querystring = '') {
-  return apachesolr_l("(-)", $path, array('query' => $querystring));
+function theme_apachesolr_unclick_link($facet_text, $path, $options = array()) {
+  $options['query'] = $querystring;
+  if (empty($options['html'])) {
+    $facet_text = check_plain($facet_text);
+  }
+  else {
+    // Don't pass this option as TRUE into apachesolr_l().
+    unset($options['html']);
+  }
+  return apachesolr_l("(-)", $path, $options) . ' '. $facet_text;
 }
 
 function theme_apachesolr_sort_link($text, $path, $querystring = '', $active = FALSE, $direction = '') {
Index: README.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/README.txt,v
retrieving revision 1.1.2.1.2.21
diff -u -r1.1.2.1.2.21 README.txt
--- README.txt	11 Jun 2009 12:39:05 -0000	1.1.2.1.2.21
+++ README.txt	18 Jun 2009 07:49:26 -0000
@@ -223,3 +223,9 @@
 hook_apachesolr_sort_links_alter(&$sort_links)
 
   Called by the sort link block code. Allows other modules to modify, add or remove sorts.
+
+
+Themers
+----------------
+
+See inline docs in apachesolr_theme and apachesolr_search_theme functions within apachesolr.module and apachesolr_search.module.
\ No newline at end of file
Index: apachesolr_search.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr_search.module,v
retrieving revision 1.1.2.6.2.100
diff -u -r1.1.2.6.2.100 apachesolr_search.module
--- apachesolr_search.module	12 Jun 2009 18:26:34 -0000	1.1.2.6.2.100
+++ apachesolr_search.module	18 Jun 2009 07:49:26 -0000
@@ -556,6 +556,7 @@
             $terms = array();
 
             foreach ($response->facet_counts->facet_fields->$delta as $tid => $count) {
+              $options = array();
               if ($tid == '_empty_') {
                 // TODO - for now we don't handle facet missing.
                 continue;
@@ -567,19 +568,18 @@
               if ($active = $query->has_filter('tid', $tid)) {
                 $contains_active = TRUE;
                 $new_query->remove_filter('tid', $term->tid);
-                $path = $new_query->get_path();
-                $querystring = $new_query->get_url_querystring();
-                $unclick_link = theme('apachesolr_unclick_link', $path, $querystring);
+                $options['query'] = $new_query->get_url_querystring();
+                $link = theme('apachesolr_unclick_link', $term->name, $new_query->get_path(), $options);
               }
               else {
                 $new_query->add_filter('tid', $term->tid);
-                $path = $new_query->get_path();
-                $querystring = $new_query->get_url_querystring();
+                $options['query'] = $new_query->get_url_querystring();
+                $link = theme('apachesolr_facet_item', $term->name, $new_query->get_path(), $options, $count, $active, $response->response->numFound);
               }
               $countsort = $count == 0 ? '' : 1 / $count;
               // if numdocs == 1 and !active, don't add.
               if ($response->response->numFound > 1 || $active) {
-                $terms[$term->vid][$active ? $countsort . $term->name : 1 + $countsort . $term->name] = theme('apachesolr_facet_item', $term->name, $count, $path, $querystring, $active, $unclick_link, $response->response->numFound);
+                $terms[$term->vid][$active ? $countsort . $term->name : 1 + $countsort . $term->name] = $link;
               }
             }
           }
@@ -609,13 +609,12 @@
               if ($field['#name']) {
                 $new_query = clone $query;
                 $new_query->remove_filter($field['#name'], $field['#value']);
-                $path = $new_query->get_path();
-                $querystring = $new_query->get_url_querystring();
-                $unclick_link = theme('apachesolr_unclick_link', $path, $querystring);
-                if (! $fielddisplay = theme("apachesolr_breadcrumb_". $field['#name'], $field['#value'])) {
+                $options['query'] = $new_query->get_url_querystring();
+                $fielddisplay = theme("apachesolr_breadcrumb_". $field['#name'], $field['#value']);
+                if (!$fielddisplay) {
                   $fielddisplay = $field['#value'];
                 }
-                $links[] = theme('apachesolr_facet_item', $fielddisplay, NULL, $path, $querystring, $active, $unclick_link, $response->response->numFound);
+                $links[] = theme('apachesolr_unclick_link', $fielddisplay, $new_query->get_path(), $querystring);
               }
             }
             $content = theme('apachesolr_currentsearch', $response->response->numFound, $links);
