diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index f5e6ac9..182fd0b 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -1,6 +1,7 @@
 
 Apache Solr integration 7.x-1.x-xxxx, xxxx-xx-xx
 ------------------------------
+#1059372 by jpmckinney, Georgique, Nick_vh: Fixed References integration is broken.
 #1323676 by Nick_vh: Global functions should be context driven.
 #1359294 by Nick_vh: Follow-up : Fixed Test is not enabling the correct modules.
 #1359386 by Nick_vh: Replace all instances of $_GET['q'] with current_path().
diff --git a/apachesolr.index.inc b/apachesolr.index.inc
index 7b3141c..d5ef110 100644
--- a/apachesolr.index.inc
+++ b/apachesolr.index.inc
@@ -343,18 +343,21 @@ function apachesolr_floatval($value) {
 }
 
 /**
- *  @see http://drupal.org/node/1059372
+ *  Indexing callback for the node_reference module
+ *  by the references module
  */
-function apachesolr_cck_nodereference_indexing_callback($node, $field_name, $index_key, $cck_info) {
+function apachesolr_nodereference_indexing_callback($entity, $field_name, $index_key, $field_info) {
   $fields = array();
-  if (!empty($node->{$field_name})) {
-    $index_key = apachesolr_index_key($cck_info);
-    foreach ($node->$field_name as $field) {
-      if ($index_value = (isset($field['nid']) && strlen($field['nid'])) ? $field['nid'] : FALSE) {
-        $fields[] = array(
-          'key' => $index_key,
-          'value' => $index_value,
-        );
+  if (!empty($entity->{$field_name})) {
+    $index_key = apachesolr_index_key($field_info);
+    foreach ($entity->$field_name as $field_references) {
+      foreach ($field_references as $reference) {
+        if ($index_value = (!empty($reference['nid'])) ? $reference['nid'] : FALSE) {
+          $fields[] = array(
+            'key' => $index_key,
+            'value' => $index_value,
+          );
+        }
       }
     }
   }
@@ -362,18 +365,21 @@ function apachesolr_cck_nodereference_indexing_callback($node, $field_name, $ind
 }
 
 /**
- *  @see http://drupal.org/node/1059372
+ *  Indexing callback for the user_reference module
+ *  by the references module
  */
-function apachesolr_cck_userreference_indexing_callback($node, $field_name, $index_key, $cck_info) {
+function apachesolr_userreference_indexing_callback($entity, $field_name, $index_key, $field_info) {
   $fields = array();
-  if (!empty($node->$field_name)) {
-    $index_key = apachesolr_index_key($cck_info);
-    foreach ($node->{$field_name} as $field) {
-      if ($index_value = (isset($field['uid']) && strlen($field['uid'])) ? $field['uid'] : FALSE) {
-        $fields[] = array(
-          'key' => $index_key,
-          'value' => $index_value,
-        );
+  if (!empty($entity->$field_name)) {
+    $index_key = apachesolr_index_key($field_info);
+    foreach ($entity->$field_name as $field_references) {
+      foreach ($field_references as $reference) {
+        if ($index_value = (isset($reference['uid']) && strlen($reference['uid'])) ? $reference['uid'] : FALSE) {
+          $fields[] = array(
+            'key' => $index_key,
+            'value' => $index_value,
+          );
+        }
       }
     }
   }
@@ -486,10 +492,16 @@ function apachesolr_nodeapi_mass_update($nodes) {
 
       // There was no exception, so update the table.
     if ($published_ids) {
-      db_update('apachesolr_search_node')->fields(array('changed' => REQUEST_TIME, 'status' => 1))->condition('nid', array_keys($published_ids), 'IN')->execute();
+      db_update('apachesolr_search_node')
+        ->fields(array('changed' => REQUEST_TIME, 'status' => 1))
+        ->condition('nid', array_keys($published_ids), 'IN')
+        ->execute();
     }
     if ($unpublished_ids) {
-      db_update('apachesolr_search_node')->fields(array('changed' => REQUEST_TIME, 'status' => 0))->condition('nid', array_keys($unpublished_ids), 'IN')->execute();
+      db_update('apachesolr_search_node')
+        ->fields(array('changed' => REQUEST_TIME, 'status' => 0))
+        ->condition('nid', array_keys($unpublished_ids), 'IN')
+        ->execute();
     }
     return TRUE;
   }
@@ -519,7 +531,9 @@ function apachesolr_nodeapi_mass_delete($nodes) {
     $solr->deleteByMultipleIds($ids);
     apachesolr_index_set_last_updated(REQUEST_TIME);
     // There was no exception, so update the table.
-    db_delete('apachesolr_search_node')->condition('nid', $nids, 'IN')->execute();
+    db_delete('apachesolr_search_node')
+      ->condition('nid', $nids, 'IN')
+      ->execute();
     return TRUE;
   }
   catch (Exception $e) {
diff --git a/apachesolr.module b/apachesolr.module
index 0f0cb56..66821ef 100644
--- a/apachesolr.module
+++ b/apachesolr.module
@@ -469,12 +469,32 @@ function apachesolr_document_id($id, $entity = 'node') {
  * Implements hook_user().
  *
  * Mark nodes as needing re-indexing if the author name changes.
+ *
+ * @see http://drupal.org/node/592522
+ *   Performance issue with Mysql
+ * @see http://api.drupal.org/api/drupal/includes--database--database.inc/function/db_update/7#comment-15459
+ *   To know why PDO in drupal does not support UPDATE and JOIN at once.
  */
 function apachesolr_user_update(&$edit, $account, $category) {
   if (isset($edit['name']) && $account->name != $edit['name']) {
-    // TODO: performance issue. see http://drupal.org/node/592522
-    $nid_query = db_select('node')->fields('node', array('nid'))->where("uid = :uid", array(':uid' => $account->uid));
-    db_update('apachesolr_search_node')->condition('nid', $nid_query, 'IN')->fields(array('changed' => REQUEST_TIME))->execute();
+    switch (db_driver()) {
+      case 'mysql' :
+        $query = "UPDATE {apachesolr_search_node} asn
+          INNER JOIN {node} n ON asn.nid = n.nid SET asn.changed = :changed
+          WHERE n.uid = :uid";
+        $result = db_query($query, array(':changed' => REQUEST_TIME,
+          ':uid' => $account->uid,
+        ));
+        break;
+      default :
+        $nids = db_select('node')
+          ->fields('node', array('nid'))
+          ->where("uid = :uid", array(':uid' => $account->uid));
+        $update = db_update('apachesolr_search_node')
+          ->condition('nid', $nids, 'IN')
+          ->fields(array('changed' => REQUEST_TIME))
+          ->execute();
+    }
   }
 }
 
@@ -482,11 +502,31 @@ function apachesolr_user_update(&$edit, $account, $category) {
  * Implements hook_taxonomy().
  *
  * Mark nodes as needing re-indexing if a term name changes.
+ *
+ * @see http://drupal.org/node/592522
+ *   Performance issue with Mysql
+ * @see http://api.drupal.org/api/drupal/includes--database--database.inc/function/db_update/7#comment-15459
+ *   To know why PDO in drupal does not support UPDATE and JOIN at once.
  */
 function apachesolr_taxonomy_term_update($term) {
-  // TODO: performance issue. see http://drupal.org/node/592522
-  $nid_query = db_select('taxonomy_index')->fields('taxonomy_index', array('nid'))->where("tid = :tid", array(':tid' => $term->tid));
-  db_update('apachesolr_search_node')->condition('nid', $nid_query, 'IN')->fields(array('changed' => REQUEST_TIME))->execute();
+  switch (db_driver()) {
+    case 'mysql' :
+      $query = "UPDATE {apachesolr_search_node} asn
+        INNER JOIN {term_node} tn ON asn.nid = n.nid SET asn.changed = :changed
+        WHERE tn.tid = :tid";
+      $result = db_query($query, array(':changed' => REQUEST_TIME,
+        ':tid' => $term->tid,
+      ));
+      break;
+    default :
+      $nids = db_select('taxonomy_index')
+        ->fields('taxonomy_index', array('nid'))
+        ->where("tid = :tid", array(':tid' => $term->tid));
+      $update = db_update('apachesolr_search_node')
+        ->condition('nid', $nids, 'IN')
+        ->fields(array('changed' => REQUEST_TIME))
+        ->execute();
+  }
   // TODO: the rest, such as term deletion.
 }
 
@@ -536,7 +576,10 @@ function apachesolr_comment_unpublish($comment) {
  * Mark one node as needing re-indexing.
  */
 function apachesolr_mark_node($nid) {
-  db_update('apachesolr_search_node')->condition('nid', $nid)->fields(array('changed' => REQUEST_TIME))->execute();
+  db_update('apachesolr_search_node')
+    ->condition('nid', $nid)
+    ->fields(array('changed' => REQUEST_TIME))
+    ->execute();
 }
 
 /**
@@ -548,12 +591,34 @@ function apachesolr_node_type_delete($info) {
 
 /**
  * Implements of hook_node_type_update().
+ *
+ * @see http://drupal.org/node/592522
+ *   Performance issue with Mysql
+ * @see http://api.drupal.org/api/drupal/includes--database--database.inc/function/db_update/7#comment-15459
+ *   To know why PDO in drupal does not support UPDATE and JOIN at once.
  */
 function apachesolr_node_type_update($info) {
   if (!empty($info->old_type) && $info->old_type != $info->type) {
     // We cannot be sure we are going before or after node module.
-    $nid = db_select('node')->fields('node', array('nid'))->where("type = :new OR type = :old", array(':new' => $info->type, ':old' => $info->old_type));
-    db_update('apachesolr_search_node')->condition('nid', $nid, 'IN')->fields(array('changed' => REQUEST_TIME))->execute();
+    switch (db_driver()) {
+      case 'mysql' :
+        $query = "UPDATE {apachesolr_search_node} asn
+          INNER JOIN {node} n ON asn.nid = n.nid SET asn.changed = :changed
+          WHERE (n.type = :type OR n.type = :old_type)";
+        $result = db_query($query, array(':changed' => REQUEST_TIME,
+          ':type' => $info->type,
+          ':old_type' => $info->old_type,
+        ));
+        break;
+      default :
+        $nids = db_select('node')
+          ->fields('node', array('nid'))
+          ->where("type = :new OR type = :old", array(':new' => $info->type, ':old' => $info->old_type));
+        $update = db_update('apachesolr_search_node')
+          ->condition('nid', $nids, 'IN')
+          ->fields(array('changed' => REQUEST_TIME))
+          ->execute();
+    }
   }
 }
 
@@ -564,13 +629,16 @@ function apachesolr_index_status($namespace) {
   $excluded_types = apachesolr_get_excluded_types($namespace);
   list($last_change, $last_nid) = apachesolr_get_last_change($namespace);
 
-  $query = db_select('apachesolr_search_node', 'asn')->condition('asn.status', 1);
+  $query = db_select('apachesolr_search_node', 'asn')
+    ->condition('asn.status', 1);
   apachesolr_query_add_excluded_types($query, $excluded_types);
   $total = $query->countQuery()->execute()->fetchField();
 
   $query = db_select('apachesolr_search_node', 'asn')
     ->condition('asn.status', 1)
-    ->condition(db_or()->condition('asn.changed', $last_change, '>')->condition(db_and()->condition('asn.changed', $last_change)->condition('asn.nid', $last_nid, '>')));
+    ->condition(db_or()->condition('asn.changed', $last_change, '>')
+    ->condition(db_and()->condition('asn.changed', $last_change)
+    ->condition('asn.nid', $last_nid, '>')));
   apachesolr_query_add_excluded_types($query, $excluded_types);
   $remaining = $query->countQuery()->execute()->fetchField();
 
@@ -609,10 +677,27 @@ function apachesolr_clear_last_index($namespace = '') {
  */
 function apachesolr_rebuild_index_table($type = NULL) {
   if (isset($type)) {
-    $sel_query = db_select('node')
-      ->fields('node', array('nid'))
-      ->condition('type', $type);
-    db_delete('apachesolr_search_node')->condition('nid', $sel_query, 'IN')->execute();
+
+
+    switch (db_driver()) {
+      case 'mysql' :
+        $query = "DELETE FROM {apachesolr_search_node}
+          USING {apachesolr_search_node} asn
+          INNER JOIN {node} n ON asn.nid = n.nid
+          WHERE n.type = ':type";
+        db_query($query, array(':changed' => REQUEST_TIME,
+          ':type' => $type,
+        ));
+        break;
+      default :
+        $nids = db_select('node')
+          ->fields('node', array('nid'))
+          ->condition('type', $type);
+        db_delete('apachesolr_search_node')
+          ->condition('nid', $nids, 'IN')
+          ->execute();
+    }
+
 
     // Populate table
     $sel_query = db_select('node')
@@ -620,12 +705,14 @@ function apachesolr_rebuild_index_table($type = NULL) {
       ->condition('type', $type);
     $sel_query->addExpression(REQUEST_TIME, 'changed');
 
-    db_insert('apachesolr_search_node')->fields(array('nid', 'status', 'changed'))
+    db_insert('apachesolr_search_node')
+      ->fields(array('nid', 'status', 'changed'))
       ->from($sel_query)
       ->execute();
   }
   else {
-    db_delete('apachesolr_search_node')->execute();
+    db_delete('apachesolr_search_node')
+      ->execute();
     // Populate table
     $sel_query = db_select('node', 'n')
       ->fields('n', array('nid', 'status'));
@@ -640,12 +727,16 @@ function apachesolr_rebuild_index_table($type = NULL) {
       $sel_query->addExpression('GREATEST(n.created, n.changed)', 'changed');
     }
 
-    db_insert('apachesolr_search_node')->fields($insert_fields)
+    db_insert('apachesolr_search_node')
+      ->fields($insert_fields)
       ->from($sel_query)
       ->execute();
 
     // Make sure no nodes end up with a timestamp that's in the future.
-    db_update('apachesolr_search_node')->condition('changed', REQUEST_TIME, '>')->fields(array('changed' => REQUEST_TIME))->execute();
+    db_update('apachesolr_search_node')
+      ->condition('changed', REQUEST_TIME, '>')
+      ->fields(array('changed' => REQUEST_TIME))
+      ->execute();
     apachesolr_clear_last_index();
   }
   cache_clear_all('*', 'cache_apachesolr', TRUE);
@@ -2002,41 +2093,69 @@ function apachesolr_fields_list_facet_map_callback($facets, $options) {
 }
 
 /**
- * Use the content.module's content_format() to format the
- * field based on its nid ($facet).
- *
  *  @param $facet string
  *    The indexed value
  *  @param $options
  *    An array of options including the hook_block $delta.
  *  @see http://drupal.org/node/1059372
  */
-function apachesolr_cck_nodereference_field_callback($facet, $options) {
-  if (function_exists('content_format')) {
-    return strip_tags(content_format($options['delta'], array('nid' => $facet)));
+function apachesolr_nodereference_map_callback($facets, $options) {
+  $map = array();
+  $allowed_values = array();
+  // @see list_field_formatter_view()
+  $fields = field_info_fields();
+  $field_name = $options['field']['field_name'];
+  if (isset($fields[$field_name])) {
+    $allowed_values = node_reference_potential_references($fields[$field_name]);
   }
-  else {
-    return $facet;
+  foreach ($facets as $key) {
+    if (isset($allowed_values[$key])) {
+      $map[$key]['#markup'] = field_filter_xss($allowed_values[$key]['title']);
+    }
+    elseif ($key == '_empty_' && $options['facet missing allowed']) {
+      // Facet missing.
+      $map[$key]['#markup'] = theme('facetapi_facet_missing', array('field_name' => $options['display_name']));
+    }
+    else {
+      $map[$key]['#markup'] = field_filter_xss($key);
+    }
+    // The value has already been filtered.
+    $map[$key]['#html'] = TRUE;
   }
+  return $map;
 }
 
 /**
- * Use the content.module's content_format() to format the
- * field based on its uid ($facet).
- *
  *  @param $facet string
  *    The indexed value
  *  @param $options
  *    An array of options including the hook_block $delta.
  *  @see http://drupal.org/node/1059372
  */
-function apachesolr_cck_userreference_field_callback($facet, $options) {
-  if (function_exists('content_format')) {
-    return strip_tags(content_format($options['delta'], array('uid' => $facet)));
+function apachesolr_userreference_map_callback($facets, $options) {
+	$map = array();
+  $allowed_values = array();
+  // @see list_field_formatter_view()
+  $fields = field_info_fields();
+  $field_name = $options['field']['field_name'];
+  if (isset($fields[$field_name])) {
+    $allowed_values = user_reference_potential_references($fields[$field_name]);
   }
-  else {
-    return $facet;
+  foreach ($facets as $key) {
+    if (isset($allowed_values[$key])) {
+      $map[$key]['#markup'] = field_filter_xss($allowed_values[$key]['title']);
+    }
+    elseif ($key == '_empty_' && $options['facet missing allowed']) {
+      // Facet missing.
+      $map[$key]['#markup'] = theme('facetapi_facet_missing', array('field_name' => $options['display_name']));
+    }
+    else {
+      $map[$key]['#markup'] = field_filter_xss($key);
+    }
+    // The value has already been filtered.
+    $map[$key]['#html'] = TRUE;
   }
+  return $map;
 }
 
 /**
@@ -2314,23 +2433,34 @@ function apachesolr_get_max_date(array $facet) {
   return $return;
 }
 
-
-
 /**
- * Implements hook_apachesolr_field_mappings() on behalf of CCK.
+ * Implements hook_apachesolr_field_mappings() on behalf of References (node_reference).
  * @see http://drupal.org/node/1059372
  */
-function content_apachesolr_field_mappings() {
+function node_reference_apachesolr_field_mappings() {
   $mappings = array(
     'node_reference' => array(
-      'display_callback' => 'apachesolr_cck_nodereference_field_callback',
-      'indexing_callback' => 'apachesolr_cck_nodereference_indexing_callback',
+      'indexing_callback' => 'apachesolr_nodereference_indexing_callback',
       'index_type' => 'integer',
-    ),
+      'map callback' => 'apachesolr_nodereference_map_callback',
+      'facets' => TRUE,
+    )
+  );
+
+  return $mappings;
+}
+
+/**
+ * Implements hook_apachesolr_field_mappings() on behalf of References (user_reference).
+ * @see http://drupal.org/node/1059372
+ */
+function user_reference_apachesolr_field_mappings() {
+  $mappings = array(
     'user_reference' => array(
-      'display_callback' => 'apachesolr_cck_userreference_field_callback',
-      'indexing_callback' => 'apachesolr_cck_userreference_indexing_callback',
+      'indexing_callback' => 'apachesolr_userreference_indexing_callback',
       'index_type' => 'integer',
+      'map callback' => 'apachesolr_userreference_map_callback',
+      'facets' => TRUE,
     ),
   );
 
diff --git a/apachesolr_search.admin.inc b/apachesolr_search.admin.inc
index aacefd7..f27cb5a 100644
--- a/apachesolr_search.admin.inc
+++ b/apachesolr_search.admin.inc
@@ -895,7 +895,10 @@ function apachesolr_search_type_boost_form_submit($form, &$form_state) {
     // Set no longer omitted node types for reindexing.
     if (empty($new_excluded_types[$type]) && !empty($old_excluded_types[$type])) {
       $nids = db_select('node')->fields('node', array('nid'))->condition('type', $type);
-      db_update('apachesolr_search_node')->fields(array('changed' => REQUEST_TIME))->condition('nid', $nids, 'IN')->execute();
+      db_update('apachesolr_search_node')
+        ->fields(array('changed' => REQUEST_TIME))
+        ->condition('nid', $nids, 'IN')
+        ->execute();
     }
   }
 }
