diff --git domain_solr.module domain_solr.module
index 0c25ebb..20b3526 100644
--- domain_solr.module
+++ domain_solr.module
@@ -11,9 +11,16 @@
  */
 function domain_solr_apachesolr_update_index(&$document, $node) {
   // Index group posts
-  
+
   foreach($node->domains as $domain) {
 
+    // The gid in the {domain} table is unsigned, but the domain module
+    // makes it -1 for the deault domain. Also apache doesn't like it
+    // if we query for domain id -1.
+    if ($domain == -1) {
+      $domain = 0;
+    }
+
     $document->setMultiValue(_domain_solr_index_key(), $domain);
   }
 }
@@ -54,7 +61,7 @@ function domain_solr_apachesolr_process_results(&$results) {
   if ($domains) {
     $accessible_domains = array();
     $placeholders = db_placeholders($domains);
-    $result = db_query(db_rewrite_sql('SELECT * FROM {domain} n WHERE domain_id IN ('. $placeholders. ')'), $domains);
+    $result = db_query('SELECT * FROM {domain} d WHERE domain_id IN ('. $placeholders. ')', $domains);
     while ($row = db_fetch_object($result)) {
       $accessible_domains[] = $row->domain_id;
     }
@@ -108,7 +115,7 @@ function domain_solr_block($op = 'list', $delta = 0, $edit = array()) {
           return;
         }
         $query = apachesolr_current_query();
-		
+
         return apachesolr_facet_block($response, $query, 'domain_solr', $delta, $delta, t('Filter by Site'), 'domain_solr_domain_name');
       }
       break;
@@ -145,7 +152,7 @@ function domain_solr_theme() {
  * Theme the breadcrumb.
  */
 function theme_domain_solr_breadcrumb_im($domain_id) {
-  if (!is_numeric($group_id)) {
+  if (!is_numeric($domain_id)) {
     return t('No site');
   }
 
