Quite a few people have been wondering why their backlinks don't update after new content is submitted. Researching other posts has shown that the reason is that the new content is not indexed in the search engine, and the views argument relies upon the index to create the backlinks list. This is why after running cron the backlinks list updates with the new content.
I thought that it might be nice to have a discussion about the best way to index these nodes so that the backlink function immediately works as desired.
There are lots of ways to accomplish this (custom module, etc), but below I will describe the way that I believe is simplest.
My favorite choice right now is to create an action that triggers after new content is posted. This action will run the _node_index_node function on the node that was just created (http://api.drupal.org/api/function/_node_index_node). Ideally, this function causes the individual node to be added to the index, and thus avoids a huge performance lag on the site from running a complete cron.
I'm new to the development side of drupal, so if anyone has advice on how to create a custom action that triggers in this way, I would appreciate it, and I'm sure that others have my same question.
p.s. another choice would use node_update_index (http://api.drupal.org/api/function/node_update_index) However, I presume that indexing every node is unnecessary if a trigger is set up correctly.
Comments
Is there any solution by
Is there any solution by now?
Theoretically the core node
Theoretically the core node and search modules take care of automatically updating the index when content is added or updated. If this isn't happening it sounds like a bug. If it's not a bug, then it would be a good idea to document the conditions that lead to a stale search index.
I couldn't find a more recent
I couldn't find a more recent discussion about this issue.
I tried Ariesto's suggestion by adding hook_nodeapi to my custom module:
function mycustommodule_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {switch ($op) {
case "insert":
case "update":
_node_index_node($node);
break;
}
}
It almost works. New nodes are re-indexed immediately and show up in views based upon "search: Links to". But when a node reference is changed in a node, the node is not re-indexed, I suppose because the updated reference has not been written to the table yet. If you edit and save the node again, it is then re-indexed.