Index: faceted_search/author_facet.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/faceted_search/author_facet.module,v
retrieving revision 1.13
diff -u -F^function -r1.13 author_facet.module
--- faceted_search/author_facet.module	20 May 2008 01:55:00 -0000	1.13
+++ faceted_search/author_facet.module	22 Jun 2008 18:54:23 -0000
@@ -60,17 +60,21 @@ function author_facet_faceted_search_col
       if (!isset($selection) || isset($selection['author'][1])) {
         // Scan the search text for a 'author:uid' token, and extract a
         // facet from it.
-        if ($uid = search_query_extract($arg, 'author')) {
-          if (is_numeric($uid)) {
-            $excluded_roles = author_facet_excluded_roles($env_id);
-            if ($name = author_facet_get_user_name($env_id, $uid, $excluded_roles)) {
-              // Create a facet with the user found in the search text as the
-              // active category.
-              $facets[] = new author_facet($excluded_roles, $uid, $name);
-            }
+        if ($uid = _author_facet_query_extract($arg, 'author')) {
+          $excluded_roles = author_facet_excluded_roles($env_id);
+          if ($uid == 0) {
+            $name = variable_get('anonymous', t('Anonymous'));
+          }
+          else {
+            $name = author_facet_get_user_name($env_id, $uid, $excluded_roles);
+          }
+          if ($name) {
+            // Create a facet with the user found in the search text as the
+            // active category.
+            $facets[] = new author_facet($excluded_roles, $uid, $name);
           }
           // Remove the parsed token from the search text.
-          $arg = search_query_insert($arg, 'author');
+          $arg = _author_facet_query_insert($arg, 'author');
         }
       }
       return $arg;
@@ -119,6 +123,36 @@ function _author_facet_filter_role($role
 }
 
 /**
+ * Extract a module-specific search option from a search query. e.g. 'type:book'.
+ *
+ * Based on search_query_extract(), but modified to support numeric keys
+ * (including zero).
+ */
+function _author_facet_query_extract($keys, $option) {
+  if (preg_match('/(^| )'. $option .':([0-9]+)( |$)/i', $keys, $matches)) {
+    return $matches[2];
+  }
+}
+
+/**
+ * Return a query with the given module-specific search option inserted in.
+ * e.g. 'type:book'.
+ *
+ * Based on search_query_insert(), but modified to support numeric keys
+ * (including zero).
+ */
+function _author_facet_query_insert($keys, $option, $value = '') {
+  $key = _author_facet_query_extract($keys, $option);
+  if (isset($key)) {
+    $keys = trim(preg_replace('/(^| )'. $option .':[0-9]+/i', '', $keys));
+  }
+  if ($value != '') {
+    $keys .= ' '. $option .':'. $value;
+  }
+  return $keys;
+}
+
+/**
  * A facet for node authors. 
  */
 class author_facet extends faceted_search_facet {
@@ -128,9 +162,9 @@ function _author_facet_filter_role($role
   /**
    * Constructor. Optionally assigns the active user of the facet.
    */
-  function author_facet($excluded_roles = array(), $uid = 0, $name = '') {
+  function author_facet($excluded_roles = array(), $uid = NULL, $name = NULL) {
     $active_path = array();
-    if ($uid && $name) {
+    if (isset($uid) && isset($name)) {
       $active_path[] = new author_facet_category($uid, $name);
     }
     parent::faceted_search_facet('author', $active_path);
