diff --git a/core/modules/search/search.module b/core/modules/search/search.module
index 0bbdd0d..564f7d7 100644
--- a/core/modules/search/search.module
+++ b/core/modules/search/search.module
@@ -639,14 +639,8 @@ function search_index($sid, $module, $text) {
           // Check if link points to a node on this site
           if (preg_match($node_regexp, $value, $match)) {
             $path = drupal_get_normal_path($match[1]);
-            if (preg_match('!(?:node|book)/(?:view/)?([0-9]+)!i', $path, $match)) {
-              $linknid = $match[1];
-              if ($linknid > 0) {
-                $node = db_query('SELECT title, nid, vid FROM {node} WHERE nid = :nid', array(':nid' => $linknid), array('target' => 'slave'))->fetchObject();
-                $link = TRUE;
-                $linktitle = $node->title;
-              }
-            }
+            $link_node = _search_node_extract($path);
+            $link = $link_node->title ? TRUE : NULL;
           }
         }
       }
@@ -659,7 +653,8 @@ function search_index($sid, $module, $text) {
         if ($link) {
           // Check to see if the node link text is its URL. If so, we use the target node title instead.
           if (preg_match('!^https?://!i', $value)) {
-            $value = $linktitle;
+            $link_node = _search_node_extract($value);
+            $value = $link_node->title;
           }
         }
         $words = search_index_split($value);
@@ -670,6 +665,9 @@ function search_index($sid, $module, $text) {
           if (is_numeric($word) || drupal_strlen($word) >= $minimum_word_size) {
             // Links score mainly for the target.
             if ($link) {
+              $link_node = _search_node_extract($value);
+              $linknid = $link_node->nid;
+
               if (!isset($results[$linknid])) {
                 $results[$linknid] = array();
               }
@@ -782,6 +780,23 @@ function search_index($sid, $module, $text) {
 }
 
 /**
+ * Check if link points to a node on this site
+ *
+ * @param $path
+ *   The internal path or external URL being checked.
+ * @return
+ *   Return node title. No return value if $path are not points to a node on this site.
+ */
+function _search_node_extract($path) {
+  if (preg_match('!(?:node|book)/(?:view/)?([0-9]+)!i', $path, $match)) {
+    $linknid = $match[1];
+    if ($linknid > 0) {
+      $node = db_query('SELECT title, nid FROM {node} WHERE nid = :nid', array(':nid' => $linknid), array('target' => 'slave'))->fetchObject();
+      return $node;
+    }
+  }
+}
+/**
  * Changes a node's changed timestamp to 'now' to force reindexing.
  *
  * @param $nid
