Index: search.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/search/search.module,v
retrieving revision 1.338
diff -u -r1.338 search.module
--- modules/search/search.module	17 Feb 2010 22:44:52 -0000	1.338
+++ modules/search/search.module	21 Feb 2010 21:46:11 -0000
@@ -535,7 +535,7 @@
   // and begins and ends with a literal (inserting $null as required).
 
   $tag = FALSE; // Odd/even counter. Tag or no tag.
-  $link = FALSE; // State variable for link analyzer
+  $linknid = NULL; // State variable for link analyzer
   $score = 1; // Starting score per word
   $accum = ' '; // Accumulator for cleaned up data
   $tagstack = array(); // Stack with open tags
@@ -562,7 +562,7 @@
           $score = max(1, $score - $tags[array_shift($tagstack)]);
         }
         if ($tagname == 'a') {
-          $link = FALSE;
+          $linknid = NULL;
         }
       }
       else {
@@ -583,11 +583,6 @@
             $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;
-              }
             }
           }
         }
@@ -598,10 +593,18 @@
     else {
       // Note: use of PREG_SPLIT_DELIM_CAPTURE above will introduce empty values
       if ($value != '') {
-        if ($link) {
+        if ($linknid > 0) {
           // Check to see if the node link text is its URL. If so, we use the target node title instead.
+          // If the target node does not exist, we leave the existing link text.
           if (preg_match('!^https?://!i', $value)) {
-            $value = $linktitle;
+            $node = db_query(
+              'SELECT title, nid, vid FROM {node} WHERE nid = :nid',
+              array(':nid' => $linknid),
+              array('target' => 'slave')
+            )->fetchObject();
+            if (is_object($node) && !emtpy($node->title)) {
+              $value = $node->title;
+            }
           }
         }
         $words = search_index_split($value);
@@ -617,7 +620,7 @@
             }
 
             // Links score mainly for the target.
-            if ($link) {
+            if ($linknid > 0) {
               if (!isset($results[$linknid])) {
                 $results[$linknid] = array();
               }

