The gigantic and amazing patch to the search module that was committed over at http://drupal.org/node/146466 does wonderful things, but I found a small bug. It does not correctly handle the situation where one node links to another and then that link gets changed -- the old link will remain in the search index as a "ghost" and continue to show up in search results (even after cron has been run a couple times to update the search index).

After poking around a bit, I found that this was due to a simple PHP mistake. The following code is used in search_index():

// Any left-over links in $links no longer exist. Delete them and mark the nodes for reindexing.
foreach ($links as $nid) {
    db_query("DELETE FROM {search_node_links} WHERE sid = %d AND type = '%s' AND nid = %d", $sid, $type, $nid);
    search_touch_node($nid);
  }

However, the nid is actually the key of the $links array, not its value. Therefore, changing the first line to foreach ($links as $nid => $leftover_caption) { fixes the problem.

A patch is attached.

CommentFileSizeAuthor
#1 205199.patch742 bytesdouggreen
search_update_links.patch751 bytesDavid_Rothstein
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

douggreen’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
742 bytes

Thanks! I reviewed the code and confirm that this is a bug. I also applied the patch and confirm that it applies. I changed the variable name from "leftover_caption" to just "caption", under the guise, that they're all leftover -- you could equally rename "nid" to "leftover_nid".

Gábor Hojtsy’s picture

Status: Reviewed & tested by the community » Fixed

Thanks, committed.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.