diff --git a/core/modules/search/search.module b/core/modules/search/search.module
index 14ffc80..7862f92 100644
--- a/core/modules/search/search.module
+++ b/core/modules/search/search.module
@@ -639,14 +639,7 @@ 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 = _search_title_extract($path) ? TRUE : NULL;
           }
         }
       }
@@ -659,7 +652,7 @@ 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;
+            $value = _search_title_extract($value);
           }
         }
         $words = search_index_split($value);
@@ -782,6 +775,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_title_extract($path) {
+  if (preg_match('!(?:node|book)/(?:view/)?([0-9]+)!i', $path, $match)) {
+    $linknid = $match[1];
+    if ($linknid > 0) {
+      $node = db_query('SELECT title FROM {node} WHERE nid = :nid', array(':nid' => $linknid), array('target' => 'slave'))->fetchObject();
+      return $node->title;
+    }
+  }
+}
+/**
  * Changes a node's changed timestamp to 'now' to force reindexing.
  *
  * @param $nid
